Coverage for .tox/coverage/lib/python3.11/site-packages/wuttjamaican/db/model/upgrades.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2025-01-06 17:01 -0600

1# -*- coding: utf-8; -*- 

2################################################################################ 

3# 

4# WuttJamaican -- Base package for Wutta Framework 

5# Copyright © 2023-2024 Lance Edgar 

6# 

7# This file is part of Wutta Framework. 

8# 

9# Wutta Framework is free software: you can redistribute it and/or modify it 

10# under the terms of the GNU General Public License as published by the Free 

11# Software Foundation, either version 3 of the License, or (at your option) any 

12# later version. 

13# 

14# Wutta Framework is distributed in the hope that it will be useful, but 

15# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 

16# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 

17# more details. 

18# 

19# You should have received a copy of the GNU General Public License along with 

20# Wutta Framework. If not, see <http://www.gnu.org/licenses/>. 

21# 

22################################################################################ 

23""" 

24Upgrade Model 

25""" 

26 

27import datetime 

28 

29import sqlalchemy as sa 

30from sqlalchemy import orm 

31 

32from .base import Base, uuid_column, uuid_fk_column 

33from wuttjamaican.enum import UpgradeStatus 

34from wuttjamaican.db.util import UUID 

35from wuttjamaican.util import make_true_uuid 

36 

37 

38class Upgrade(Base): 

39 """ 

40 Represents an app upgrade. 

41 """ 

42 __tablename__ = 'upgrade' 

43 

44 uuid = uuid_column(UUID(), default=make_true_uuid) 

45 

46 created = sa.Column(sa.DateTime(timezone=True), nullable=False, 

47 default=datetime.datetime.now, doc=""" 

48 When the upgrade record was created. 

49 """) 

50 

51 created_by_uuid = uuid_fk_column('user.uuid', nullable=False) 

52 created_by = orm.relationship( 

53 'User', 

54 foreign_keys=[created_by_uuid], 

55 cascade_backrefs=False, 

56 doc=""" 

57 :class:`~wuttjamaican.db.model.auth.User` who created the 

58 upgrade record. 

59 """) 

60 

61 description = sa.Column(sa.String(length=255), nullable=False, doc=""" 

62 Basic (identifying) description for the upgrade. 

63 """) 

64 

65 notes = sa.Column(sa.Text(), nullable=True, doc=""" 

66 Notes for the upgrade. 

67 """) 

68 

69 executing = sa.Column(sa.Boolean(), nullable=False, default=False, doc=""" 

70 Whether or not the upgrade is currently being performed. 

71 """) 

72 

73 status = sa.Column(sa.Enum(UpgradeStatus), nullable=False, doc=""" 

74 Current status for the upgrade. This field uses an enum, 

75 :class:`~wuttjamaican.enum.UpgradeStatus`. 

76 """) 

77 

78 executed = sa.Column(sa.DateTime(timezone=True), nullable=True, doc=""" 

79 When the upgrade was executed. 

80 """) 

81 

82 executed_by_uuid = uuid_fk_column('user.uuid', nullable=True) 

83 executed_by = orm.relationship( 

84 'User', 

85 foreign_keys=[executed_by_uuid], 

86 cascade_backrefs=False, 

87 doc=""" 

88 :class:`~wuttjamaican.db.model.auth.User` who executed the 

89 upgrade. 

90 """) 

91 

92 exit_code = sa.Column(sa.Integer(), nullable=True, doc=""" 

93 Exit code for the upgrade execution process, if applicable. 

94 """) 

95 

96 def __str__(self): 

97 return str(self.description or "")