Skip to content

Commit 4f66e94

Browse files
authored
fix: primary key migration (#800)
1 parent 90250f2 commit 4f66e94

File tree

3 files changed

+73
-67
lines changed

3 files changed

+73
-67
lines changed

.docker/docker-compose-infra.yml

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -47,70 +47,70 @@ services:
4747
PGBOUNCER_IGNORE_STARTUP_PARAMETERS: "extra_float_digits, options"
4848
PGBOUNCER_STATS_USERS: postgres
4949

50-
supavisor:
51-
image: supabase/supavisor:1.1.23
52-
depends_on:
53-
multitenant_db:
54-
condition: service_healthy
55-
tenant_db:
56-
condition: service_healthy
57-
ports:
58-
- 4000:4000
59-
- 5452:5452
60-
- 6543:6543
61-
healthcheck:
62-
test: ["CMD", "curl", "-f", "http://localhost:4000/api/health"]
63-
interval: 2s
64-
timeout: 10s
65-
retries: 5
66-
environment:
67-
PORT: 4000
68-
PROXY_PORT_SESSION: 5452
69-
PROXY_PORT_TRANSACTION: 6543
70-
DATABASE_URL: "ecto://postgres:postgres@multitenant_db:5432/postgres"
71-
CLUSTER_POSTGRES: "true"
72-
SECRET_KEY_BASE: "12345678901234567890121234567890123456789012345678903212345678901234567890123456789032123456789012345678901234567890323456789032"
73-
VAULT_ENC_KEY: "12345678901234567890123456789032"
74-
API_JWT_SECRET: "dev"
75-
METRICS_JWT_SECRET: "dev"
76-
REGION: "local"
77-
ERL_AFLAGS: -proto_dist inet_tcp
78-
command: sh -c "/app/bin/migrate && /app/bin/server"
79-
80-
supavisor_setup:
81-
image: supabase/supavisor:1.1.23
82-
command: |
83-
curl -X PUT \
84-
"http://supavisor:4000/api/tenants/bjhaohmqunupljrqypxz" \
85-
--header "Accept: application/json" \
86-
--header "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJvbGUiOiJhbm9uIiwiaWF0IjoxNjQ1MTkyODI0LCJleHAiOjE5NjA3Njg4MjR9.M9jrxyvPLkUxWgOYSf5dNdJ8v_eRrq810ShFRT8N-6M" \
87-
--header "Content-Type: application/json" \
88-
--data-raw "{
89-
\"tenant\": {
90-
\"db_host\": \"tenant_db\",
91-
\"db_port\": 5432,
92-
\"db_database\": \"postgres\",
93-
\"ip_version\": \"auto\",
94-
\"require_user\": true,
95-
\"upstream_ssl\": false,
96-
\"enforce_ssl\": false,
97-
\"default_max_clients\": 200,
98-
\"default_pool_size\": 15,
99-
\"users\": [
100-
{
101-
\"db_user\": \"postgres\",
102-
\"db_password\": \"postgres\",
103-
\"mode_type\": \"transaction\",
104-
\"pool_size\": 15,
105-
\"max_clients\": 200,
106-
\"pool_checkout_timeout\": 5000
107-
}
108-
]
109-
}
110-
}"
111-
depends_on:
112-
supavisor:
113-
condition: service_healthy
50+
# supavisor:
51+
# image: supabase/supavisor:1.1.23
52+
# depends_on:
53+
# multitenant_db:
54+
# condition: service_healthy
55+
# tenant_db:
56+
# condition: service_healthy
57+
# ports:
58+
# - 4000:4000
59+
# - 5452:5452
60+
# - 6543:6543
61+
# healthcheck:
62+
# test: ["CMD", "curl", "-f", "http://localhost:4000/api/health"]
63+
# interval: 2s
64+
# timeout: 10s
65+
# retries: 5
66+
# environment:
67+
# PORT: 4000
68+
# PROXY_PORT_SESSION: 5452
69+
# PROXY_PORT_TRANSACTION: 6543
70+
# DATABASE_URL: "ecto://postgres:postgres@multitenant_db:5432/postgres"
71+
# CLUSTER_POSTGRES: "true"
72+
# SECRET_KEY_BASE: "12345678901234567890121234567890123456789012345678903212345678901234567890123456789032123456789012345678901234567890323456789032"
73+
# VAULT_ENC_KEY: "12345678901234567890123456789032"
74+
# API_JWT_SECRET: "dev"
75+
# METRICS_JWT_SECRET: "dev"
76+
# REGION: "local"
77+
# ERL_AFLAGS: -proto_dist inet_tcp
78+
# command: sh -c "/app/bin/migrate && /app/bin/server"
79+
#
80+
# supavisor_setup:
81+
# image: supabase/supavisor:1.1.23
82+
# command: |
83+
# curl -X PUT \
84+
# "http://supavisor:4000/api/tenants/bjhaohmqunupljrqypxz" \
85+
# --header "Accept: application/json" \
86+
# --header "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJvbGUiOiJhbm9uIiwiaWF0IjoxNjQ1MTkyODI0LCJleHAiOjE5NjA3Njg4MjR9.M9jrxyvPLkUxWgOYSf5dNdJ8v_eRrq810ShFRT8N-6M" \
87+
# --header "Content-Type: application/json" \
88+
# --data-raw "{
89+
# \"tenant\": {
90+
# \"db_host\": \"tenant_db\",
91+
# \"db_port\": 5432,
92+
# \"db_database\": \"postgres\",
93+
# \"ip_version\": \"auto\",
94+
# \"require_user\": true,
95+
# \"upstream_ssl\": false,
96+
# \"enforce_ssl\": false,
97+
# \"default_max_clients\": 200,
98+
# \"default_pool_size\": 15,
99+
# \"users\": [
100+
# {
101+
# \"db_user\": \"postgres\",
102+
# \"db_password\": \"postgres\",
103+
# \"mode_type\": \"transaction\",
104+
# \"pool_size\": 15,
105+
# \"max_clients\": 200,
106+
# \"pool_checkout_timeout\": 5000
107+
# }
108+
# ]
109+
# }
110+
# }"
111+
# depends_on:
112+
# supavisor:
113+
# condition: service_healthy
114114

