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:
1 parent
ab98015190
commit
a86bdac87e
27 files changed
+239
-1093
No files matched your search
@@ -17,7 +17,6 @@ func registerCollectionsRoutes(cfg *Config) {
|
||||
collections.GET("/:id/books", cfg.CollectionHandler.GetBookCollections)
|
||||
collections.POST("/:id/books", cfg.CollectionHandler.AddBooks)
|
||||
collections.PUT("/:id/items/order", cfg.CollectionHandler.ReorderItems)
|
||||
collections.PUT("/:id/match-mode", cfg.CollectionHandler.SetMatchMode)
|
||||
// The chain's listening order lives ON the collection (plan §10 R2):
|
||||
// merges into view_settings; the episode chain producer honors it.
|
||||
collections.PUT("/:id/view-settings", cfg.CollectionHandler.SetCollectionChainOrder)
|
||||
|
||||
@@ -569,7 +569,6 @@ func registerFrontendRoutes(cfg *Config) {
|
||||
col, services.SmartEvalOptions{
|
||||
LibraryID: libScope,
|
||||
VisibleIDs: visibleIDs,
|
||||
MatchMode: col.RuleMatchMode,
|
||||
ViewerUserID: func() pgtype.UUID {
|
||||
uid, _ := uuid.Parse(user.ID)
|
||||
return uuidToPGType(uid)
|
||||
@@ -702,9 +701,9 @@ func registerFrontendRoutes(cfg *Config) {
|
||||
}
|
||||
|
||||
// The editor's vocabulary + prefill (item 3.4): the unified
|
||||
// builder in the collection's scope. A stored tree renders as-is;
|
||||
// a legacy rules array preloads as its CONVERTED tree
|
||||
// (RulesToFilterTree) — the upgrade lands at the first Apply.
|
||||
// builder in the collection's scope. A stored tree renders
|
||||
// as-is. (The legacy rules-array preload retired 2026-10-31
|
||||
// with the rules-array storage — the tree is the only form.)
|
||||
scope := "books"
|
||||
treeJSON := "{}"
|
||||
if len(collection.FilterTree) > 0 {
|
||||
@@ -714,13 +713,6 @@ func registerFrontendRoutes(cfg *Config) {
|
||||
treeJSON = string(b)
|
||||
}
|
||||
}
|
||||
} else if rules := cfg.CollectionHandler.CollectionService().ParseRules(collection.AutoAssignRules); len(rules) > 0 {
|
||||
if t, cerr := services.RulesToFilterTree(rules, collection.RuleMatchMode); cerr == nil {
|
||||
scope = t.FilterScope()
|
||||
if b, merr := json.Marshal(t); merr == nil {
|
||||
treeJSON = string(b)
|
||||
}
|
||||
}
|
||||
}
|
||||
fieldsPayload, merr := json.Marshal(services.FilterFieldsPayload(scope))
|
||||
if merr != nil {
|
||||
|
||||
@@ -288,7 +288,6 @@ func collectionDataFromRow(collection database.Collections, collectionID string,
|
||||
Icon: collection.Icon.String,
|
||||
IsSystem: collection.IsSystemCollection.Bool,
|
||||
IsSmart: isSmart,
|
||||
MatchMode: collection.RuleMatchMode,
|
||||
ChainOrder: chainOrder,
|
||||
BookCount: bookCount,
|
||||
}
|
||||
@@ -312,7 +311,6 @@ func (cfg *Config) collectionBooksForScope(c *echo.Context, userUUID uuid.UUID,
|
||||
collection, services.SmartEvalOptions{
|
||||
LibraryID: libScope,
|
||||
VisibleIDs: visibleIDs,
|
||||
MatchMode: collection.RuleMatchMode,
|
||||
ViewerUserID: pgtype.UUID{Bytes: userUUID, Valid: true},
|
||||
})
|
||||
if evalErr != nil {
|
||||
|
||||
@@ -341,7 +341,6 @@ func buildSmartCollectionSequenceContext(c *echo.Context, cfg *Config, item *dat
|
||||
}
|
||||
matches, err := colService.EvaluateSmartMembership(ctx, coll, services.SmartEvalOptions{
|
||||
VisibleIDs: visibleIDs,
|
||||
MatchMode: coll.RuleMatchMode,
|
||||
ViewerUserID: userID,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user