diff libervia/backend/memory/sqla_mapping.py @ 4152:23d21daed216

core (memory/sqla_mapping): add a `version_id` column to detect race conditions.
author Goffi <goffi@goffi.org>
date Wed, 22 Nov 2023 14:52:00 +0100
parents 02f0adc745c6
children 2074b2bbe616
line wrap: on
line diff
--- a/libervia/backend/memory/sqla_mapping.py	Wed Nov 22 14:50:35 2023 +0100
+++ b/libervia/backend/memory/sqla_mapping.py	Wed Nov 22 14:52:00 2023 +0100
@@ -35,6 +35,7 @@
     Integer,
     JSON,
     MetaData,
+    text,
     Text,
     UniqueConstraint,
     event,
@@ -267,6 +268,9 @@
     )
 
     uid = Column(Text, primary_key=True)
+    # FIXME: version_id is only needed for changes in `extra` column. It would maybe be
+    # better to use separate table for `extra` data instead.
+    version_id = Column(Integer, nullable=False, server_default=text("1"))
     origin_id = Column(Text)
     stanza_id = Column(Text)
     update_uid = Column(Text)
@@ -300,6 +304,7 @@
     thread = relationship(
         "Thread", uselist=False, back_populates="history", passive_deletes=True
     )
+    __mapper_args__ = {"version_id_col": version_id}
 
     def __init__(self, *args, **kwargs):
         source_jid = kwargs.pop("source_jid", None)