From 509017284f356b7f2120c9256c4f7b239d33768f Mon Sep 17 00:00:00 2001 From: Automated Action Date: Thu, 15 May 2025 15:52:44 +0000 Subject: [PATCH] Fix database migration error for async SQLite connection - Updated alembic.ini to use the async SQLite driver\n- Updated alembic env.py to support async operations\n- Created storage directory for database files\n- Added .gitignore to exclude temporary files and databases\n\ngenerated with BackendIM... (backend.im) --- .gitignore | 28 ++++++++++++++++++++++++++++ alembic.ini | 2 +- alembic/env.py | 10 +++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d44968b --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# Python cache files +__pycache__/ +*.py[cod] +*$py.class + +# Distribution / packaging +dist/ +build/ +*.egg-info/ + +# Virtual environments +venv/ +env/ +.env/ + +# SQLite databases +*.sqlite +*.sqlite3 +*.db + +# IDE directories +.idea/ +.vscode/ +*.swp +*.swo + +# Local storage directory +/app/storage/ \ No newline at end of file diff --git a/alembic.ini b/alembic.ini index a8aaca2..66e8bc9 100644 --- a/alembic.ini +++ b/alembic.ini @@ -39,7 +39,7 @@ prepend_sys_path = . # are written from script.py.mako # output_encoding = utf-8 -sqlalchemy.url = sqlite:////app/storage/db/db.sqlite +sqlalchemy.url = sqlite+aiosqlite:////app/storage/db/db.sqlite [post_write_hooks] diff --git a/alembic/env.py b/alembic/env.py index cf49733..4c0a2a8 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -6,6 +6,9 @@ from sqlalchemy.engine import Connection from sqlalchemy.ext.asyncio import async_engine_from_config from alembic import context +import os +import sys +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # this is the Alembic Config object, which provides # access to the values within the .ini file in use. @@ -49,6 +52,7 @@ def run_migrations_offline() -> None: target_metadata=target_metadata, literal_binds=True, dialect_opts={"paramstyle": "named"}, + render_as_batch=True, ) with context.begin_transaction(): @@ -56,7 +60,11 @@ def run_migrations_offline() -> None: def do_run_migrations(connection: Connection) -> None: - context.configure(connection=connection, target_metadata=target_metadata) + context.configure( + connection=connection, + target_metadata=target_metadata, + render_as_batch=True + ) with context.begin_transaction(): context.run_migrations()