-- +goose Up -- Effective credit rules: company > assigned plan > global defaults. -- These affect future debits only. Existing credit history is never repriced. CREATE TABLE IF NOT EXISTS plan_processing_costs ( plan_id BIGINT NOT NULL REFERENCES plans(id) ON DELETE CASCADE, feature_name TEXT NOT NULL, cost_per_unit INTEGER NOT NULL CHECK (cost_per_unit >= 1 AND cost_per_unit <= 1000000), updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), PRIMARY KEY (plan_id, feature_name) ); CREATE TABLE IF NOT EXISTS company_processing_costs ( company_id UUID NOT NULL REFERENCES companies(id) ON DELETE CASCADE, feature_name TEXT NOT NULL, cost_per_unit INTEGER NOT NULL CHECK (cost_per_unit >= 1 AND cost_per_unit <= 1000000), updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), PRIMARY KEY (company_id, feature_name) ); CREATE INDEX IF NOT EXISTS plan_processing_costs_feature_idx ON plan_processing_costs(feature_name); CREATE INDEX IF NOT EXISTS company_processing_costs_feature_idx ON company_processing_costs(feature_name); -- +goose Down DROP TABLE IF EXISTS company_processing_costs; DROP TABLE IF EXISTS plan_processing_costs;