fix(data): make postgres snapshot migrations idempotent

This commit is contained in:
elky
2026-09-05 03:44:10 +08:00
parent af712ebdbf
commit 7ed48e7b58
2 changed files with 8 additions and 1 deletions
@@ -30,5 +30,9 @@ BEGIN
ADD CONSTRAINT ldap_configs_singleton_key_key UNIQUE (singleton_key);
EXCEPTION
WHEN duplicate_object THEN NULL;
-- The empty-database snapshot already materializes this constraint. PostgreSQL
-- reports the existing constraint's backing relation as duplicate_table (42P07)
-- rather than duplicate_object, so treat that known idempotent case the same way.
WHEN duplicate_table THEN NULL;
END
$migration$;
@@ -1,5 +1,8 @@
ALTER TABLE public.routing_groups
ADD COLUMN sort_order bigint NOT NULL DEFAULT 0;
-- The empty-database snapshot may already contain the current logical
-- schema. Keep the incremental migration safe for both snapshot and
-- legacy databases.
ADD COLUMN IF NOT EXISTS sort_order bigint NOT NULL DEFAULT 0;
CREATE INDEX IF NOT EXISTS routing_groups_enabled_sort_idx
ON public.routing_groups (enabled DESC, sort_order, name, id);