You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ka...@apache.org on 2023/05/18 19:21:39 UTC

[incubator-devlake] 01/03: fix: Fix Job.migrate on postgresql (#5194)

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

ka94 pushed a commit to branch release-v0.17
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 230f7df43a6feeba489d8370a743f26f7d4da07d
Author: Camille Teruel <ca...@gmail.com>
AuthorDate: Mon May 15 19:19:30 2023 +0200

    fix: Fix Job.migrate on postgresql (#5194)
    
    MySQL and postgresql don't have the same syntax to remove a primary key constraint.
    
    Co-authored-by: Camille Teruel <ca...@meri.co>
---
 backend/python/plugins/azuredevops/azuredevops/models.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/backend/python/plugins/azuredevops/azuredevops/models.py b/backend/python/plugins/azuredevops/azuredevops/models.py
index 35fc0e614..7e96e64cc 100644
--- a/backend/python/plugins/azuredevops/azuredevops/models.py
+++ b/backend/python/plugins/azuredevops/azuredevops/models.py
@@ -18,6 +18,8 @@ from enum import Enum
 from typing import Optional
 import re
 
+from sqlmodel import Session
+
 from pydevlake import Field, Connection, TransformationRule
 from pydevlake.model import ToolModel, ToolScope
 from pydevlake.pipeline_tasks import RefDiffOptions
@@ -121,3 +123,14 @@ class Job(ToolModel, table=True):
     finishTime: datetime.datetime
     state: State
     result: Result
+
+    @classmethod
+    def migrate(self, session: Session):
+        dialect = session.bind.dialect.name
+        if dialect == 'mysql':
+            session.execute(f'ALTER TABLE {self.__tablename__} DROP PRIMARY KEY')
+        elif dialect == 'postgresql':
+            session.execute(f'ALTER TABLE {self.__tablename__} DROP CONSTRAINT {self.__tablename__}_pkey')
+        else:
+            raise Exception(f'Unsupported dialect {dialect}')
+        session.execute(f'ALTER TABLE {self.__tablename__} ADD PRIMARY KEY (id, build_id)')