comparison sat/memory/migration/versions/4b002773cf92_add_origin_id_column_to_history_and_.py @ 3796:24c1c06c865b

core (memory/mapping): add `origin_id` column to History + constraints update: - `origin_id` is added as a column instead of being just in extra, as it an important data to filter on. - Add some constraints. - Add `serialise` method to Message and Subject.
author Goffi <goffi@goffi.org>
date Fri, 17 Jun 2022 14:15:23 +0200
parents
children
comparison
equal deleted inserted replaced
3795:967a8e109cda 3796:24c1c06c865b
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')