From c730e26024d0463b4155a60cb7de361480d00c83 Mon Sep 17 00:00:00 2001 From: fenos Date: Mon, 17 Nov 2025 11:13:21 +0100 Subject: [PATCH] fix: primary key migration --- .docker/docker-compose-infra.yml | 128 +++++++++--------- .../multitenant/0023-iceberg-catalog-id.sql | 3 +- .../tenant/0048-iceberg-catalog-ids.sql | 9 +- 3 files changed, 73 insertions(+), 67 deletions(-) diff --git a/.docker/docker-compose-infra.yml b/.docker/docker-compose-infra.yml index 49f2c2fef..a5fc77293 100644 --- a/.docker/docker-compose-infra.yml +++ b/.docker/docker-compose-infra.yml @@ -47,70 +47,70 @@ services: PGBOUNCER_IGNORE_STARTUP_PARAMETERS: "extra_float_digits, options" PGBOUNCER_STATS_USERS: postgres - supavisor: - image: supabase/supavisor:1.1.23 - depends_on: - multitenant_db: - condition: service_healthy - tenant_db: - condition: service_healthy - ports: - - 4000:4000 - - 5452:5452 - - 6543:6543 - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:4000/api/health"] - interval: 2s - timeout: 10s - retries: 5 - environment: - PORT: 4000 - PROXY_PORT_SESSION: 5452 - PROXY_PORT_TRANSACTION: 6543 - DATABASE_URL: "ecto://postgres:postgres@multitenant_db:5432/postgres" - CLUSTER_POSTGRES: "true" - SECRET_KEY_BASE: "12345678901234567890121234567890123456789012345678903212345678901234567890123456789032123456789012345678901234567890323456789032" - VAULT_ENC_KEY: "12345678901234567890123456789032" - API_JWT_SECRET: "dev" - METRICS_JWT_SECRET: "dev" - REGION: "local" - ERL_AFLAGS: -proto_dist inet_tcp - command: sh -c "/app/bin/migrate && /app/bin/server" - - supavisor_setup: - image: supabase/supavisor:1.1.23 - command: | - curl -X PUT \ - "http://supavisor:4000/api/tenants/bjhaohmqunupljrqypxz" \ - --header "Accept: application/json" \ - --header "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJvbGUiOiJhbm9uIiwiaWF0IjoxNjQ1MTkyODI0LCJleHAiOjE5NjA3Njg4MjR9.M9jrxyvPLkUxWgOYSf5dNdJ8v_eRrq810ShFRT8N-6M" \ - --header "Content-Type: application/json" \ - --data-raw "{ - \"tenant\": { - \"db_host\": \"tenant_db\", - \"db_port\": 5432, - \"db_database\": \"postgres\", - \"ip_version\": \"auto\", - \"require_user\": true, - \"upstream_ssl\": false, - \"enforce_ssl\": false, - \"default_max_clients\": 200, - \"default_pool_size\": 15, - \"users\": [ - { - \"db_user\": \"postgres\", - \"db_password\": \"postgres\", - \"mode_type\": \"transaction\", - \"pool_size\": 15, - \"max_clients\": 200, - \"pool_checkout_timeout\": 5000 - } - ] - } - }" - depends_on: - supavisor: - condition: service_healthy +# supavisor: +# image: supabase/supavisor:1.1.23 +# depends_on: +# multitenant_db: +# condition: service_healthy +# tenant_db: +# condition: service_healthy +# ports: +# - 4000:4000 +# - 5452:5452 +# - 6543:6543 +# healthcheck: +# test: ["CMD", "curl", "-f", "http://localhost:4000/api/health"] +# interval: 2s +# timeout: 10s +# retries: 5 +# environment: +# PORT: 4000 +# PROXY_PORT_SESSION: 5452 +# PROXY_PORT_TRANSACTION: 6543 +# DATABASE_URL: "ecto://postgres:postgres@multitenant_db:5432/postgres" +# CLUSTER_POSTGRES: "true" +# SECRET_KEY_BASE: "12345678901234567890121234567890123456789012345678903212345678901234567890123456789032123456789012345678901234567890323456789032" +# VAULT_ENC_KEY: "12345678901234567890123456789032" +# API_JWT_SECRET: "dev" +# METRICS_JWT_SECRET: "dev" +# REGION: "local" +# ERL_AFLAGS: -proto_dist inet_tcp +# command: sh -c "/app/bin/migrate && /app/bin/server" +# +# supavisor_setup: +# image: supabase/supavisor:1.1.23 +# command: | +# curl -X PUT \ +# "http://supavisor:4000/api/tenants/bjhaohmqunupljrqypxz" \ +# --header "Accept: application/json" \ +# --header "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJvbGUiOiJhbm9uIiwiaWF0IjoxNjQ1MTkyODI0LCJleHAiOjE5NjA3Njg4MjR9.M9jrxyvPLkUxWgOYSf5dNdJ8v_eRrq810ShFRT8N-6M" \ +# --header "Content-Type: application/json" \ +# --data-raw "{ +# \"tenant\": { +# \"db_host\": \"tenant_db\", +# \"db_port\": 5432, +# \"db_database\": \"postgres\", +# \"ip_version\": \"auto\", +# \"require_user\": true, +# \"upstream_ssl\": false, +# \"enforce_ssl\": false, +# \"default_max_clients\": 200, +# \"default_pool_size\": 15, +# \"users\": [ +# { +# \"db_user\": \"postgres\", +# \"db_password\": \"postgres\", +# \"mode_type\": \"transaction\", +# \"pool_size\": 15, +# \"max_clients\": 200, +# \"pool_checkout_timeout\": 5000 +# } +# ] +# } +# }" +# depends_on: +# supavisor: +# condition: service_healthy minio: image: minio/minio diff --git a/migrations/multitenant/0023-iceberg-catalog-id.sql b/migrations/multitenant/0023-iceberg-catalog-id.sql index e2958047e..804ac23f5 100644 --- a/migrations/multitenant/0023-iceberg-catalog-id.sql +++ b/migrations/multitenant/0023-iceberg-catalog-id.sql @@ -13,7 +13,8 @@ DO $$ ALTER TABLE iceberg_catalogs RENAME COLUMN id TO name; END IF; - ALTER TABLE iceberg_catalogs ADD COLUMN IF NOT EXISTS id uuid NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY; + ALTER TABLE iceberg_catalogs ADD COLUMN IF NOT EXISTS id uuid NOT NULL DEFAULT gen_random_uuid(); + ALTER TABLE iceberg_catalogs ADD PRIMARY KEY (id); ALTER TABLE iceberg_catalogs ADD COLUMN IF NOT EXISTS deleted_at timestamptz NULL; CREATE INDEX IF NOT EXISTS iceberg_catalogs_unique_name_idx diff --git a/migrations/tenant/0048-iceberg-catalog-ids.sql b/migrations/tenant/0048-iceberg-catalog-ids.sql index 0d06db2b7..a6490776d 100644 --- a/migrations/tenant/0048-iceberg-catalog-ids.sql +++ b/migrations/tenant/0048-iceberg-catalog-ids.sql @@ -5,6 +5,8 @@ DO $$ BEGIN IF is_multitenant = false THEN + ALTER TABLE storage.iceberg_namespaces DROP CONSTRAINT IF EXISTS iceberg_namespaces_catalog_id_fkey; + ALTER TABLE storage.iceberg_tables DROP CONSTRAINT IF EXISTS iceberg_tables_catalog_id_fkey; ALTER TABLE storage.iceberg_namespaces DROP CONSTRAINT IF EXISTS iceberg_namespaces_bucket_id_fkey; ALTER TABLE storage.iceberg_tables DROP CONSTRAINT IF EXISTS iceberg_tables_bucket_id_fkey; END IF; @@ -17,13 +19,16 @@ DO $$ AND table_name = 'buckets_analytics' AND constraint_type = 'PRIMARY KEY'; - EXECUTE drop_constraint_sql; + IF drop_constraint_sql IS NOT NULL THEN + EXECUTE drop_constraint_sql; + END IF; IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'buckets_analytics' AND column_name = 'name') THEN ALTER TABLE storage.buckets_analytics RENAME COLUMN id TO name; END IF; - ALTER TABLE storage.buckets_analytics ADD COLUMN IF NOT EXISTS id uuid NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY; + ALTER TABLE storage.buckets_analytics ADD COLUMN IF NOT EXISTS id uuid NOT NULL DEFAULT gen_random_uuid(); + ALTER TABLE storage.buckets_analytics ADD PRIMARY KEY (id); ALTER TABLE storage.buckets_analytics ADD COLUMN IF NOT EXISTS deleted_at timestamptz NULL; CREATE UNIQUE INDEX IF NOT EXISTS buckets_analytics_unique_name_idx