memory (sqla): add "parent_node_id" and "linked_mode_id" to PubsubNode:
This is to prepare for the implementation of XEP-0496 and XEP-0499. rel 463
This commit is contained in:
parent
f5a4b4b599
commit
e593f32f09
2 changed files with 59 additions and 0 deletions
|
|
@ -0,0 +1,32 @@
|
|||
"""add "parent_node_id" and "linked_mode_id" to PubsubNode
|
||||
|
||||
Revision ID: ece2a6d7e4bb
|
||||
Revises: 8db042adb973
|
||||
Create Date: 2025-08-16 16:47:48.242973
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'ece2a6d7e4bb'
|
||||
down_revision = '8db042adb973'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
with op.batch_alter_table('pubsub_nodes', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('linked_node_id', sa.Integer(), nullable=True))
|
||||
batch_op.add_column(sa.Column('parent_node_id', sa.Integer(), nullable=True))
|
||||
batch_op.create_foreign_key(batch_op.f('fk_pubsub_nodes_parent_node_id_pubsub_nodes'), 'pubsub_nodes', ['parent_node_id'], ['id'], ondelete='CASCADE')
|
||||
batch_op.create_foreign_key(batch_op.f('fk_pubsub_nodes_linked_node_id_pubsub_nodes'), 'pubsub_nodes', ['linked_node_id'], ['id'], ondelete='CASCADE')
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table('pubsub_nodes', schema=None) as batch_op:
|
||||
batch_op.drop_constraint(batch_op.f('fk_pubsub_nodes_linked_node_id_pubsub_nodes'), type_='foreignkey')
|
||||
batch_op.drop_constraint(batch_op.f('fk_pubsub_nodes_parent_node_id_pubsub_nodes'), type_='foreignkey')
|
||||
batch_op.drop_column('parent_node_id')
|
||||
batch_op.drop_column('linked_node_id')
|
||||
|
|
@ -653,10 +653,37 @@ class PubsubNode(Base):
|
|||
subtype = Column(Text, nullable=True)
|
||||
extra = Column(JSON)
|
||||
|
||||
linked_node_id = Column(Integer, ForeignKey("pubsub_nodes.id", ondelete="CASCADE"), nullable=True)
|
||||
parent_node_id = Column(Integer, ForeignKey("pubsub_nodes.id", ondelete="CASCADE"), nullable=True)
|
||||
|
||||
items = relationship("PubsubItem", back_populates="node", passive_deletes=True)
|
||||
affiliations = relationship("PubsubAffiliation", back_populates="node", passive_deletes=True)
|
||||
subscriptions = relationship("PubsubSub", back_populates="node", passive_deletes=True)
|
||||
|
||||
linked_node = relationship(
|
||||
"PubsubNode",
|
||||
remote_side=[id],
|
||||
foreign_keys=[linked_node_id],
|
||||
back_populates="linking_nodes"
|
||||
)
|
||||
linking_nodes = relationship(
|
||||
"PubsubNode",
|
||||
foreign_keys=[linked_node_id],
|
||||
back_populates="linked_node",
|
||||
)
|
||||
|
||||
parent_node = relationship(
|
||||
"PubsubNode",
|
||||
remote_side=[id],
|
||||
foreign_keys=[parent_node_id],
|
||||
back_populates="child_nodes"
|
||||
)
|
||||
child_nodes = relationship(
|
||||
"PubsubNode",
|
||||
foreign_keys=[parent_node_id],
|
||||
back_populates="parent_node",
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"Pubsub node {self.name!r} at {self.service}"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue