|
|
@@ -0,0 +1,25 @@
|
|
|
+from pyplanner.database import SQLABase
|
|
|
+from sqlalchemy import Column, Integer, String, event
|
|
|
+import uuid
|
|
|
+
|
|
|
+
|
|
|
+class UniversalIndex(SQLABase):
|
|
|
+ __tablename__ = 'universal_index'
|
|
|
+
|
|
|
+ id = Column(Integer, primary_key=True)
|
|
|
+ table = Column(String)
|
|
|
+ object_id = Column(Integer)
|
|
|
+ uuid = Column(String)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def listen(database):
|
|
|
+ def do_something(session, flush_context):
|
|
|
+ "listen for the 'after_flush' event"
|
|
|
+ print(session.new, session.dirty, session.deleted)
|
|
|
+
|
|
|
+ uis = [UniversalIndex(
|
|
|
+ table=obj.__class__.__name__, object_id=obj.id, uuid=uuid.uuid4().hex
|
|
|
+ ) for obj in session.new if not isinstance(obj, UniversalIndex)]
|
|
|
+ session.add_all(uis)
|
|
|
+
|
|
|
+ event.listen(database.session_factory, 'after_flush', do_something)
|