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)
This commit is contained in:
Automated Action 2025-05-15 15:52:44 +00:00
parent 629ba0ee1c
commit 509017284f
3 changed files with 38 additions and 2 deletions

28
.gitignore vendored Normal file
View File

@ -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/

View File

@ -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]

View File

@ -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()