mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 08:09:18 +02:00
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:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user