fix: make schema.sql fully idempotent — add IF NOT EXISTS to all CREATE INDEX, CREATE TRIGGER, and CREATE VIEW statements

This commit is contained in:
Pontoporeia
2026-05-11 10:31:19 +02:00
parent 973444bdbb
commit 28ef35dce5
5 changed files with 66 additions and 42 deletions

View File

@@ -131,6 +131,11 @@ for (sql,) in indexes:
clean = sql.strip()
if not clean.endswith(';'):
clean += ';'
# Make idempotent — SQLite doesn't store IF NOT EXISTS in sqlite_master.sql
if clean.upper().startswith('CREATE INDEX ') and 'IF NOT EXISTS' not in clean.upper():
clean = clean.replace('CREATE INDEX ', 'CREATE INDEX IF NOT EXISTS ', 1)
if clean.upper().startswith('CREATE UNIQUE INDEX ') and 'IF NOT EXISTS' not in clean.upper():
clean = clean.replace('CREATE UNIQUE INDEX ', 'CREATE UNIQUE INDEX IF NOT EXISTS ', 1)
print(clean)
print()
@@ -143,6 +148,9 @@ for (sql,) in views:
clean = sql.strip()
if not clean.endswith(';'):
clean += ';'
# Make idempotent — SQLite doesn't store IF NOT EXISTS in sqlite_master.sql
if clean.upper().startswith('CREATE VIEW ') and 'IF NOT EXISTS' not in clean.upper():
clean = clean.replace('CREATE VIEW ', 'CREATE VIEW IF NOT EXISTS ', 1)
print(clean)
print()
@@ -155,6 +163,9 @@ for (sql,) in triggers:
clean = sql.strip()
if not clean.endswith(';'):
clean += ';'
# Make idempotent — SQLite doesn't store IF NOT EXISTS in sqlite_master.sql
if clean.upper().startswith('CREATE TRIGGER ') and 'IF NOT EXISTS' not in clean.upper():
clean = clean.replace('CREATE TRIGGER ', 'CREATE TRIGGER IF NOT EXISTS ', 1)
print(clean)
print()