This is an automated email from the ASF dual-hosted git repository.
camilleteruel pushed a commit to branch release-v0.17
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/release-v0.17 by this push:
new d9492fe33 fix: Add migration for nullable columns (#5420)
d9492fe33 is described below
commit d9492fe33677d5845c8fdcf5b5c55281e96176f2
Author: Camille Teruel <[email protected]>
AuthorDate: Fri Jun 9 13:12:58 2023 +0200
fix: Add migration for nullable columns (#5420)
Co-authored-by: Camille Teruel <[email protected]>
---
.../plugins/azuredevops/azuredevops/models.py | 23 ++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/backend/python/plugins/azuredevops/azuredevops/models.py
b/backend/python/plugins/azuredevops/azuredevops/models.py
index e61f58966..73ea30132 100644
--- a/backend/python/plugins/azuredevops/azuredevops/models.py
+++ b/backend/python/plugins/azuredevops/azuredevops/models.py
@@ -71,10 +71,16 @@ class GitPullRequest(ToolModel, table=True):
@classmethod
def migrate(self, session: Session):
dialect = session.bind.dialect.name
+ if dialect not in ['mysql', 'postgresql']:
+ raise Exception(f'Unsupported dialect {dialect}')
+ table = self.__tablename__
+
if dialect == 'mysql':
- session.execute(f'ALTER TABLE {self.__tablename__} MODIFY COLUMN
description TEXT')
+ session.execute(f'ALTER TABLE {table} MODIFY COLUMN description
TEXT')
+ session.execute(f'ALTER TABLE {table} MODIFY COLUMN
merge_commit_sha VARCHAR(255) NULL')
elif dialect == 'postgresql':
- session.execute(f'ALTER TABLE {self.__tablename__} ALTER COLUMN
description TYPE TEXT')
+ session.execute(f'ALTER TABLE {table} ALTER COLUMN description
TYPE TEXT')
+ session.execute(f'ALTER TABLE {table} ALTER COLUMN
merge_commit_sha DROP NOT NULL')
class GitPullRequestCommit(ToolModel, table=True):
@@ -109,6 +115,19 @@ class Build(ToolModel, table=True):
source_branch: str
source_version: str
+ @classmethod
+ def migrate(self, session: Session):
+ dialect = session.bind.dialect.name
+ if dialect not in ['mysql', 'postgresql']:
+ raise Exception(f'Unsupported dialect {dialect}')
+ table = self.__tablename__
+
+ # Make column result nullable
+ if dialect == 'mysql':
+ session.execute(f'ALTER TABLE {table} MODIFY COLUMN result
VARCHAR(255) NULL')
+ elif dialect == 'postgresql':
+ session.execute(f'ALTER TABLE {table} ALTER COLUMN "result" DROP
NOT NULL')
+
class Job(ToolModel, table=True):
class JobState(Enum):