refactor(collections): retire the legacy rules surface — tree-only storage

The pre-tree rules machinery is deleted: no row ever carried a rules
array or a non-default match mode (verified in the dev DB), the web
never read the envelope keys, and the Android app consumes none of it.
Dead code gets no documentation.

Removed:
- PUT /api/collections/:id/match-mode — endpoint, route, and the
  UpdateCollectionMatchMode query. The tree's root mode owns any|all.
- auto_assign_rules / rule_match_mode from every envelope
  (create/list/detail/update), from the create/update request shapes,
  and from the schema: both columns DROPPED (schema.sql carries
  idempotent DROP COLUMN IF EXISTS heals for existing DBs; sqlc
  regenerated).
- The rules CRUD service layer (AddRule/SetRuleEnabled/RemoveRule +
  validateRule + UpdateCollectionRulesJSON), ParseRules /
  EnabledRules / IsSmartCollection, RulesToFilterTree (+ the SSR
  preload branch), the legacy branch of EvaluateSmartMembership, and
  SmartEvalOptions.MatchMode. IsCollectionSmart = tree presence;
  create-path isSmart = collection_type=smart OR a filter_tree.

Kept (live consumers): POST /api/collections/preview still evaluates
rules payloads in memory (the custom-section builder's preview), and
include_auto stays on the list (the Android app sends it).

The custom-section builder's SAVE was already broken — its
stringified auto_assign_rules payload failed request binding (probed
live: 400 invalid request). Create now rejects that payload loudly
with a 400 naming the retirement, instead of silently creating a
hollow static section; custom-section-builder.md carries the flag.
The builder's tree migration remains the flagged follow-up.

Test-side (asymmetry rule — deleted behavior, deleted tests):
TestPodcastSmartCollections rewritten onto trees (mode lives in the
tree root), match-mode subtests and tree_wins_over_legacy_rules
deleted, TestRulesToFilterTree deleted, contract-pin envelope keys
retracted per the contract_pins 2026-10-31 retirement entry. Mirrors
hand-synced: openapi.yaml, bruno create/update, docs/api/*.md,
docs/schema.go, api.d.ts. Full container suite green (155s).
This commit is contained in:
John O'Keefe committed 2026-10-31 19:06:48 -04:00
1 parent ab98015190
commit a86bdac87e
27 files changed
+239 -1093

No files matched your search

+9 -15
View File
@@ -1341,14 +1341,8 @@ CREATE TABLE IF NOT EXISTS collections (
description TEXT,
color VARCHAR(7),
icon VARCHAR(50),
auto_assign_rules JSONB,
-- Smart-collection match semantics (plan item 2.4): 'any' = OR
-- (the original behavior — every legacy row's default), 'all' =
-- AND (the daily briefing needs feed∈{…} ∧ unplayed ∧ <7d).
-- Applied only when rules exist; static collections ignore it.
rule_match_mode TEXT NOT NULL DEFAULT 'any',
-- The unified filter tree (plan item 3.2): when present the qf
-- engine drives membership; see FilterTree. NULL = legacy rules.
-- engine drives membership; see FilterTree. NULL = static.
filter_tree JSONB,
view_settings JSONB,
show_on_dashboard BOOLEAN DEFAULT false,
@@ -1365,16 +1359,16 @@ CREATE TABLE IF NOT EXISTS collections (
-- the row id (and everything referencing it) never churn.
ALTER TABLE collections ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMPTZ;
-- Smart-collection match mode (plan item 2.4): 'any' (OR, legacy
-- default) | 'all' (AND — the daily briefing). Idempotent; NOT NULL
-- DEFAULT covers existing rows.
ALTER TABLE collections ADD COLUMN IF NOT EXISTS rule_match_mode TEXT NOT NULL DEFAULT 'any';
-- Legacy rules-array columns RETIRED (2026-10-31): the unified filter
-- tree is the only smart-membership storage. No production row ever
-- carried a rules array or a non-default match mode (verified), so the
-- columns drop clean; the DROPs are the idempotent heal for databases
-- created before this change.
ALTER TABLE collections DROP COLUMN IF EXISTS auto_assign_rules;
ALTER TABLE collections DROP COLUMN IF EXISTS rule_match_mode;
-- Smart collections in the UNIFIED filter engine (plan item 3.2): the
-- qf tree (same DSL as saved filters, See FilterTree). NULL = no tree
-- (the legacy rules array governs until the collection is rewritten).
-- Legacy rule_match_mode stays authoritative for rules-array
-- collections; a tree's root mode owns its semantics.
-- qf tree (same DSL as saved filters, See FilterTree). NULL = static.
ALTER TABLE collections ADD COLUMN IF NOT EXISTS filter_tree JSONB;
CREATE INDEX IF NOT EXISTS idx_collections_user_id ON collections(user_id);