From 6b37715f34972f1c14af1d368c91e3c99115bf4e Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Mon, 15 Jun 2026 19:11:22 -0700 Subject: [PATCH] fix(db): make 0218_create_event_routes idempotent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CREATE TABLE IF NOT EXISTS silently skips if the table already exists, but the subsequent ALTER TABLE ADD CONSTRAINT had no guard — causing: ERROR: multiple primary keys for table "event_routes" are not allowed on any DB where the table was already created. Fix by inlining the PRIMARY KEY constraint in the CREATE TABLE definition so the whole statement is skipped under IF NOT EXISTS. This has been blocking bridge auto-upgrades since the 0218 migration was first applied to production (June 9). All migrate-* jobs in the api namespace have been failing, leaving 60+ auto-upgrader CronJob pods stuck in a 30-min kubectl-wait loop. --- ddl/migrations/0218_create_event_routes.sql | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ddl/migrations/0218_create_event_routes.sql b/ddl/migrations/0218_create_event_routes.sql index 3fbb9e3b..a0c1b521 100644 --- a/ddl/migrations/0218_create_event_routes.sql +++ b/ddl/migrations/0218_create_event_routes.sql @@ -4,7 +4,6 @@ -- indexer when an event is created, owner_id points to the event's host user, -- and is_current flags the canonical row so a LEFT JOIN ON is_current = true -- always lands on at most one row per event. - CREATE TABLE IF NOT EXISTS public.event_routes ( slug character varying NOT NULL, owner_id integer NOT NULL, @@ -12,11 +11,8 @@ CREATE TABLE IF NOT EXISTS public.event_routes ( is_current boolean NOT NULL, blockhash character varying NOT NULL, blocknumber integer NOT NULL, - txhash character varying NOT NULL + txhash character varying NOT NULL, + CONSTRAINT event_routes_pkey PRIMARY KEY (owner_id, slug) ); - -ALTER TABLE ONLY public.event_routes - ADD CONSTRAINT event_routes_pkey PRIMARY KEY (owner_id, slug); - CREATE INDEX IF NOT EXISTS event_routes_event_id_idx ON public.event_routes USING btree (event_id);