From 1d39bc03d85621eafdf10a572e1b39da5ae0974a Mon Sep 17 00:00:00 2001 From: senior Date: Thu, 6 Aug 2026 05:10:47 +0000 Subject: [PATCH] Update SQL/postgres.initial.sql makes the script safe to re-run against an already-migrated database --- SQL/postgres.initial.sql | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/SQL/postgres.initial.sql b/SQL/postgres.initial.sql index 2363c6c..9ccfab3 100644 --- a/SQL/postgres.initial.sql +++ b/SQL/postgres.initial.sql @@ -1,4 +1,13 @@ -CREATE TABLE ident_switch +-- Patched version of SQL/postgres.initial.sql for gecka/ident-switch. +-- Commit this into your Gitea fork at the same path, replacing the +-- upstream file. Only two changes from upstream: +-- 1. CREATE TABLE / CREATE INDEX -> IF NOT EXISTS +-- 2. INSERT INTO system -> upsert via ON CONFLICT +-- This makes the script safe to re-run against an already-migrated +-- database, which happens on every container restart unless +-- /var/www/html is persisted (composer re-installs "fresh" each time). + +CREATE TABLE IF NOT EXISTS ident_switch ( id serial @@ -82,8 +91,9 @@ CREATE TABLE ident_switch UNIQUE (user_id, label) ); -CREATE INDEX IX_ident_switch_user_id ON ident_switch(user_id); -CREATE INDEX IX_ident_switch_iid ON ident_switch(iid); -CREATE INDEX IX_ident_switch_parent_id ON ident_switch(parent_id); +CREATE INDEX IF NOT EXISTS IX_ident_switch_user_id ON ident_switch(user_id); +CREATE INDEX IF NOT EXISTS IX_ident_switch_iid ON ident_switch(iid); +CREATE INDEX IF NOT EXISTS IX_ident_switch_parent_id ON ident_switch(parent_id); -INSERT INTO system (name, value) VALUES ('ident_switch-version', '2026021000'); +INSERT INTO system (name, value) VALUES ('ident_switch-version', '2026021000') +ON CONFLICT (name) DO UPDATE SET value = EXCLUDED.value; \ No newline at end of file