Files
apskel-pos-backend/migrations/000112_add_budget_controller_to_reward_configs.up.sql
T

20 lines
1.3 KiB
SQL
Raw Normal View History

-- Reward configurations made by accepting a Budget Controller recommendation
-- (docs/rfc-enakgame.md §10, PRD §29–§31). Such a version scales the amounts of the
-- version an admin wrote last, its base, so a run of adjustments never compounds its
-- rounding and min/max multiplier are measured against what the admin set. A version
-- an admin writes has none of the three, and becomes the base of the next adjustments.
ALTER TABLE game_reward_configs
ADD COLUMN base_config_id UUID REFERENCES game_reward_configs(id),
-- Applied to every amount of the base, rounded down: 0.8100 pays 81%.
ADD COLUMN multiplier NUMERIC(6,4),
-- The global budget whose recommendation was accepted.
ADD COLUMN budget_id UUID REFERENCES game_budgets(id),
ADD CONSTRAINT chk_game_reward_configs_controller CHECK (
(base_config_id IS NULL AND multiplier IS NULL AND budget_id IS NULL)
OR (base_config_id IS NOT NULL AND multiplier > 0 AND budget_id IS NOT NULL AND effective_at IS NOT NULL));
-- The last adjustment of an organization, for the cooldown. effective_at is when the
-- Budget Controller made it, by the application clock.
CREATE INDEX idx_game_reward_configs_controller
ON game_reward_configs(organization_id, effective_at DESC) WHERE budget_id IS NOT NULL;