From 287155a7830dfa5e47f8d11b950a6f545ddf77a7 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 1 Jun 2025 17:16:41 +0000 Subject: [PATCH] Fix(alembic): Resolve TypeError in migration script and remove redundant migration call This commit addresses two issues: 1. A `TypeError` during Alembic migrations (`upgrade() takes 0 positional arguments but 1 was given`). This was caused by the `upgrade` and `downgrade` functions in the initial migration script not accepting any arguments, while the custom migration runner in `migrations.py` was passing a context argument. - Modified `be/alembic/versions/0001_initial_schema.py` to ensure `upgrade` and `downgrade` functions accept a `context` argument. 2. Redundant execution of migrations. Migrations were being triggered both by the `entrypoint.sh` script and within the FastAPI application's startup event in `app/main.py`. - Commented out the `await run_migrations()` call in `app/main.py` to ensure migrations are only handled by the `entrypoint.sh` script. These changes should ensure that database migrations run correctly and only once when the backend container starts. --- be/alembic/versions/0001_initial_schema.py | 4 ++-- be/app/main.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/be/alembic/versions/0001_initial_schema.py b/be/alembic/versions/0001_initial_schema.py index e428ac0..6227807 100644 --- a/be/alembic/versions/0001_initial_schema.py +++ b/be/alembic/versions/0001_initial_schema.py @@ -25,7 +25,7 @@ recurrence_type_enum = postgresql.ENUM('DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY', n chore_frequency_enum = postgresql.ENUM('one_time', 'daily', 'weekly', 'monthly', 'custom', name='chorefrequencyenum', create_type=False) chore_type_enum = postgresql.ENUM('personal', 'group', name='choretypeenum', create_type=False) -def upgrade() -> None: +def upgrade(context=None) -> None: # Add context=None for compatibility, real arg passed by Alembic # Create enums user_role_enum.create(op.get_bind(), checkfirst=True) split_type_enum.create(op.get_bind(), checkfirst=True) @@ -280,7 +280,7 @@ def upgrade() -> None: op.create_index(op.f('ix_settlement_activities_paid_by_user_id'), 'settlement_activities', ['paid_by_user_id'], unique=False) -def downgrade() -> None: +def downgrade(context=None) -> None: # Add context=None for compatibility, real arg passed by Alembic op.drop_table('settlement_activities') op.drop_table('settlements') op.drop_table('expense_splits') diff --git a/be/app/main.py b/be/app/main.py index e56f0a3..eca992d 100644 --- a/be/app/main.py +++ b/be/app/main.py @@ -242,7 +242,7 @@ async def startup_event(): logger.info(f"Application startup in {settings.ENVIRONMENT} environment...") # Run database migrations - await run_migrations() + # await run_migrations() # Initialize scheduler init_scheduler()