mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-11-09 19:20:09 +01: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:
1 parent
973444bdbb
commit
28ef35dce5
5 files changed
+66
-42
No files matched your search
@@ -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