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

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


The following commit(s) were added to refs/heads/main by this push:
     new 2affdffa7 fix: Fix Job.migrate on postgresql (#5194)
2affdffa7 is described below

commit 2affdffa7541552cf6e12bff7168a2592b60109a
Author: Camille Teruel <[email protected]>
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 <[email protected]>
---
 backend/python/plugins/azuredevops/azuredevops/models.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/backend/python/plugins/azuredevops/azuredevops/models.py 
b/backend/python/plugins/azuredevops/azuredevops/models.py
index 6d7f231f6..5952f410b 100644
--- a/backend/python/plugins/azuredevops/azuredevops/models.py
+++ b/backend/python/plugins/azuredevops/azuredevops/models.py
@@ -126,5 +126,11 @@ class Job(ToolModel, table=True):
 
     @classmethod
     def migrate(self, session: Session):
-        session.execute(f'ALTER TABLE {self.__tablename__} DROP PRIMARY KEY')
+        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)')

Reply via email to