annotate libervia/backend/memory/migration/versions/4b002773cf92_add_origin_id_column_to_history_and_.py @ 4272:89a0999884ac default tip @

cli (list/set): add "--comments" argument.
author Goffi <goffi@goffi.org>
date Thu, 20 Jun 2024 14:46:55 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3796
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 """add origin_id column to history and adapt constraints
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 Revision ID: 4b002773cf92
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 Revises: 79e5f3313fa4
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Create Date: 2022-06-13 16:10:39.711634
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 """
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
8
3796
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 from alembic import op
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 import sqlalchemy as sa
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
12
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # revision identifiers, used by Alembic.
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
14 revision = "4b002773cf92"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
15 down_revision = "79e5f3313fa4"
3796
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 branch_labels = None
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 depends_on = None
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 def upgrade():
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
21 with op.batch_alter_table("history", schema=None) as batch_op:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
22 batch_op.add_column(sa.Column("origin_id", sa.Text(), nullable=True))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
23 batch_op.create_unique_constraint(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
24 "uq_origin_id", ["profile_id", "origin_id", "source"]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
25 )
3796
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
27 with op.batch_alter_table("message", schema=None) as batch_op:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
28 batch_op.alter_column("history_uid", existing_type=sa.TEXT(), nullable=False)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
29 batch_op.alter_column("message", existing_type=sa.TEXT(), nullable=False)
3796
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
31 with op.batch_alter_table("subject", schema=None) as batch_op:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
32 batch_op.alter_column("history_uid", existing_type=sa.TEXT(), nullable=False)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
33 batch_op.alter_column("subject", existing_type=sa.TEXT(), nullable=False)
3796
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 def downgrade():
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
37 with op.batch_alter_table("subject", schema=None) as batch_op:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
38 batch_op.alter_column("subject", existing_type=sa.TEXT(), nullable=True)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
39 batch_op.alter_column("history_uid", existing_type=sa.TEXT(), nullable=True)
3796
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
41 with op.batch_alter_table("message", schema=None) as batch_op:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
42 batch_op.alter_column("message", existing_type=sa.TEXT(), nullable=True)
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
43 batch_op.alter_column("history_uid", existing_type=sa.TEXT(), nullable=True)
3796
24c1c06c865b core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
45 with op.batch_alter_table("history", schema=None) as batch_op:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
46 batch_op.drop_constraint("uq_origin_id", type_="unique")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
47 batch_op.drop_column("origin_id")