From b76e5f5b0f8d7f68e917733d7a204c86a11d31da Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Sat, 25 Jul 2026 10:37:21 +0100 Subject: [PATCH] fix: use batch_alter_table for SQLite-compatible DROP COLUMN in downgrade Downgrade in migration 6c0e5f8a9b1d was using individual op.drop_column() calls outside batch_alter_table, which fails on SQLite < 3.35.0 that lacks native DROP COLUMN support. Closes #5873 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus Signed-off-by: Jonathan Springer --- .../6c0e5f8a9b1d_add_gateway_lifecycle_fields.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mcpgateway/alembic/versions/6c0e5f8a9b1d_add_gateway_lifecycle_fields.py b/mcpgateway/alembic/versions/6c0e5f8a9b1d_add_gateway_lifecycle_fields.py index de8172ee92..24c91b9636 100644 --- a/mcpgateway/alembic/versions/6c0e5f8a9b1d_add_gateway_lifecycle_fields.py +++ b/mcpgateway/alembic/versions/6c0e5f8a9b1d_add_gateway_lifecycle_fields.py @@ -117,8 +117,12 @@ def downgrade() -> None: if _index_exists(inspector, GATEWAY_TABLE, CLAIM_INDEX): op.drop_index(CLAIM_INDEX, table_name=GATEWAY_TABLE) + # Use batch_alter_table for SQLite compatibility (SQLite < 3.35.0 doesn't support DROP COLUMN) inspector = sa.inspect(bind) columns = _column_names(inspector, GATEWAY_TABLE) - for column_name in reversed(LIFECYCLE_COLUMNS): - if column_name in columns: - op.drop_column(GATEWAY_TABLE, column_name) + columns_to_drop = [col for col in reversed(LIFECYCLE_COLUMNS) if col in columns] + + if columns_to_drop: + with op.batch_alter_table(GATEWAY_TABLE, schema=None) as batch_op: + for column_name in columns_to_drop: + batch_op.drop_column(column_name)