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)
This commit is contained in:
parent
8ae38a1131
commit
a3e6425eb2
1 changed files with 466 additions and 36 deletions
|
|
@ -149,14 +149,13 @@ class Storage:
|
|||
@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 @@ class Storage:
|
|||
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():
|
||||
|
|
|
|||
Loading…
Reference in a new issue