From 47c13d82c1a8946ba1a8cb6ddc8b2b71c22fd5c4 Mon Sep 17 00:00:00 2001 From: Automated Action Date: Fri, 16 May 2025 12:51:50 +0000 Subject: [PATCH] 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 --- alembic/env.py | 18 +++++++++++++++++- alembic/versions/0002_add_user_table.py | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/alembic/env.py b/alembic/env.py index 0a08c69..a24367e 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -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(): diff --git a/alembic/versions/0002_add_user_table.py b/alembic/versions/0002_add_user_table.py index a2a68e1..6b219b7 100644 --- a/alembic/versions/0002_add_user_table.py +++ b/alembic/versions/0002_add_user_table.py @@ -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