comparison sat/memory/sqla_mapping.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 162866ca4be7
children 24c1c06c865b
comparison
equal deleted inserted replaced
3743:54c249ec35ce 3744:658ddbabaf36
56 COMPLETED = 2 56 COMPLETED = 2
57 #: something wrong happened during synchronisation, won't sync 57 #: something wrong happened during synchronisation, won't sync
58 ERROR = 3 58 ERROR = 3
59 #: synchronisation won't be done even if a syncing analyser matches 59 #: synchronisation won't be done even if a syncing analyser matches
60 NO_SYNC = 4 60 NO_SYNC = 4
61
62
63 class SubscriptionState(enum.Enum):
64 SUBSCRIBED = 1
65 PENDING = 2
61 66
62 67
63 class LegacyPickle(TypeDecorator): 68 class LegacyPickle(TypeDecorator):
64 """Handle troubles with data pickled by former version of SàT 69 """Handle troubles with data pickled by former version of SàT
65 70
508 Text, nullable=True 513 Text, nullable=True
509 ) 514 )
510 extra = Column(JSON) 515 extra = Column(JSON)
511 516
512 items = relationship("PubsubItem", back_populates="node", passive_deletes=True) 517 items = relationship("PubsubItem", back_populates="node", passive_deletes=True)
518 subscriptions = relationship("PubsubSub", back_populates="node", passive_deletes=True)
513 519
514 def __str__(self): 520 def __str__(self):
515 return f"Pubsub node {self.name!r} at {self.service}" 521 return f"Pubsub node {self.name!r} at {self.service}"
522
523
524 class PubsubSub(Base):
525 """Subscriptions to pubsub nodes
526
527 Used by components managing a pubsub service
528 """
529 __tablename__ = "pubsub_subs"
530 __table_args__ = (
531 UniqueConstraint("node_id", "subscriber"),
532 )
533
534 id = Column(Integer, primary_key=True)
535 node_id = Column(ForeignKey("pubsub_nodes.id", ondelete="CASCADE"), nullable=False)
536 subscriber = Column(JID)
537 state = Column(
538 Enum(
539 SubscriptionState,
540 name="state",
541 create_constraint=True,
542 ),
543 nullable=True
544 )
545
546 node = relationship("PubsubNode", back_populates="subscriptions")
516 547
517 548
518 class PubsubItem(Base): 549 class PubsubItem(Base):
519 __tablename__ = "pubsub_items" 550 __tablename__ = "pubsub_items"
520 __table_args__ = ( 551 __table_args__ = (