Fix: Migration 0094 prueft Spalten-Existenz vor GIN-Index-Erstellung

This commit is contained in:
Agent Zero
2026-08-03 16:14:43 +02:00
parent d5daeb8dfd
commit fe6a4fdd54
@@ -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)