Coverage for mindsdb / migrations / versions / 2022-12-26_459218b0844c_fix_unique_constraint.py: 41%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-21 00:36 +0000

1"""fix_unique_constraint 

2 

3Revision ID: 459218b0844c 

4Revises: d429095b570f 

5Create Date: 2022-12-26 13:40:57.141241 

6 

7""" 

8from alembic import op 

9 

10revision = '459218b0844c' 

11down_revision = 'd429095b570f' 

12branch_labels = None 

13depends_on = None 

14 

15 

16def upgrade(): 

17 

18 # try - for sqlite database 

19 try: 

20 op.execute("ALTER TABLE project DROP CONSTRAINT IF EXISTS unique_integration_name_company_id") 

21 op.execute("ALTER TABLE project DROP CONSTRAINT IF EXISTS unique_project_name_company_id") 

22 except Exception: 

23 pass 

24 

25 try: 

26 with op.batch_alter_table('project', schema=None) as batch_op: 

27 batch_op.create_unique_constraint('unique_project_name_company_id', ['name', 'company_id']) 

28 except Exception: 

29 pass 

30 

31 

32def downgrade(): 

33 # do nothing 

34 ...