Skip to content

feat: detail --files --related-ddl 纳入链上对象的附属 DDL 文件 (#161) - #162

Merged
c2j merged 1 commit into
mainfrom
feature/detail-related-ddl
Sep 8, 2026
Merged

c2j merged 1 commit into
mainfrom
feature/detail-related-ddl

Conversation

@c2j

@c2j c2j commented Sep 8, 2026

Copy link
Copy Markdown
Owner

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 时对链上节点补 Incoming IndexesTable / AliasesObject,并按 Trigger.table 匹配链上表/视图/物化视图
  • CLI:codeweb detail <node> --files --related-ddl;单独 --related-ddl 被 clap 拒绝
  • TUI f 仍只显示调用链文件(本期不做对称开关)
  • 文档:docs/user-guide.md §6.7、README 示例

不纳入:依赖该表的 VIEW、对该表做 DML 的过程、GRANT/COMMENT(图中无节点)

Testing

  • cargo test --features cli --bin codeweb collect_chain_files
  • cargo clippy --features full -- -D warnings
  • cargo fmt --all

覆盖:默认不含独立索引文件、打开后包含、同文件只加标签、同义词+触发器、误匹配其它表触发器、detail 表本身、depth 0、不拉取依赖视图。

Notes

  • MCP / HTTP 本来没有 FILES,未做对称参数
  • 不修「存过按同义名访问落到 inferred 表」的既有解析限制

--files 仍只列出调用链源文件。加上 --related-ddl 后,把链上表/视图的
索引、同义词、触发器文件合并进同一段 FILES,不改变调用树。

Closes #161
Comment thread src/graph/traverse.rs
#[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);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Comment thread src/graph/traverse.rs
};
let name = name.to_lowercase();
let schema = if trigger_table.len() >= 2 {
Some(trigger_table[trigger_table.len() - 2].to_lowercase())

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@c2j
c2j merged commit bba7f23 into main Sep 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: detail --files --related-ddl 纳入链上对象的附属 DDL 文件(索引/同义词/触发器)

1 participant