Files
member-console/internal/db/migrations/00003_schema_separation.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

75 lines
3.2 KiB
SQL

-- +goose Up
-- +goose StatementBegin
-- Decision 85: All domain tables live in a `core` PostgreSQL schema.
-- Decision 86: Integration modules get schema-per-provider (fedwiki).
-- The `public` schema retains shared extensions and functions only.
CREATE SCHEMA IF NOT EXISTS core;
CREATE SCHEMA IF NOT EXISTS fedwiki;
-- Move existing domain tables to core schema (no-op on fresh installs).
-- Identity
ALTER TABLE IF EXISTS public.users SET SCHEMA core;
ALTER TABLE IF EXISTS public.persons SET SCHEMA core;
-- Organization
ALTER TABLE IF EXISTS public.organizations SET SCHEMA core;
ALTER TABLE IF EXISTS public.workspaces SET SCHEMA core;
ALTER TABLE IF EXISTS public.roles SET SCHEMA core;
ALTER TABLE IF EXISTS public.org_members SET SCHEMA core;
ALTER TABLE IF EXISTS public.role_assignments SET SCHEMA core;
ALTER TABLE IF EXISTS public.invitations SET SCHEMA core;
-- Billing
ALTER TABLE IF EXISTS public.products SET SCHEMA core;
-- Entitlements
ALTER TABLE IF EXISTS public.resource_keys SET SCHEMA core;
ALTER TABLE IF EXISTS public.resource_pools SET SCHEMA core;
ALTER TABLE IF EXISTS public.grants SET SCHEMA core;
ALTER TABLE IF EXISTS public.pool_provisions SET SCHEMA core;
ALTER TABLE IF EXISTS public.pool_assignments SET SCHEMA core;
ALTER TABLE IF EXISTS public.numeric_entitlements SET SCHEMA core;
ALTER TABLE IF EXISTS public.numeric_entitlement_contributions SET SCHEMA core;
ALTER TABLE IF EXISTS public.numeric_entitlement_usage SET SCHEMA core;
ALTER TABLE IF EXISTS public.entitlement_sets SET SCHEMA core;
ALTER TABLE IF EXISTS public.entitlement_set_rules SET SCHEMA core;
ALTER TABLE IF EXISTS public.product_entitlement_rules SET SCHEMA core;
-- Move fedwiki integration table to its own schema (Decision 86).
ALTER TABLE IF EXISTS public.sites SET SCHEMA fedwiki;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
-- Move everything back to public.
ALTER TABLE IF EXISTS fedwiki.sites SET SCHEMA public;
ALTER TABLE IF EXISTS core.product_entitlement_rules SET SCHEMA public;
ALTER TABLE IF EXISTS core.entitlement_set_rules SET SCHEMA public;
ALTER TABLE IF EXISTS core.entitlement_sets SET SCHEMA public;
ALTER TABLE IF EXISTS core.numeric_entitlement_usage SET SCHEMA public;
ALTER TABLE IF EXISTS core.numeric_entitlement_contributions SET SCHEMA public;
ALTER TABLE IF EXISTS core.numeric_entitlements SET SCHEMA public;
ALTER TABLE IF EXISTS core.pool_assignments SET SCHEMA public;
ALTER TABLE IF EXISTS core.pool_provisions SET SCHEMA public;
ALTER TABLE IF EXISTS core.grants SET SCHEMA public;
ALTER TABLE IF EXISTS core.resource_pools SET SCHEMA public;
ALTER TABLE IF EXISTS core.resource_keys SET SCHEMA public;
ALTER TABLE IF EXISTS core.products SET SCHEMA public;
ALTER TABLE IF EXISTS core.invitations SET SCHEMA public;
ALTER TABLE IF EXISTS core.role_assignments SET SCHEMA public;
ALTER TABLE IF EXISTS core.org_members SET SCHEMA public;
ALTER TABLE IF EXISTS core.roles SET SCHEMA public;
ALTER TABLE IF EXISTS core.workspaces SET SCHEMA public;
ALTER TABLE IF EXISTS core.organizations SET SCHEMA public;
ALTER TABLE IF EXISTS core.persons SET SCHEMA public;
ALTER TABLE IF EXISTS core.users SET SCHEMA public;
DROP SCHEMA IF EXISTS fedwiki;
DROP SCHEMA IF EXISTS core;
-- +goose StatementEnd