refactoring: renamed sat package to libervia.backend
This commit is contained in:
parent
a15648d682
commit
d2685ba11b
6 changed files with 1293 additions and 1293 deletions
|
|
@ -0,0 +1,49 @@
|
|||
"""create virtual table for Full-Text Search
|
||||
|
||||
Revision ID: 129ac51807e4
|
||||
Revises: 8974efc51d22
|
||||
Create Date: 2021-08-13 19:13:54.112538
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '129ac51807e4'
|
||||
down_revision = '8974efc51d22'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
queries = [
|
||||
"CREATE VIRTUAL TABLE pubsub_items_fts "
|
||||
"USING fts5(data, content=pubsub_items, content_rowid=id)",
|
||||
"CREATE TRIGGER pubsub_items_fts_sync_ins AFTER INSERT ON pubsub_items BEGIN"
|
||||
" INSERT INTO pubsub_items_fts(rowid, data) VALUES (new.id, new.data);"
|
||||
"END",
|
||||
"CREATE TRIGGER pubsub_items_fts_sync_del AFTER DELETE ON pubsub_items BEGIN"
|
||||
" INSERT INTO pubsub_items_fts(pubsub_items_fts, rowid, data) "
|
||||
"VALUES('delete', old.id, old.data);"
|
||||
"END",
|
||||
"CREATE TRIGGER pubsub_items_fts_sync_upd AFTER UPDATE ON pubsub_items BEGIN"
|
||||
" INSERT INTO pubsub_items_fts(pubsub_items_fts, rowid, data) VALUES"
|
||||
"('delete', old.id, old.data);"
|
||||
" INSERT INTO pubsub_items_fts(rowid, data) VALUES(new.id, new.data);"
|
||||
"END",
|
||||
"INSERT INTO pubsub_items_fts(rowid, data) SELECT id, data from pubsub_items"
|
||||
]
|
||||
for q in queries:
|
||||
op.execute(sa.DDL(q))
|
||||
|
||||
|
||||
def downgrade():
|
||||
queries = [
|
||||
"DROP TRIGGER IF EXISTS pubsub_items_fts_sync_ins",
|
||||
"DROP TRIGGER IF EXISTS pubsub_items_fts_sync_del",
|
||||
"DROP TRIGGER IF EXISTS pubsub_items_fts_sync_upd",
|
||||
"DROP TABLE IF EXISTS pubsub_items_fts",
|
||||
]
|
||||
for q in queries:
|
||||
op.execute(sa.DDL(q))
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
"""add origin_id column to history and adapt constraints
|
||||
|
||||
Revision ID: 4b002773cf92
|
||||
Revises: 79e5f3313fa4
|
||||
Create Date: 2022-06-13 16:10:39.711634
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '4b002773cf92'
|
||||
down_revision = '79e5f3313fa4'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
with op.batch_alter_table('history', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('origin_id', sa.Text(), nullable=True))
|
||||
batch_op.create_unique_constraint('uq_origin_id', ['profile_id', 'origin_id', 'source'])
|
||||
|
||||
with op.batch_alter_table('message', schema=None) as batch_op:
|
||||
batch_op.alter_column('history_uid',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=False)
|
||||
batch_op.alter_column('message',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=False)
|
||||
|
||||
with op.batch_alter_table('subject', schema=None) as batch_op:
|
||||
batch_op.alter_column('history_uid',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=False)
|
||||
batch_op.alter_column('subject',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table('subject', schema=None) as batch_op:
|
||||
batch_op.alter_column('subject',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=True)
|
||||
batch_op.alter_column('history_uid',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=True)
|
||||
|
||||
with op.batch_alter_table('message', schema=None) as batch_op:
|
||||
batch_op.alter_column('message',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=True)
|
||||
batch_op.alter_column('history_uid',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=True)
|
||||
|
||||
with op.batch_alter_table('history', schema=None) as batch_op:
|
||||
batch_op.drop_constraint('uq_origin_id', type_='unique')
|
||||
batch_op.drop_column('origin_id')
|
||||
|
|
@ -0,0 +1,410 @@
|
|||
"""drop message_types table + fix nullable + rename constraints
|
||||
|
||||
Revision ID: 602caf848068
|
||||
Revises:
|
||||
Create Date: 2021-06-26 12:42:54.148313
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
from sqlalchemy import (
|
||||
Table,
|
||||
Column,
|
||||
MetaData,
|
||||
TEXT,
|
||||
INTEGER,
|
||||
Text,
|
||||
Integer,
|
||||
Float,
|
||||
Enum,
|
||||
ForeignKey,
|
||||
Index,
|
||||
PrimaryKeyConstraint,
|
||||
)
|
||||
from sqlalchemy.sql import table, column
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "602caf848068"
|
||||
down_revision = None
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# we have to recreate former tables for batch_alter_table's reflexion, otherwise the
|
||||
# database will be used, and this will keep unammed UNIQUE constraints in addition
|
||||
# to the named ones that we create
|
||||
metadata = MetaData(
|
||||
naming_convention={
|
||||
"ix": "ix_%(column_0_label)s",
|
||||
"uq": "uq_%(table_name)s_%(column_0_name)s",
|
||||
"ck": "ck_%(table_name)s_%(constraint_name)s",
|
||||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
||||
"pk": "pk_%(table_name)s",
|
||||
},
|
||||
)
|
||||
|
||||
old_profiles_table = Table(
|
||||
"profiles",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=True, autoincrement=False),
|
||||
Column("name", Text, unique=True),
|
||||
)
|
||||
|
||||
old_components_table = Table(
|
||||
"components",
|
||||
metadata,
|
||||
Column(
|
||||
"profile_id",
|
||||
ForeignKey("profiles.id", ondelete="CASCADE"),
|
||||
nullable=True,
|
||||
primary_key=True,
|
||||
),
|
||||
Column("entry_point", Text, nullable=False),
|
||||
)
|
||||
|
||||
old_message_table = Table(
|
||||
"message",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=True, autoincrement=False),
|
||||
Column("history_uid", ForeignKey("history.uid", ondelete="CASCADE")),
|
||||
Column("message", Text),
|
||||
Column("language", Text),
|
||||
Index("message__history_uid", "history_uid"),
|
||||
)
|
||||
|
||||
old_subject_table = Table(
|
||||
"subject",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=True, autoincrement=False),
|
||||
Column("history_uid", ForeignKey("history.uid", ondelete="CASCADE")),
|
||||
Column("subject", Text),
|
||||
Column("language", Text),
|
||||
Index("subject__history_uid", "history_uid"),
|
||||
)
|
||||
|
||||
old_thread_table = Table(
|
||||
"thread",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=True, autoincrement=False),
|
||||
Column("history_uid", ForeignKey("history.uid", ondelete="CASCADE")),
|
||||
Column("thread_id", Text),
|
||||
Column("parent_id", Text),
|
||||
Index("thread__history_uid", "history_uid"),
|
||||
)
|
||||
|
||||
old_history_table = Table(
|
||||
"history",
|
||||
metadata,
|
||||
Column("uid", Text, primary_key=True, nullable=True),
|
||||
Column("stanza_id", Text),
|
||||
Column("update_uid", Text),
|
||||
Column("profile_id", Integer, ForeignKey("profiles.id", ondelete="CASCADE")),
|
||||
Column("source", Text),
|
||||
Column("dest", Text),
|
||||
Column("source_res", Text),
|
||||
Column("dest_res", Text),
|
||||
Column("timestamp", Float, nullable=False),
|
||||
Column("received_timestamp", Float),
|
||||
Column("type", Text, ForeignKey("message_types.type")),
|
||||
Column("extra", Text),
|
||||
Index("history__profile_id_timestamp", "profile_id", "timestamp"),
|
||||
Index(
|
||||
"history__profile_id_received_timestamp", "profile_id", "received_timestamp"
|
||||
),
|
||||
)
|
||||
|
||||
old_param_gen_table = Table(
|
||||
"param_gen",
|
||||
metadata,
|
||||
Column("category", Text, primary_key=True),
|
||||
Column("name", Text, primary_key=True),
|
||||
Column("value", Text),
|
||||
)
|
||||
|
||||
old_param_ind_table = Table(
|
||||
"param_ind",
|
||||
metadata,
|
||||
Column("category", Text, primary_key=True),
|
||||
Column("name", Text, primary_key=True),
|
||||
Column(
|
||||
"profile_id", ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True
|
||||
),
|
||||
Column("value", Text),
|
||||
)
|
||||
|
||||
old_private_gen_table = Table(
|
||||
"private_gen",
|
||||
metadata,
|
||||
Column("namespace", Text, primary_key=True),
|
||||
Column("key", Text, primary_key=True),
|
||||
Column("value", Text),
|
||||
)
|
||||
|
||||
old_private_ind_table = Table(
|
||||
"private_ind",
|
||||
metadata,
|
||||
Column("namespace", Text, primary_key=True),
|
||||
Column("key", Text, primary_key=True),
|
||||
Column(
|
||||
"profile_id", ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True
|
||||
),
|
||||
Column("value", Text),
|
||||
)
|
||||
|
||||
old_private_gen_bin_table = Table(
|
||||
"private_gen_bin",
|
||||
metadata,
|
||||
Column("namespace", Text, primary_key=True),
|
||||
Column("key", Text, primary_key=True),
|
||||
Column("value", Text),
|
||||
)
|
||||
|
||||
old_private_ind_bin_table = Table(
|
||||
"private_ind_bin",
|
||||
metadata,
|
||||
Column("namespace", Text, primary_key=True),
|
||||
Column("key", Text, primary_key=True),
|
||||
Column(
|
||||
"profile_id", ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True
|
||||
),
|
||||
Column("value", Text),
|
||||
)
|
||||
|
||||
old_files_table = Table(
|
||||
"files",
|
||||
metadata,
|
||||
Column("id", Text, primary_key=True),
|
||||
Column("public_id", Text, unique=True),
|
||||
Column("version", Text, primary_key=True),
|
||||
Column("parent", Text, nullable=False),
|
||||
Column(
|
||||
"type",
|
||||
Enum("file", "directory", name="file_type", create_constraint=True),
|
||||
nullable=False,
|
||||
server_default="file",
|
||||
),
|
||||
Column("file_hash", Text),
|
||||
Column("hash_algo", Text),
|
||||
Column("name", Text, nullable=False),
|
||||
Column("size", Integer),
|
||||
Column("namespace", Text),
|
||||
Column("media_type", Text),
|
||||
Column("media_subtype", Text),
|
||||
Column("created", Float, nullable=False),
|
||||
Column("modified", Float),
|
||||
Column("owner", Text),
|
||||
Column("access", Text),
|
||||
Column("extra", Text),
|
||||
Column("profile_id", ForeignKey("profiles.id", ondelete="CASCADE")),
|
||||
Index("files__profile_id_owner_parent", "profile_id", "owner", "parent"),
|
||||
Index(
|
||||
"files__profile_id_owner_media_type_media_subtype",
|
||||
"profile_id",
|
||||
"owner",
|
||||
"media_type",
|
||||
"media_subtype",
|
||||
),
|
||||
)
|
||||
|
||||
op.drop_table("message_types")
|
||||
|
||||
with op.batch_alter_table(
|
||||
"profiles", copy_from=old_profiles_table, schema=None
|
||||
) as batch_op:
|
||||
batch_op.create_unique_constraint(batch_op.f("uq_profiles_name"), ["name"])
|
||||
|
||||
with op.batch_alter_table(
|
||||
"components",
|
||||
copy_from=old_components_table,
|
||||
naming_convention={
|
||||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
||||
},
|
||||
schema=None,
|
||||
) as batch_op:
|
||||
batch_op.create_unique_constraint(batch_op.f("uq_profiles_name"), ["name"])
|
||||
|
||||
with op.batch_alter_table(
|
||||
"history",
|
||||
copy_from=old_history_table,
|
||||
naming_convention={
|
||||
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
||||
},
|
||||
schema=None,
|
||||
) as batch_op:
|
||||
batch_op.alter_column("uid", existing_type=TEXT(), nullable=False)
|
||||
batch_op.alter_column(
|
||||
"type",
|
||||
type_=Enum(
|
||||
"chat",
|
||||
"error",
|
||||
"groupchat",
|
||||
"headline",
|
||||
"normal",
|
||||
"info",
|
||||
name="message_type",
|
||||
create_constraint=True,
|
||||
),
|
||||
existing_type=TEXT(),
|
||||
nullable=False,
|
||||
)
|
||||
batch_op.create_unique_constraint(
|
||||
batch_op.f("uq_history_profile_id"),
|
||||
["profile_id", "stanza_id", "source", "dest"],
|
||||
)
|
||||
batch_op.drop_constraint("fk_history_type_message_types", type_="foreignkey")
|
||||
|
||||
with op.batch_alter_table(
|
||||
"message", copy_from=old_message_table, schema=None
|
||||
) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"id", existing_type=INTEGER(), nullable=False, autoincrement=False
|
||||
)
|
||||
|
||||
with op.batch_alter_table(
|
||||
"subject", copy_from=old_subject_table, schema=None
|
||||
) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"id", existing_type=INTEGER(), nullable=False, autoincrement=False
|
||||
)
|
||||
|
||||
with op.batch_alter_table(
|
||||
"thread", copy_from=old_thread_table, schema=None
|
||||
) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"id", existing_type=INTEGER(), nullable=False, autoincrement=False
|
||||
)
|
||||
|
||||
with op.batch_alter_table(
|
||||
"param_gen", copy_from=old_param_gen_table, schema=None
|
||||
) as batch_op:
|
||||
batch_op.alter_column("category", existing_type=TEXT(), nullable=False)
|
||||
batch_op.alter_column("name", existing_type=TEXT(), nullable=False)
|
||||
|
||||
with op.batch_alter_table(
|
||||
"param_ind", copy_from=old_param_ind_table, schema=None
|
||||
) as batch_op:
|
||||
batch_op.alter_column("category", existing_type=TEXT(), nullable=False)
|
||||
batch_op.alter_column("name", existing_type=TEXT(), nullable=False)
|
||||
batch_op.alter_column("profile_id", existing_type=INTEGER(), nullable=False)
|
||||
|
||||
with op.batch_alter_table(
|
||||
"private_gen", copy_from=old_private_gen_table, schema=None
|
||||
) as batch_op:
|
||||
batch_op.alter_column("namespace", existing_type=TEXT(), nullable=False)
|
||||
batch_op.alter_column("key", existing_type=TEXT(), nullable=False)
|
||||
|
||||
with op.batch_alter_table(
|
||||
"private_ind", copy_from=old_private_ind_table, schema=None
|
||||
) as batch_op:
|
||||
batch_op.alter_column("namespace", existing_type=TEXT(), nullable=False)
|
||||
batch_op.alter_column("key", existing_type=TEXT(), nullable=False)
|
||||
batch_op.alter_column("profile_id", existing_type=INTEGER(), nullable=False)
|
||||
|
||||
with op.batch_alter_table(
|
||||
"private_gen_bin", copy_from=old_private_gen_bin_table, schema=None
|
||||
) as batch_op:
|
||||
batch_op.alter_column("namespace", existing_type=TEXT(), nullable=False)
|
||||
batch_op.alter_column("key", existing_type=TEXT(), nullable=False)
|
||||
|
||||
# found some invalid rows in local database, maybe old values made during development,
|
||||
# but in doubt we have to delete them
|
||||
op.execute("DELETE FROM private_ind_bin WHERE namespace IS NULL")
|
||||
|
||||
with op.batch_alter_table(
|
||||
"private_ind_bin", copy_from=old_private_ind_bin_table, schema=None
|
||||
) as batch_op:
|
||||
batch_op.alter_column("namespace", existing_type=TEXT(), nullable=False)
|
||||
batch_op.alter_column("key", existing_type=TEXT(), nullable=False)
|
||||
batch_op.alter_column("profile_id", existing_type=INTEGER(), nullable=False)
|
||||
|
||||
with op.batch_alter_table(
|
||||
"files", copy_from=old_files_table, schema=None
|
||||
) as batch_op:
|
||||
batch_op.create_unique_constraint(batch_op.f("uq_files_public_id"), ["public_id"])
|
||||
batch_op.alter_column(
|
||||
"type",
|
||||
type_=Enum("file", "directory", name="file_type", create_constraint=True),
|
||||
existing_type=Text(),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
# downgrade doesn't restore the exact same state as before upgrade, as it
|
||||
# would be useless and waste of resource to restore broken things such as
|
||||
# anonymous constraints
|
||||
with op.batch_alter_table("thread", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"id", existing_type=INTEGER(), nullable=True, autoincrement=False
|
||||
)
|
||||
|
||||
with op.batch_alter_table("subject", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"id", existing_type=INTEGER(), nullable=True, autoincrement=False
|
||||
)
|
||||
|
||||
with op.batch_alter_table("private_ind_bin", schema=None) as batch_op:
|
||||
batch_op.alter_column("profile_id", existing_type=INTEGER(), nullable=True)
|
||||
batch_op.alter_column("key", existing_type=TEXT(), nullable=True)
|
||||
batch_op.alter_column("namespace", existing_type=TEXT(), nullable=True)
|
||||
|
||||
with op.batch_alter_table("private_ind", schema=None) as batch_op:
|
||||
batch_op.alter_column("profile_id", existing_type=INTEGER(), nullable=True)
|
||||
batch_op.alter_column("key", existing_type=TEXT(), nullable=True)
|
||||
batch_op.alter_column("namespace", existing_type=TEXT(), nullable=True)
|
||||
|
||||
with op.batch_alter_table("private_gen_bin", schema=None) as batch_op:
|
||||
batch_op.alter_column("key", existing_type=TEXT(), nullable=True)
|
||||
batch_op.alter_column("namespace", existing_type=TEXT(), nullable=True)
|
||||
|
||||
with op.batch_alter_table("private_gen", schema=None) as batch_op:
|
||||
batch_op.alter_column("key", existing_type=TEXT(), nullable=True)
|
||||
batch_op.alter_column("namespace", existing_type=TEXT(), nullable=True)
|
||||
|
||||
with op.batch_alter_table("param_ind", schema=None) as batch_op:
|
||||
batch_op.alter_column("profile_id", existing_type=INTEGER(), nullable=True)
|
||||
batch_op.alter_column("name", existing_type=TEXT(), nullable=True)
|
||||
batch_op.alter_column("category", existing_type=TEXT(), nullable=True)
|
||||
|
||||
with op.batch_alter_table("param_gen", schema=None) as batch_op:
|
||||
batch_op.alter_column("name", existing_type=TEXT(), nullable=True)
|
||||
batch_op.alter_column("category", existing_type=TEXT(), nullable=True)
|
||||
|
||||
with op.batch_alter_table("message", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"id", existing_type=INTEGER(), nullable=True, autoincrement=False
|
||||
)
|
||||
|
||||
op.create_table(
|
||||
"message_types",
|
||||
Column("type", TEXT(), nullable=True),
|
||||
PrimaryKeyConstraint("type"),
|
||||
)
|
||||
message_types_table = table("message_types", column("type", TEXT()))
|
||||
op.bulk_insert(
|
||||
message_types_table,
|
||||
[
|
||||
{"type": "chat"},
|
||||
{"type": "error"},
|
||||
{"type": "groupchat"},
|
||||
{"type": "headline"},
|
||||
{"type": "normal"},
|
||||
{"type": "info"},
|
||||
],
|
||||
)
|
||||
|
||||
with op.batch_alter_table("history", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
"type",
|
||||
type_=TEXT(),
|
||||
existing_type=TEXT(),
|
||||
nullable=True,
|
||||
)
|
||||
batch_op.create_foreign_key(
|
||||
batch_op.f("fk_history_type_message_types"),
|
||||
"message_types",
|
||||
["type"],
|
||||
["type"],
|
||||
)
|
||||
batch_op.alter_column("uid", existing_type=TEXT(), nullable=True)
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
"""create table for pubsub subscriptions
|
||||
|
||||
Revision ID: 79e5f3313fa4
|
||||
Revises: 129ac51807e4
|
||||
Create Date: 2022-03-14 17:15:00.689871
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from libervia.backend.memory.sqla_mapping import JID
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '79e5f3313fa4'
|
||||
down_revision = '129ac51807e4'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_table('pubsub_subs',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('node_id', sa.Integer(), nullable=False),
|
||||
sa.Column('subscriber', JID(), nullable=True),
|
||||
sa.Column('state', sa.Enum('SUBSCRIBED', 'PENDING', name='state'), nullable=True),
|
||||
sa.ForeignKeyConstraint(['node_id'], ['pubsub_nodes.id'], name=op.f('fk_pubsub_subs_node_id_pubsub_nodes'), ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_pubsub_subs')),
|
||||
sa.UniqueConstraint('node_id', 'subscriber', name=op.f('uq_pubsub_subs_node_id'))
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('pubsub_subs')
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
"""create tables for Pubsub caching
|
||||
|
||||
Revision ID: 8974efc51d22
|
||||
Revises: 602caf848068
|
||||
Create Date: 2021-07-27 16:38:54.658212
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from libervia.backend.memory.sqla_mapping import JID, Xml
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '8974efc51d22'
|
||||
down_revision = '602caf848068'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('pubsub_nodes',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('profile_id', sa.Integer(), nullable=True),
|
||||
sa.Column('service', JID(), nullable=True),
|
||||
sa.Column('name', sa.Text(), nullable=False),
|
||||
sa.Column('subscribed', sa.Boolean(create_constraint=True, name='subscribed_bool'), nullable=False),
|
||||
sa.Column('analyser', sa.Text(), nullable=True),
|
||||
sa.Column('sync_state', sa.Enum('IN_PROGRESS', 'COMPLETED', 'ERROR', 'NO_SYNC', name='sync_state', create_constraint=True), nullable=True),
|
||||
sa.Column('sync_state_updated', sa.Float(), nullable=False),
|
||||
sa.Column('type', sa.Text(), nullable=True),
|
||||
sa.Column('subtype', sa.Text(), nullable=True),
|
||||
sa.Column('extra', sa.JSON(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['profile_id'], ['profiles.id'], name=op.f('fk_pubsub_nodes_profile_id_profiles'), ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_pubsub_nodes')),
|
||||
sa.UniqueConstraint('profile_id', 'service', 'name', name=op.f('uq_pubsub_nodes_profile_id'))
|
||||
)
|
||||
op.create_table('pubsub_items',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('node_id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.Text(), nullable=False),
|
||||
sa.Column('data', Xml(), nullable=False),
|
||||
sa.Column('created', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('updated', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.Column('parsed', sa.JSON(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['node_id'], ['pubsub_nodes.id'], name=op.f('fk_pubsub_items_node_id_pubsub_nodes'), ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id', name=op.f('pk_pubsub_items')),
|
||||
sa.UniqueConstraint('node_id', 'name', name=op.f('uq_pubsub_items_node_id'))
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('pubsub_items')
|
||||
op.drop_table('pubsub_nodes')
|
||||
# ### end Alembic commands ###
|
||||
0
libervia/backend/memory/migration/versions/__init__.py
Normal file
0
libervia/backend/memory/migration/versions/__init__.py
Normal file
Loading…
Reference in a new issue