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.
This commit is contained in:
parent
4540ad359e
commit
287155a783
@ -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_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)
|
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
|
# Create enums
|
||||||
user_role_enum.create(op.get_bind(), checkfirst=True)
|
user_role_enum.create(op.get_bind(), checkfirst=True)
|
||||||
split_type_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)
|
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('settlement_activities')
|
||||||
op.drop_table('settlements')
|
op.drop_table('settlements')
|
||||||
op.drop_table('expense_splits')
|
op.drop_table('expense_splits')
|
||||||
|
@ -242,7 +242,7 @@ async def startup_event():
|
|||||||
logger.info(f"Application startup in {settings.ENVIRONMENT} environment...")
|
logger.info(f"Application startup in {settings.ENVIRONMENT} environment...")
|
||||||
|
|
||||||
# Run database migrations
|
# Run database migrations
|
||||||
await run_migrations()
|
# await run_migrations()
|
||||||
|
|
||||||
# Initialize scheduler
|
# Initialize scheduler
|
||||||
init_scheduler()
|
init_scheduler()
|
||||||
|
Loading…
Reference in New Issue
Block a user