docs(apps): add platform SQL authoring guide to the db-execute skill - #1912
Conversation
Aligns the lark-cli apps +db-execute skill with the Miaoda platform's SQL constraints (the same dataloom backend the sandbox miaoda-sql skill targets), so agents writing SQL via the CLI don't get server-rejected or build tables that misbehave. Previously the skill covered only the command contract with zero SQL-content guidance. Adds a "平台 SQL 规范" section to lark-apps-db-execute.md covering: - Platform-forbidden SQL (DATABASE/SCHEMA/USER/ROLE/OWNED) that hard-rejects - CREATE TABLE template: 4 audit columns + RLS + 4 default policies - user_profile compound type (ROW()::user_profile, (field).user_id, index) - Audit column names and semantics - DDL rules: IF NOT EXISTS support matrix; pre-check online rows before adding constraints, split by UNIQUE / tighten-to-NOT-NULL / new-NOT-NULL-column - SELECT / DML safety rules and common PostgreSQL pitfalls Sandbox-specific bits (miaoda command names, generate_image, test-user list, schema.ts codegen, string error codes) are intentionally excluded. Wires pointers from SKILL.md routing and lark-apps-db.md.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughChanges平台 SQL 规范指引
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1912 +/- ##
==========================================
+ Coverage 74.73% 74.95% +0.22%
==========================================
Files 887 892 +5
Lines 92644 94056 +1412
==========================================
+ Hits 69235 70502 +1267
- Misses 18050 18140 +90
- Partials 5359 5414 +55 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@fb42b52b615419a64b55bf36fbade3d1e050e7f4🧩 Skill updatenpx skills add larksuite/cli#feat/db-execute-skill-align -y -g |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@skills/lark-apps/references/lark-apps-db-execute.md`:
- Around line 148-152: Update the “IF NOT EXISTS” support matrix to qualify
CREATE EXTENSION as supported only when allowlisted, matching the hard-rejection
behavior for non-whitelisted extensions. Use wording such as “allowlisted CREATE
EXTENSION” or enumerate the permitted extensions; leave the other matrix entries
unchanged.
- Around line 92-105: Restrict the default RLS policies in the SQL template
instead of granting global access: replace the authenticated FOR ALL and
authenticated/anon SELECT USING (true) predicates with explicit role or
ownership checks, and fix “修改本人数据” so its owner predicate can actually match
rather than using the always-empty ARRAY. Preserve service_role bypass, or
clearly document that the template is intentionally public/global.
- Line 229: 更新数据库主键说明:不要将 user_profile 复合值设为主键,统一保留 id uuid PRIMARY KEY DEFAULT
gen_random_uuid();对于人员实体表,改为基于 ((field).user_id) 创建唯一表达式索引,并明确 name、email
等可变字段不参与主键。
- Line 215: Update the table-name example in the schema-prefix guidance so it
uses a relation placeholder such as <table> or a real relation name like orders
instead of user_profile. Keep the guidance that business tables should use bare
names and not public.t.
- Around line 75-86: Update the _created_by and _updated_by default expressions
to treat a NULL app.user_id the same as an empty setting, returning NULL before
constructing the value. Replace the concat-based user_profile cast with
ROW(current_setting('app.user_id', TRUE))::user_profile after the guard.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f3c6f0cc-f8be-4ae4-be0e-0e430e9b17ff
📒 Files selected for processing (3)
skills/lark-apps/SKILL.mdskills/lark-apps/references/lark-apps-db-execute.mdskills/lark-apps/references/lark-apps-db.md
- Drop the IF NOT EXISTS support matrix (redundant / conflicted with the extension-allowlist note in the callout). - Use `orders` instead of the built-in composite type `user_profile` as the bare-table-name example, which was misleading. - Remove the "user_profile PRIMARY KEY" suggestion for person tables (the composite carries mutable fields; a uuid PK is the right default).
What
Aligns the
lark-cli apps +db-executeskill with the Miaoda platform's SQL constraints — the same dataloom backend the sandboxmiaoda-sqlskill targets — so agents writing SQL through the CLI don't get server-rejected or build tables that misbehave. Previously the db-execute skill documented only the command contract (flags/output/transactions) with zero SQL-content guidance.Adds a 「平台 SQL 规范」 section to
lark-apps-db-execute.md(后半部分):CREATE/DROP DATABASE·SCHEMA·USER·ROLE、REASSIGN/DROP OWNED。user_profile复合类型:ROW('<user_id>')::user_profile写入、(field).user_id解引用、三重括号表达式索引。_created_at/_updated_at/_created_by/_updated_by命名与语义。IF NOT EXISTS支持矩阵;多环境库加约束前查 online 存量,按「唯一约束 / 已有列改 NOT NULL / 新加 NOT NULL 字段」三类分别给检查 SQL + 处理方式。Scope decisions
来源是
code.byted.org/apaas/miaoda-skills的miaoda-sqlskill。迁移平台后端共享的 SQL 内容正确性规范;排除沙箱/agent 环境特定内容:miaoda db命令名、generate_image/Picsum 图片规则、测试用户 id 列表、schema.tscodegen、miaoda 字符串错误码(我们用 typed error envelope)。SKILL.md意图路由与lark-apps-db.md加了指向该规范的指针。Testing
TestSkillDocsCommandsConsistentWithShortcuts/TestAppsShortcuts_*通过。+db-execute/+db-table-list/+db-table-get/+db-env-migrate)均真实存在,交叉链接目标文件都在。Summary by CodeRabbit
+db-execute的“意图路由”说明,强调其包含平台 SQL 标准(审计列、RLS、user_profile约束、禁用 SQL 与 PostgreSQL 陷阱等)。+db-execute文档新增“何时用”与完整“平台 SQL 规范”章节,覆盖建表/改表、默认策略、复合类型使用限制、SELECT 行数与分页、DML 风险与安全流程。+db相关指引,新增引用提醒:涉及建表/改表/SQL 时需先对照平台 SQL 规范。