Mercurial > libervia-backend
comparison libervia/backend/memory/migration/versions/4b002773cf92_add_origin_id_column_to_history_and_.py @ 4071:4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 02 Jun 2023 11:49:51 +0200 |
parents | sat/memory/migration/versions/4b002773cf92_add_origin_id_column_to_history_and_.py@24c1c06c865b |
children | 0d7bb4df2343 |
comparison
equal
deleted
inserted
replaced
4070:d10748475025 | 4071:4b842c1fb686 |
---|---|
1 """add origin_id column to history and adapt constraints | |
2 | |
3 Revision ID: 4b002773cf92 | |
4 Revises: 79e5f3313fa4 | |
5 Create Date: 2022-06-13 16:10:39.711634 | |
6 | |
7 """ | |
8 from alembic import op | |
9 import sqlalchemy as sa | |
10 | |
11 | |
12 # revision identifiers, used by Alembic. | |
13 revision = '4b002773cf92' | |
14 down_revision = '79e5f3313fa4' | |
15 branch_labels = None | |
16 depends_on = None | |
17 | |
18 | |
19 def upgrade(): | |
20 with op.batch_alter_table('history', schema=None) as batch_op: | |
21 batch_op.add_column(sa.Column('origin_id', sa.Text(), nullable=True)) | |
22 batch_op.create_unique_constraint('uq_origin_id', ['profile_id', 'origin_id', 'source']) | |
23 | |
24 with op.batch_alter_table('message', schema=None) as batch_op: | |
25 batch_op.alter_column('history_uid', | |
26 existing_type=sa.TEXT(), | |
27 nullable=False) | |
28 batch_op.alter_column('message', | |
29 existing_type=sa.TEXT(), | |
30 nullable=False) | |
31 | |
32 with op.batch_alter_table('subject', schema=None) as batch_op: | |
33 batch_op.alter_column('history_uid', | |
34 existing_type=sa.TEXT(), | |
35 nullable=False) | |
36 batch_op.alter_column('subject', | |
37 existing_type=sa.TEXT(), | |
38 nullable=False) | |
39 | |
40 | |
41 def downgrade(): | |
42 with op.batch_alter_table('subject', schema=None) as batch_op: | |
43 batch_op.alter_column('subject', | |
44 existing_type=sa.TEXT(), | |
45 nullable=True) | |
46 batch_op.alter_column('history_uid', | |
47 existing_type=sa.TEXT(), | |
48 nullable=True) | |
49 | |
50 with op.batch_alter_table('message', schema=None) as batch_op: | |
51 batch_op.alter_column('message', | |
52 existing_type=sa.TEXT(), | |
53 nullable=True) | |
54 batch_op.alter_column('history_uid', | |
55 existing_type=sa.TEXT(), | |
56 nullable=True) | |
57 | |
58 with op.batch_alter_table('history', schema=None) as batch_op: | |
59 batch_op.drop_constraint('uq_origin_id', type_='unique') | |
60 batch_op.drop_column('origin_id') |