115115
minio:
116116
image: minio/minio

migrations/multitenant/0023-iceberg-catalog-id.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ DO $$
1313
ALTER TABLE iceberg_catalogs RENAME COLUMN id TO name;
1414
END IF;
1515

16-
ALTER TABLE iceberg_catalogs ADD COLUMN IF NOT EXISTS id uuid NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY;
16+
ALTER TABLE iceberg_catalogs ADD COLUMN IF NOT EXISTS id uuid NOT NULL DEFAULT gen_random_uuid();
17+
ALTER TABLE iceberg_catalogs ADD PRIMARY KEY (id);
1718
ALTER TABLE iceberg_catalogs ADD COLUMN IF NOT EXISTS deleted_at timestamptz NULL;
1819

1920
CREATE INDEX IF NOT EXISTS iceberg_catalogs_unique_name_idx

migrations/tenant/0048-iceberg-catalog-ids.sql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ DO $$
55
BEGIN
66

77
IF is_multitenant = false THEN
8+
ALTER TABLE storage.iceberg_namespaces DROP CONSTRAINT IF EXISTS iceberg_namespaces_catalog_id_fkey;
9+
ALTER TABLE storage.iceberg_tables DROP CONSTRAINT IF EXISTS iceberg_tables_catalog_id_fkey;
810
ALTER TABLE storage.iceberg_namespaces DROP CONSTRAINT IF EXISTS iceberg_namespaces_bucket_id_fkey;
911
ALTER TABLE storage.iceberg_tables DROP CONSTRAINT IF EXISTS iceberg_tables_bucket_id_fkey;
1012
END IF;
@@ -17,13 +19,16 @@ DO $$
1719
AND table_name = 'buckets_analytics'
1820
AND constraint_type = 'PRIMARY KEY';
1921

20-
EXECUTE drop_constraint_sql;
22+
IF drop_constraint_sql IS NOT NULL THEN
23+
EXECUTE drop_constraint_sql;
24+
END IF;
2125

2226
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'buckets_analytics' AND column_name = 'name') THEN
2327
ALTER TABLE storage.buckets_analytics RENAME COLUMN id TO name;
2428
END IF;
2529

26-
ALTER TABLE storage.buckets_analytics ADD COLUMN IF NOT EXISTS id uuid NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY;
30+
ALTER TABLE storage.buckets_analytics ADD COLUMN IF NOT EXISTS id uuid NOT NULL DEFAULT gen_random_uuid();
31+
ALTER TABLE storage.buckets_analytics ADD PRIMARY KEY (id);
2732
ALTER TABLE storage.buckets_analytics ADD COLUMN IF NOT EXISTS deleted_at timestamptz NULL;
2833

2934
CREATE UNIQUE INDEX IF NOT EXISTS buckets_analytics_unique_name_idx

0 commit comments

Comments
 (0)