From 46124f3c46e4d7e723787a4fb01f3e62aa1672eb Mon Sep 17 00:00:00 2001 From: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com> Date: Fri, 26 Jun 2026 20:43:38 -0400 Subject: [PATCH] fix(db): add communities to schema snapshot Relay E2E applies schema/schema.sql as declarative desired state before the relay starts. The multi-tenant migration added FKs to communities, but the snapshot did not define the table, so pgschema failed before tests ran. Co-authored-by: Mari <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@sprout-oss.stage.blox.sqprod.co> Signed-off-by: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com> --- schema/schema.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/schema/schema.sql b/schema/schema.sql index cc30730117..7775daaef8 100644 --- a/schema/schema.sql +++ b/schema/schema.sql @@ -18,6 +18,21 @@ CREATE TYPE subscription_status AS ENUM ('active', 'paused', 'deleted'); CREATE TYPE pause_reason AS ENUM ('user', 'system', 'rate_limit'); CREATE TYPE channel_add_policy AS ENUM ('anyone', 'owner_only', 'nobody'); +-- ── Communities ─────────────────────────────────────────────────────────────── +-- Host normalization: `host` is stored already-normalized — ASCII-lowercased, +-- trailing dot stripped, default port omitted. The UNIQUE is on `lower(host)` so +-- resolution and storage agree even if a writer forgets to normalize first. + +CREATE TABLE communities ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + host VARCHAR(255) NOT NULL, + signing_key BYTEA, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + CONSTRAINT chk_communities_id_not_nil CHECK (id <> '00000000-0000-0000-0000-000000000000'::uuid) +); + +CREATE UNIQUE INDEX idx_communities_host ON communities (lower(host)); + -- ── Channels ────────────────────────────────────────────────────────────────── CREATE TABLE channels (