diff --git a/alembic/versions/0094_fix_gin_indexes_and_plugins_dedup.py b/alembic/versions/0094_fix_gin_indexes_and_plugins_dedup.py index bab1cc8..3afc2a5 100644 --- a/alembic/versions/0094_fix_gin_indexes_and_plugins_dedup.py +++ b/alembic/versions/0094_fix_gin_indexes_and_plugins_dedup.py @@ -34,11 +34,18 @@ GIN_INDEXES = [ def upgrade() -> None: # Fix GIN indexes: drop and recreate with USING GIN (idempotent) + # Only create index if the column exists (avoids failure on fresh DB) for table, index_name, column in GIN_INDEXES: op.execute(f"DROP INDEX IF EXISTS {index_name}") + # Check if column exists before creating index op.execute( + "DO $do$ BEGIN " + "IF EXISTS (SELECT 1 FROM information_schema.columns " + f"WHERE table_name = '{table}' AND column_name = '{column}') THEN " f"CREATE INDEX IF NOT EXISTS {index_name} " - f"ON {table} USING gin ({column})" + f"ON {table} USING gin ({column}); " + "END IF; " + "END $do$;" ) # Remove redundant plugins.name index (plugins_name_key already enforces uniqueness)