Files
member-console/internal/billing/migrations/00008_subscription_items.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

35 lines
1.3 KiB
SQL

-- +goose Up
-- +goose StatementBegin
CREATE TABLE billing.subscription_items (
subscription_item_id UUID PRIMARY KEY DEFAULT uuidv7(),
subscription_id UUID NOT NULL REFERENCES billing.subscriptions(subscription_id),
product_id UUID NOT NULL REFERENCES billing.products(product_id),
price_id UUID NOT NULL REFERENCES billing.prices(price_id),
quantity INTEGER NOT NULL DEFAULT 1,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX idx_subscription_items_subscription_id ON billing.subscription_items(subscription_id);
CREATE TRIGGER trigger_subscription_items_updated_at
BEFORE UPDATE ON billing.subscription_items
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();
-- Per-schema role grants (Decision 115).
GRANT ALL ON ALL TABLES IN SCHEMA billing TO billing_owner;
GRANT ALL ON ALL TABLES IN SCHEMA billing TO billing_writer;
GRANT SELECT ON ALL TABLES IN SCHEMA billing TO billing_reader;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TRIGGER IF EXISTS trigger_subscription_items_updated_at ON billing.subscription_items;
DROP INDEX IF EXISTS billing.idx_subscription_items_subscription_id;
DROP TABLE IF EXISTS billing.subscription_items;
-- +goose StatementEnd