Mercurial > libervia-backend
diff sat/memory/migration/versions/79e5f3313fa4_create_table_for_pubsub_subscriptions.py @ 3744:658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
node subscriptions can now be cached, this can be useful for components which must keep
track of subscibers.
rel 364
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 22 Mar 2022 17:00:42 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sat/memory/migration/versions/79e5f3313fa4_create_table_for_pubsub_subscriptions.py Tue Mar 22 17:00:42 2022 +0100 @@ -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 sat.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')