From be6590c33c3aaa34a9e6c6f42706dda98ca3db42 Mon Sep 17 00:00:00 2001 From: Silvan <27845747+adlerhurst@users.noreply.github.com> Date: Wed, 4 Feb 2026 11:55:46 +0100 Subject: [PATCH] fix(setup): ensure step 69 runs without issues (#11503) ## Which problems are solved https://github.com/zitadel/zitadel/pull/11484 introduced a regression that causes the setup process to fail on existing Zitadel deployments. This prevents users from upgrading to recent versions without encountering setup failures. ## How the problems are solved Setup step 69 has been corrected to properly handle existing deployment configurations and prevent setup failures during initialization and upgrades. ## Additional Context introduced by [7a41fe968b9fcb69b378336740b74e5448c1ff81](https://github.com/zitadel/zitadel/commit/7a41fe968b9fcb69b378336740b74e5448c1ff81) ### Testing - [x] Verified setup succeeds on fresh deployments - [x] Verified setup succeeds on existing deployments - [x] Verified migration from PostgreSQL 17 to 18 after running setup of this version --- cmd/setup/69.sql | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/setup/69.sql b/cmd/setup/69.sql index d8d8d3ec3..1cbf9b2b4 100644 --- a/cmd/setup/69.sql +++ b/cmd/setup/69.sql @@ -1,13 +1,31 @@ DO $do$ BEGIN + -- Convert objects to logged first (if unlogged) IF EXISTS (SELECT 1 FROM pg_class WHERE oid = 'cache.objects'::REGCLASS AND relpersistence = 'u') THEN ALTER TABLE IF EXISTS cache.objects SET LOGGED; END IF; - IF EXISTS (SELECT 1 FROM pg_class WHERE oid = 'cache.string_keys'::REGCLASS AND relpersistence = 'u') THEN + + -- Convert string_keys to logged (if unlogged) + -- Drop the FK constraint first to allow converting cache.string_keys (and avoid loggedness-change restrictions involving the FK) + IF EXISTS (SELECT 1 FROM pg_class WHERE oid = to_regclass('cache.objects') AND relpersistence = 'u') THEN + ALTER TABLE IF EXISTS cache.objects + SET LOGGED; + END IF; + + -- Convert string_keys to logged (if unlogged) + -- Drop the FK constraint first to avoid conflict with parent table conversion + IF EXISTS (SELECT 1 FROM pg_class WHERE oid = to_regclass('cache.string_keys') AND relpersistence = 'u') THEN + ALTER TABLE IF EXISTS cache.string_keys + DROP CONSTRAINT IF EXISTS fk_object; ALTER TABLE IF EXISTS cache.string_keys SET LOGGED; + ALTER TABLE IF EXISTS cache.string_keys + ADD CONSTRAINT fk_object + FOREIGN KEY(cache_name, object_id) + REFERENCES cache.objects(cache_name, id) + ON DELETE CASCADE; END IF; CREATE UNLOGGED TABLE IF NOT EXISTS cache.objects_default