ci / lint-test (push) Successful in 38s
Apply History listed only counts - '13 matches · 13 transactions' - which reads identically whether the run renamed a merchant or split every transaction with another participant. Revert is destructive, so that is not enough to decide on. Two additions. Migration 0017 records rule_id, rule_name and source on each run: rule_name is denormalised so history stays readable after a rule is edited or deleted, and there is no FK so deleting a rule cannot cascade away the audit trail. Both write paths now populate it - the condition-matched run and the selection-based quick action. And rows expand to show the run's snapshot set against current values: which transactions were touched and what changed on each. Rows changed by something else since the run are called out, because reverting restores the pre-run value and would discard that later edit. Runs recorded before this show 'Unknown rule' - the rule they came from is not recoverable.
29 lines
1.4 KiB
SQL
29 lines
1.4 KiB
SQL
-- Record which rule a run came from.
|
|
--
|
|
-- rule_apply_runs stored only counts ("13 matches · 13 transactions"), which is
|
|
-- not enough to decide whether to revert: you cannot tell a merchant rename from
|
|
-- a 50/50 split of your entire history. The snapshot column already holds the
|
|
-- before-state, but nothing said what was applied or why.
|
|
--
|
|
-- rule_name is denormalised deliberately. A run must stay readable after the
|
|
-- rule it came from is edited or deleted -- the history is a record of what
|
|
-- happened, not a pointer to what the rule says today.
|
|
|
|
ALTER TABLE rule_apply_runs
|
|
ADD COLUMN IF NOT EXISTS rule_id INTEGER,
|
|
ADD COLUMN IF NOT EXISTS rule_name TEXT,
|
|
-- 'all' = bulk run over every enabled rule; 'rule' = one rule by conditions;
|
|
-- 'selection' = one rule against hand-picked transactions (preview → apply).
|
|
ADD COLUMN IF NOT EXISTS source TEXT;
|
|
|
|
ALTER TABLE rule_apply_runs DROP CONSTRAINT IF EXISTS rule_apply_runs_source_check;
|
|
ALTER TABLE rule_apply_runs ADD CONSTRAINT rule_apply_runs_source_check
|
|
CHECK (source IS NULL OR source IN ('all', 'rule', 'selection'));
|
|
|
|
-- No FK to rules: deleting a rule must not cascade away the audit trail.
|
|
CREATE INDEX IF NOT EXISTS idx_rule_apply_runs_rule
|
|
ON rule_apply_runs (rule_id) WHERE rule_id IS NOT NULL;
|
|
|
|
-- Existing rows stay NULL. There is no way to recover which rule they ran;
|
|
-- the UI shows them as "unknown rule" rather than guessing.
|