Files
member-console/internal/db/migrations/00008_resource_key_kinds.sql
T
cgalo5758 24cb2e66f0 Support boolean entitlement rule authoring
Classify resource keys as boolean or numeric, adapt the operator form to
the selected key, and derive rule types server-side to prevent
wrong-shape rules.
2026-07-22 00:42:01 -05:00

20 lines
1.0 KiB
SQL

-- +goose Up
-- Shape discriminator for resource keys. 'numeric' keys are conferred by
-- limit (and, when materialized, quota) rules and consumed via
-- numeric_entitlements; 'boolean' keys are conferred by boolean rules and
-- consumed via boolean_entitlements. The rule-authoring UI derives rule_type
-- from the selected key's kind, so a wrong-shape rule (e.g. a limit rule on a
-- boolean-consumed key, which materializes a numeric row nothing reads) can no
-- longer be authored.
--
-- DEFAULT 'numeric' is correct for every key existing at the time this
-- migration runs (platform seed keys and fedwiki_sites). Integration streams
-- whose key INSERTs predate this column correct their own rows in their own
-- stream (discourse store 00002); new key INSERTs declare kind explicitly.
ALTER TABLE core.resource_keys
ADD COLUMN kind VARCHAR(20) NOT NULL DEFAULT 'numeric'
CONSTRAINT chk_resource_keys_kind CHECK (kind IN ('boolean', 'numeric'));
-- +goose Down
ALTER TABLE core.resource_keys DROP COLUMN kind;