diff sat/memory/sqla.py @ 3583:16ade4ad63f3 sqlalchemy

core (memory/sqla_mapping): fix some technical debt: a first Alembic revision file is joined to migrate existing databases to new mapping. This patch: - set `nullable=False` in various places - drop legacy `message_types` table, and use `Enum` instead - use naming convention, and get rid of anonymous constraint (this is the main reason why the revision file is so long)
author Goffi <goffi@goffi.org>
date Sun, 27 Jun 2021 00:15:40 +0200
parents 71516731d0aa
children 7510648e8e3a
line wrap: on
line diff
--- a/sat/memory/sqla.py	Fri Jun 25 17:55:23 2021 +0200
+++ b/sat/memory/sqla.py	Sun Jun 27 00:15:40 2021 +0200
@@ -149,14 +149,13 @@
     @aio
     async def initialise(self) -> None:
         log.info(_("Connecting database"))
+
         db_config = sqla_config.getDbConfig()
         engine = create_async_engine(
             db_config["url"],
             future=True
         )
-        self.session = sessionmaker(
-            engine, expire_on_commit=False, class_=AsyncSession
-        )
+
         new_base = not db_config["path"].exists()
         if new_base:
             log.info(_("The database is new, creating the tables"))
@@ -164,6 +163,10 @@
         else:
             await self.checkAndUpdateDB(engine, db_config)
 
+        self.session = sessionmaker(
+            engine, expire_on_commit=False, class_=AsyncSession
+        )
+
         async with self.session() as session:
             result = await session.execute(select(Profile))
             for p in result.scalars():