Files
member-console/internal/fedwiki/migrations/00001_init.sql
Christian Galo 1f1540d7e0 Use plain DB connection for migrations
Add ConnectPlain to open the DB without the custom search_path and
switch migration and CLI flows to run on that plain connection.
Wrap multi-statement goose migrations with StatementBegin/End to
ensure statements are executed atomically. Move Stripe price outbox
seeding into a dedicated stripe migration.
2026-04-05 18:25:05 -05:00

43 lines
1.5 KiB
SQL

-- +goose Up
-- +goose StatementBegin
-- Drop legacy user-scoped sites and payments tables (per design D7)
DROP TRIGGER IF EXISTS trigger_payments_updated_at ON payments;
DROP TRIGGER IF EXISTS trigger_sites_updated_at ON sites;
DROP INDEX IF EXISTS idx_payments_payment_processor_id;
DROP INDEX IF EXISTS idx_sites_owner_oidc_subject;
DROP INDEX IF EXISTS idx_sites_domain;
DROP INDEX IF EXISTS idx_payments_user_id;
DROP INDEX IF EXISTS idx_sites_user_id;
DROP TABLE IF EXISTS payments;
DROP TABLE IF EXISTS sites;
-- Create new workspace-scoped sites table in fedwiki schema (Decision 86).
CREATE TABLE fedwiki.sites (
site_id UUID PRIMARY KEY DEFAULT uuidv7(),
workspace_id UUID NOT NULL REFERENCES organization.workspaces(workspace_id),
domain TEXT UNIQUE NOT NULL,
is_custom_domain BOOLEAN NOT NULL DEFAULT FALSE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_sites_workspace_id ON fedwiki.sites(workspace_id);
CREATE INDEX idx_sites_domain ON fedwiki.sites(domain);
CREATE TRIGGER trigger_sites_updated_at
BEFORE UPDATE ON fedwiki.sites
FOR EACH ROW
EXECUTE FUNCTION public.update_updated_at_column();
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TRIGGER IF EXISTS trigger_sites_updated_at ON fedwiki.sites;
DROP INDEX IF EXISTS fedwiki.idx_sites_domain;
DROP INDEX IF EXISTS fedwiki.idx_sites_workspace_id;
DROP TABLE IF EXISTS fedwiki.sites;
-- +goose StatementEnd