This is an automated email from the ASF dual-hosted git repository.

camilleteruel pushed a commit to branch migrate_nullable_columns
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 24f1f187efbf05e9b71b8d9760087c6c6b8d27d9
Author: Camille Teruel <[email protected]>
AuthorDate: Fri Jun 9 12:53:22 2023 +0200

    fix: Add migration for nullable columns
---
 .../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):

Reply via email to