annotate libervia/backend/memory/migration/versions/8974efc51d22_create_tables_for_pubsub_caching.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 4b842c1fb686
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3594
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
1 """create tables for Pubsub caching
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
2
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
3 Revision ID: 8974efc51d22
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
4 Revises: 602caf848068
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Create Date: 2021-07-27 16:38:54.658212
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
6
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
7 """
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
8
3594
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
9 from alembic import op
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
10 import sqlalchemy as sa
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 3594
diff changeset
11 from libervia.backend.memory.sqla_mapping import JID, Xml
3594
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
12
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
13
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # revision identifiers, used by Alembic.
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
15 revision = "8974efc51d22"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
16 down_revision = "602caf848068"
3594
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
17 branch_labels = None
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
18 depends_on = None
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
19
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
20
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
21 def upgrade():
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
22 # ### commands auto generated by Alembic - please adjust! ###
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
23 op.create_table(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
24 "pubsub_nodes",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
25 sa.Column("id", sa.Integer(), nullable=False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
26 sa.Column("profile_id", sa.Integer(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
27 sa.Column("service", JID(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
28 sa.Column("name", sa.Text(), nullable=False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
29 sa.Column(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
30 "subscribed",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
31 sa.Boolean(create_constraint=True, name="subscribed_bool"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
32 nullable=False,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
33 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
34 sa.Column("analyser", sa.Text(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
35 sa.Column(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
36 "sync_state",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
37 sa.Enum(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
38 "IN_PROGRESS",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
39 "COMPLETED",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
40 "ERROR",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
41 "NO_SYNC",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
42 name="sync_state",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
43 create_constraint=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
44 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
45 nullable=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
46 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
47 sa.Column("sync_state_updated", sa.Float(), nullable=False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
48 sa.Column("type", sa.Text(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
49 sa.Column("subtype", sa.Text(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
50 sa.Column("extra", sa.JSON(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
51 sa.ForeignKeyConstraint(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
52 ["profile_id"],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
53 ["profiles.id"],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
54 name=op.f("fk_pubsub_nodes_profile_id_profiles"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
55 ondelete="CASCADE",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
56 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
57 sa.PrimaryKeyConstraint("id", name=op.f("pk_pubsub_nodes")),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
58 sa.UniqueConstraint(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
59 "profile_id", "service", "name", name=op.f("uq_pubsub_nodes_profile_id")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
60 ),
3594
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
61 )
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
62 op.create_table(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
63 "pubsub_items",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
64 sa.Column("id", sa.Integer(), nullable=False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
65 sa.Column("node_id", sa.Integer(), nullable=False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
66 sa.Column("name", sa.Text(), nullable=False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
67 sa.Column("data", Xml(), nullable=False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
68 sa.Column(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
69 "created",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
70 sa.DateTime(),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
71 server_default=sa.text("(CURRENT_TIMESTAMP)"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
72 nullable=False,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
73 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
74 sa.Column(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
75 "updated",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
76 sa.DateTime(),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
77 server_default=sa.text("(CURRENT_TIMESTAMP)"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
78 nullable=False,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
79 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
80 sa.Column("parsed", sa.JSON(), nullable=True),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
81 sa.ForeignKeyConstraint(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
82 ["node_id"],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
83 ["pubsub_nodes.id"],
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
84 name=op.f("fk_pubsub_items_node_id_pubsub_nodes"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
85 ondelete="CASCADE",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
86 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
87 sa.PrimaryKeyConstraint("id", name=op.f("pk_pubsub_items")),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
88 sa.UniqueConstraint("node_id", "name", name=op.f("uq_pubsub_items_node_id")),
3594
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
89 )
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
90 # ### end Alembic commands ###
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
91
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
92
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
93 def downgrade():
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
94 # ### commands auto generated by Alembic - please adjust! ###
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
95 op.drop_table("pubsub_items")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
96 op.drop_table("pubsub_nodes")
3594
d5116197e403 migration: script to create pubsub caching tables
Goffi <goffi@goffi.org>
parents:
diff changeset
97 # ### end Alembic commands ###