Skip to content

docs(apps): add platform SQL authoring guide to the db-execute skill - #1912

Merged
chenxingyang1019 merged 2 commits into
mainfrom
feat/db-execute-skill-align
Jul 16, 2026
Merged

docs(apps): add platform SQL authoring guide to the db-execute skill#1912
chenxingyang1019 merged 2 commits into
mainfrom
feat/db-execute-skill-align

Conversation

@chenxingyang1019

@chenxingyang1019 chenxingyang1019 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

What

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 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 (后半部分):

  • 平台禁用 SQL(硬拒绝):CREATE/DROP DATABASE·SCHEMA·USER·ROLEREASSIGN/DROP OWNED
  • 建表规范:4 个审计列 + 启用 RLS + 4 条默认 policy 模板,一次调用写全。
  • user_profile 复合类型ROW('<user_id>')::user_profile 写入、(field).user_id 解引用、三重括号表达式索引。
  • 审计列_created_at/_updated_at/_created_by/_updated_by 命名与语义。
  • DDL 规则IF NOT EXISTS 支持矩阵;多环境库加约束前查 online 存量,按「唯一约束 / 已有列改 NOT NULL / 新加 NOT NULL 字段」三类分别给检查 SQL + 处理方式。
  • SELECT / DML 安全规则常见 PostgreSQL 陷阱

Scope decisions

来源是 code.byted.org/apaas/miaoda-skillsmiaoda-sql skill。迁移平台后端共享的 SQL 内容正确性规范;排除沙箱/agent 环境特定内容:miaoda db 命令名、generate_image/Picsum 图片规则、测试用户 id 列表、schema.ts codegen、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

  • Documentation
    • 更新 +db-execute 的“意图路由”说明,强调其包含平台 SQL 标准(审计列、RLS、user_profile 约束、禁用 SQL 与 PostgreSQL 陷阱等)。
    • +db-execute 文档新增“何时用”与完整“平台 SQL 规范”章节,覆盖建表/改表、默认策略、复合类型使用限制、SELECT 行数与分页、DML 风险与安全流程。
    • 更新 +db 相关指引,新增引用提醒:涉及建表/改表/SQL 时需先对照平台 SQL 规范。

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.
@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 86595d59-95f1-43a9-a268-660e586ad9ac

📥 Commits

Reviewing files that changed from the base of the PR and between 36b9ee4 and fb42b52.

📒 Files selected for processing (1)
  • skills/lark-apps/references/lark-apps-db-execute.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • skills/lark-apps/references/lark-apps-db-execute.md

📝 Walkthrough

Walkthrough

Changes

平台 SQL 规范指引

Layer / File(s) Summary
命令路由与规范引用
skills/lark-apps/SKILL.md, skills/lark-apps/references/lark-apps-db.md, skills/lark-apps/references/lark-apps-db-execute.md
更新 +db-execute 路由描述,并在数据库命令说明中增加平台 SQL 规范引用及使用前提示。
平台 SQL 与建表变更规则
skills/lark-apps/references/lark-apps-db-execute.md
新增禁用 SQL、审计列、RLS、默认 policy、user_profile 及 DDL 变更规则。
查询、DML 与 PostgreSQL 设计规则
skills/lark-apps/references/lark-apps-db-execute.md
新增 SELECT、DML、PostgreSQL 陷阱、数据类型和约束设计规则。

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change to the db-execute skill.
Description check ✅ Passed The description covers the summary, main changes, testing, and scope decisions, with only the template headings and related issues section missing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/db-execute-skill-align

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.95%. Comparing base (80b3645) to head (fb42b52).
⚠️ Report is 4 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@fb42b52b615419a64b55bf36fbade3d1e050e7f4

🧩 Skill update

npx skills add larksuite/cli#feat/db-execute-skill-align -y -g

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between baf6050 and 36b9ee4.

📒 Files selected for processing (3)
  • skills/lark-apps/SKILL.md
  • skills/lark-apps/references/lark-apps-db-execute.md
  • skills/lark-apps/references/lark-apps-db.md

Comment thread skills/lark-apps/references/lark-apps-db-execute.md
Comment thread skills/lark-apps/references/lark-apps-db-execute.md
Comment thread skills/lark-apps/references/lark-apps-db-execute.md Outdated
Comment thread skills/lark-apps/references/lark-apps-db-execute.md Outdated
Comment thread skills/lark-apps/references/lark-apps-db-execute.md Outdated
- 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).
@chenxingyang1019
chenxingyang1019 merged commit 65998a2 into main Jul 16, 2026
43 checks passed
@chenxingyang1019
chenxingyang1019 deleted the feat/db-execute-skill-align branch July 16, 2026 08:05
@liangshuo-1 liangshuo-1 mentioned this pull request Jul 16, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants