feat: detail --files --related-ddl 纳入链上对象的附属 DDL 文件 (#161) - #162
Conversation
--files 仍只列出调用链源文件。加上 --related-ddl 后,把链上表/视图的 索引、同义词、触发器文件合并进同一段 FILES,不改变调用树。 Closes #161
| #[test] | ||
| fn collect_chain_files_related_ddl_on_table_target_includes_indexes() { | ||
| let (graph, _proc, table, _index) = proc_table_index_graph("index.sql"); | ||
| let (chain, _) = trace_chain(&graph, table, 1, usize::MAX, true); |
There was a problem hiding this comment.
[suggestion] collect_chain_files_related_ddl_on_table_target_includes_indexes traces from the table with the raw CallChain, so idx_users is already an Incoming caller (IndexesTable). collect_chain_files(..., true) would still list index.sql if related_ddl were ignored. That does not lock the #161 case this test is named for: CLI detail on the table itself runs filter_indexes_from_tree on chain.callers before FILES collection, which is the only reason table --files omits a separate index file.
Suggestion: After trace_chain, drop Node::Index from chain.callers the same way print_node_detail does, then assert related_ddl=false omits index.sql and related_ddl=true brings it back. That is the actual CLI gap.
| }; | ||
| let name = name.to_lowercase(); | ||
| let schema = if trigger_table.len() >= 2 { | ||
| Some(trigger_table[trigger_table.len() - 2].to_lowercase()) |
There was a problem hiding this comment.
[suggestion] trigger_matches_hosts treats schema as only the penultimate component (trigger_table[len-2]). Everywhere else (split_object_name, TableAccessExtractor::add_access) a qualified name’s schema is parts[..len-1].join("."). A 3-part db.schema.t_users host is stored as schema "db.schema", while a trigger ON db.schema.t_users becomes schema "schema", so both-sides-present comparison fails and the trigger file is dropped. 2-part schema.table still works; tests only use unqualified ["t_users"].
Suggestion: Split trigger table the same way as split_object_name (last = name, prefix join = schema), and add a case for ["db", "schema", "t_users"] vs a Table { schema: Some("db.schema"), name: "t_users" } host.
Summary
detail --files只列出调用链上节点的源文件。表 DDL 与索引/同义词/触发器分文件存放时,独立附属 DDL 不会出现在── FILES ──里。本 PR 增加 opt-in
--related-ddl(依赖--files):在同一段 FILES 中合并链上对象的附属 DDL,不改默认--files语义,也不改调用树。Closes #161
Changes
collect_chain_files(chain, graph, related_ddl):related_ddl=true时对链上节点补 IncomingIndexesTable/AliasesObject,并按Trigger.table匹配链上表/视图/物化视图codeweb detail <node> --files --related-ddl;单独--related-ddl被 clap 拒绝f仍只显示调用链文件(本期不做对称开关)docs/user-guide.md§6.7、README 示例不纳入:依赖该表的 VIEW、对该表做 DML 的过程、GRANT/COMMENT(图中无节点)
Testing
cargo test --features cli --bin codeweb collect_chain_filescargo clippy --features full -- -D warningscargo fmt --all覆盖:默认不含独立索引文件、打开后包含、同文件只加标签、同义词+触发器、误匹配其它表触发器、detail 表本身、depth 0、不拉取依赖视图。
Notes