annotate libervia/backend/memory/migration/versions/2ab01aa1f686_create_table_for_notifications.py @ 4304:92a886f31581 default tip @

doc (components): new Email gateway documentation: fix 449
author Goffi <goffi@goffi.org>
date Fri, 06 Sep 2024 18:07:44 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4130
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 """create table for notifications
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 Revision ID: 2ab01aa1f686
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 Revises: 4b002773cf92
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Create Date: 2023-10-16 12:11:43.507295
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 """
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
8
4130
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 from alembic import op
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 import sqlalchemy as sa
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12
02f0adc745c6 core: notifications implementation, first draft:
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: 4130
diff changeset
14 revision = "2ab01aa1f686"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
15 down_revision = "4b002773cf92"
4130
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 branch_labels = None
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 depends_on = None
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 def upgrade():
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
21 op.create_table(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
22 "notifications",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
23 sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
24 sa.Column("timestamp", sa.Float(), nullable=False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
25 sa.Column("expire_at", sa.Float(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
26 sa.Column("profile_id", sa.Integer(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
27 sa.Column(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
28 "type",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
29 sa.Enum(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
30 "chat",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
31 "blog",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
32 "calendar",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
33 "file",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
34 "call",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
35 "service",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
36 "other",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
37 name="notificationtype",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
38 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
39 nullable=False,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
40 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
41 sa.Column("title", sa.Text(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
42 sa.Column("body_plain", sa.Text(), nullable=False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
43 sa.Column("body_rich", sa.Text(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
44 sa.Column("requires_action", sa.Boolean(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
45 sa.Column("priority", sa.Integer(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
46 sa.Column("extra_data", sa.JSON(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
47 sa.Column(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
48 "status", sa.Enum("new", "read", name="notificationstatus"), nullable=True
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
49 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
50 sa.ForeignKeyConstraint(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
51 ["profile_id"],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
52 ["profiles.id"],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
53 name=op.f("fk_notifications_profile_id_profiles"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
54 ondelete="CASCADE",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
55 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
56 sa.PrimaryKeyConstraint("id", name=op.f("pk_notifications")),
4130
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 )
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
58 with op.batch_alter_table("notifications", schema=None) as batch_op:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
59 batch_op.create_index(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
60 batch_op.f("ix_notifications_profile_id"), ["profile_id"], unique=False
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
61 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
62 batch_op.create_index(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
63 "notifications_profile_id_status", ["profile_id", "status"], unique=False
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
64 )
4130
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 def downgrade():
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
68 with op.batch_alter_table("notifications", schema=None) as batch_op:
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
69 batch_op.drop_index("notifications_profile_id_status")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
70 batch_op.drop_index(batch_op.f("ix_notifications_profile_id"))
4130
02f0adc745c6 core: notifications implementation, first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4130
diff changeset
72 op.drop_table("notifications")