Fix: Migration 0094 prueft Spalten-Existenz vor GIN-Index-Erstellung
This commit is contained in:
@@ -34,11 +34,18 @@ GIN_INDEXES = [
|
|||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
# Fix GIN indexes: drop and recreate with USING GIN (idempotent)
|
# 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:
|
for table, index_name, column in GIN_INDEXES:
|
||||||
op.execute(f"DROP INDEX IF EXISTS {index_name}")
|
op.execute(f"DROP INDEX IF EXISTS {index_name}")
|
||||||
|
# Check if column exists before creating index
|
||||||
op.execute(
|
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"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)
|
# Remove redundant plugins.name index (plugins_name_key already enforces uniqueness)
|
||||||
|
|||||||
Reference in New Issue
Block a user