Skip to content

Commit d9492fe

Browse files
CamilleTeruelCamille Teruel
andauthored
fix: Add migration for nullable columns (#5420)
Co-authored-by: Camille Teruel <camille.teruel@meri.co>
1 parent c7a8c87 commit d9492fe

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

  • backend/python/plugins/azuredevops/azuredevops

backend/python/plugins/azuredevops/azuredevops/models.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,16 @@ class PRStatus(Enum):
7171
@classmethod
7272
def migrate(self, session: Session):
7373
dialect = session.bind.dialect.name
74+
if dialect not in ['mysql', 'postgresql']:
75+
raise Exception(f'Unsupported dialect {dialect}')
76+
table = self.__tablename__
77+
7478
if dialect == 'mysql':
75-
session.execute(f'ALTER TABLE {self.__tablename__} MODIFY COLUMN description TEXT')
79+
session.execute(f'ALTER TABLE {table} MODIFY COLUMN description TEXT')
80+
session.execute(f'ALTER TABLE {table} MODIFY COLUMN merge_commit_sha VARCHAR(255) NULL')
7681
elif dialect == 'postgresql':
77-
session.execute(f'ALTER TABLE {self.__tablename__} ALTER COLUMN description TYPE TEXT')
82+
session.execute(f'ALTER TABLE {table} ALTER COLUMN description TYPE TEXT')
83+
session.execute(f'ALTER TABLE {table} ALTER COLUMN merge_commit_sha DROP NOT NULL')
7884

7985

8086
class GitPullRequestCommit(ToolModel, table=True):
@@ -109,6 +115,19 @@ class BuildResult(Enum):
109115
source_branch: str
110116
source_version: str
111117

118+
@classmethod
119+
def migrate(self, session: Session):
120+
dialect = session.bind.dialect.name
121+
if dialect not in ['mysql', 'postgresql']:
122+
raise Exception(f'Unsupported dialect {dialect}')
123+
table = self.__tablename__
124+
125+
# Make column result nullable
126+
if dialect == 'mysql':
127+
session.execute(f'ALTER TABLE {table} MODIFY COLUMN result VARCHAR(255) NULL')
128+
elif dialect == 'postgresql':
129+
session.execute(f'ALTER TABLE {table} ALTER COLUMN "result" DROP NOT NULL')
130+
112131

113132
class Job(ToolModel, table=True):
114133
class JobState(Enum):

0 commit comments

Comments
 (0)