Debian Codegraph @

taskflow/persistence/backends/sqlalchemy/alembic/versions/00af93df9d77_add_unique_into_all_indexes.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 """Add unique into all indexes
14
15 Revision ID: 00af93df9d77
16 Revises: 40fc8c914bd2
17 Create Date: 2025-02-28 15:44:37.066720
18
19 """
20
21 # revision identifiers, used by Alembic.
22 revision = '00af93df9d77'
23 down_revision = '40fc8c914bd2'
24
25 from alembic import op
26
27
28 def upgrade():
29 bind = op.get_bind()
30 engine = bind.engine
31 if engine.name == 'mysql':
32 with op.batch_alter_table("logbooks") as batch_op:
33 batch_op.drop_index("logbook_uuid_idx")
34 batch_op.create_index(
35 index_name="logbook_uuid_idx",
36 columns=['uuid'],
37 unique=True)
38
39 with op.batch_alter_table("flowdetails") as batch_op:
40 batch_op.drop_index("flowdetails_uuid_idx")
41 batch_op.create_index(
42 index_name="flowdetails_uuid_idx",
43 columns=['uuid'],
44 unique=True)
45
46 with op.batch_alter_table("atomdetails") as batch_op:
47 batch_op.drop_index("taskdetails_uuid_idx")
48 batch_op.create_index(
49 index_name="taskdetails_uuid_idx",
50 columns=['uuid'],
51 unique=True)
52
53
54 def downgrade():
55 bind = op.get_bind()
56 engine = bind.engine
57 if engine.name == 'mysql':
58 with op.batch_alter_table("logbooks") as batch_op:
59 batch_op.drop_index("logbook_uuid_idx")
60 batch_op.create_index(
61 index_name="logbook_uuid_idx",
62 columns=['uuid'])
63
64 with op.batch_alter_table("flowdetails") as batch_op:
65 batch_op.drop_index("flowdetails_uuid_idx")
66 batch_op.create_index(
67 index_name="flowdetails_uuid_idx",
68 columns=['uuid'])
69
70 with op.batch_alter_table("atomdetails") as batch_op:
71 batch_op.drop_index("taskdetails_uuid_idx")
72 batch_op.create_index(
73 index_name="taskdetails_uuid_idx",
74 columns=['uuid'])