feat: use Alembic to initialize the database

This completely removes the previous DB patching mechanism.
When this is first run for an existing installation of Unwind, depending
on its version it might lead to problems because the database's schema
won't match the code.
To avoid that issue, when upgrading Unwind to this version make sure to
STOP the old application, install this new version but DON'T start it,
instead use `alembic upgrade head` to run the outstanding patches, and
only then start the application.
This commit is contained in:
ducklet 2024-05-19 02:25:36 +02:00
parent 5e4e70c9dc
commit 1ea09c1a45
20 changed files with 72 additions and 560 deletions

View file

@ -91,13 +91,18 @@ async def run_async_migrations() -> None:
await connectable.dispose()
def run_migrations_online_async() -> None:
def run_migrations_online() -> None:
"""Run migrations in 'online' mode."""
asyncio.run(run_async_migrations())
# Support having a (sync) connection passed in from another script.
if (conn := config.attributes.get("connection")) and isinstance(
conn, sa.Connection
):
do_run_migrations(conn)
else:
asyncio.run(run_async_migrations())
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online_async()
run_migrations_online()