55Create Date: 2025-02-22 14:59:30.668466
66
77"""
8+
89from typing import Sequence , Union
910
1011from alembic import op
11- import sqlalchemy as sa
12- from alembic .context import get_context
1312
1413
1514# revision identifiers, used by Alembic.
16- revision : str = ' b3c3938bacdb'
17- down_revision : Union [str , None ] = ' 3dae7c7b1564'
15+ revision : str = " b3c3938bacdb"
16+ down_revision : Union [str , None ] = " 3dae7c7b1564"
1817branch_labels : Union [str , Sequence [str ], None ] = None
1918depends_on : Union [str , Sequence [str ], None ] = None
2019
2120
2221def upgrade () -> None :
2322 # SQLite doesn't support constraint changes through ALTER
2423 # Need to recreate table with desired constraints
25- with op .batch_alter_table (' relation' ) as batch_op :
24+ with op .batch_alter_table (" relation" ) as batch_op :
2625 # Drop existing unique constraint
27- batch_op .drop_constraint (' uix_relation' , type_ = ' unique' )
28-
26+ batch_op .drop_constraint (" uix_relation" , type_ = " unique" )
27+
2928 # Add new constraints
3029 batch_op .create_unique_constraint (
31- 'uix_relation_from_id_to_id' ,
32- ['from_id' , 'to_id' , 'relation_type' ]
30+ "uix_relation_from_id_to_id" , ["from_id" , "to_id" , "relation_type" ]
3331 )
3432 batch_op .create_unique_constraint (
35- 'uix_relation_from_id_to_name' ,
36- ['from_id' , 'to_name' , 'relation_type' ]
33+ "uix_relation_from_id_to_name" , ["from_id" , "to_name" , "relation_type" ]
3734 )
3835
3936
4037def downgrade () -> None :
41- with op .batch_alter_table (' relation' ) as batch_op :
38+ with op .batch_alter_table (" relation" ) as batch_op :
4239 # Drop new constraints
43- batch_op .drop_constraint (' uix_relation_from_id_to_name' , type_ = ' unique' )
44- batch_op .drop_constraint (' uix_relation_from_id_to_id' , type_ = ' unique' )
45-
40+ batch_op .drop_constraint (" uix_relation_from_id_to_name" , type_ = " unique" )
41+ batch_op .drop_constraint (" uix_relation_from_id_to_id" , type_ = " unique" )
42+
4643 # Restore original constraint
47- batch_op .create_unique_constraint (
48- 'uix_relation' ,
49- ['from_id' , 'to_id' , 'relation_type' ]
50- )
44+ batch_op .create_unique_constraint ("uix_relation" , ["from_id" , "to_id" , "relation_type" ])
0 commit comments