Apply ruff linting fixes to Alembic environment

- Fix revision reference in user table migration (0001_create_tasks_table -> 0001)
- Add SQLite batch mode configuration to Alembic env.py
- Enhance logging for SQLite dialect detection
- Ensure consistent configuration for both online and offline migrations
This commit is contained in:
Automated Action 2025-05-16 12:51:50 +00:00
parent efba5e489a
commit 47c13d82c1
2 changed files with 19 additions and 3 deletions

View File

@ -176,11 +176,16 @@ def run_migrations_offline():
url = config.get_main_option("sqlalchemy.url")
logger.info(f"Running offline migrations using URL: {url}")
# Check if this is SQLite URL
is_sqlite = url.startswith("sqlite")
logger.info(f"Is SQLite URL: {is_sqlite}")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
render_as_batch=is_sqlite, # Enable batch mode for SQLite
)
with context.begin_transaction():
@ -229,8 +234,19 @@ def run_migrations_online():
# Connect and run migrations
with connectable.connect() as connection:
logger.info("Connection successful")
# Check if this is SQLite and enable batch mode if needed
is_sqlite = connection.dialect.name == "sqlite"
logger.info(f"Detected dialect: {connection.dialect.name}")
if is_sqlite:
logger.info(
"SQLite detected, enabling batch mode for migrations"
)
context.configure(
connection=connection, target_metadata=target_metadata
connection=connection,
target_metadata=target_metadata,
render_as_batch=is_sqlite, # This is essential for SQLite migrations
)
with context.begin_transaction():

View File

@ -1,7 +1,7 @@
"""Add user table and task relation
Revision ID: 0002
Revises: 0001_create_tasks_table
Revises: 0001
Create Date: 2023-10-31
"""
@ -12,7 +12,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic
revision = "0002"
down_revision = "0001_create_tasks_table"
down_revision = "0001"
branch_labels = None
depends_on = None