$npx -y skills add TencentCloudBase/cloudbase-skills --skill postgresql-developmentUse when building, debugging, or evaluating CloudBase PostgreSQL / CloudBase PG / PG mode apps, including Postgres schema setup, queryPgDatabase/managePgDatabase, JS SDK v3 app.rdb() CRUD/RPC, PG HTTP API fallback, RLS-style permissions, username-password auth, and Web CMS/admin
| 1 | ## Standalone Install Note |
| 2 | |
| 3 | If this environment only installed the current skill, start from the CloudBase main entry and use the published `cloudbase/references/...` paths for sibling skills. |
| 4 | |
| 5 | - CloudBase main entry: `https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/SKILL.md` |
| 6 | - Current skill raw source: `https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/postgresql-development/SKILL.md` |
| 7 | |
| 8 | # CloudBase PostgreSQL Development |
| 9 | |
| 10 | ## Activation Contract |
| 11 | |
| 12 | ### Use this first when |
| 13 | |
| 14 | - The task says CloudBase PG, PostgreSQL, Postgres, PG mode, RLS, JS SDK v3 PostgreSQL, `app.rdb()`, `queryPgDatabase`, or `managePgDatabase`. |
| 15 | - A Web app or CMS must persist business data in CloudBase PostgreSQL instead of NoSQL or MySQL. |
| 16 | |
| 17 | ### Then also read |
| 18 | |
| 19 | - Web auth provider readiness -> `../auth-tool/SKILL.md` (standalone fallback: `https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/auth-tool/SKILL.md`) |
| 20 | - Web login implementation -> `../auth-web/SKILL.md` (standalone fallback: `https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/auth-web/SKILL.md`) |
| 21 | - General Web implementation and verification -> `../web-development/SKILL.md` (standalone fallback: `https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/web-development/SKILL.md`) |
| 22 | - Browser storage upload -> `../cloud-storage-web/SKILL.md` (standalone fallback: `https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/cloud-storage-web/SKILL.md`) |
| 23 | - Raw HTTP API details only when SDK coverage is blocked -> `../http-api/SKILL.md` (standalone fallback: `https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/http-api/SKILL.md`) |
| 24 | - PG reference index -> `references/index.md` |
| 25 | - PG mode overview -> `references/pg-mode-overview.md` |
| 26 | - Auth / GRANT / RLS details -> `references/auth-and-rls.md` |
| 27 | - End-to-end PG app closure -> `references/app-workflow.md` |
| 28 | - PG storage details -> `references/storage-pg.md` |
| 29 | - HTTP API fallback -> `references/http-api.md` |
| 30 | - Troubleshooting -> `references/troubleshooting.md` |
| 31 | |
| 32 | ### Do NOT use first |
| 33 | |
| 34 | - `relational-database-tool` / `queryMysqlDatabase` / `manageMysqlDatabase`: those are MySQL-oriented. |
| 35 | - `no-sql-web-sdk` / collection APIs for business data that must live in CloudBase PG. |
| 36 | |
| 37 | ## Required Flow |
| 38 | |
| 39 | ### 🚨 CRITICAL: PG mode API is NOT the same as NoSQL |
| 40 | |
| 41 | CloudBase PG (`app.rdb()`, `app.storage.from('bucket')`) uses **different API method names** than CloudBase NoSQL (`app.database()`, `app.uploadFile()`). Low-capability models often paste legacy NoSQL/auth snippets from training; reject that path immediately. If this task is PG-backed, **do not** write `app.database()`, `db.collection(...)`, `app.uploadFile()`, `getLoginState()`, or route guards based on `auth.getUser()`. Use `app.rdb()`, PG storage v3, and `auth.getSession()` instead. If you are used to writing `.where()`, `.orderBy()`, `.count()` from other ORMs or NoSQL — **stop and read the table below**. |
| 42 | |
| 43 | | ❌ Do NOT use these (NoSQL / ORM habits) | ✅ Use these in PG mode | |
| 44 | |------------------------------------------|------------------------| |
| 45 | | `.where({ field: value })` | `.match({ field: value })` or `.eq("field", value)` | |
| 46 | | `.where("field", "ilike", "%v%")` | `.ilike("field", "%v%")` | |
| 47 | | `.orderBy("field", { ascending: false })` | `.order("field", { ascending: false })` | |
| 48 | | `.count()` | `.select("*", { count: "exact" })` — count is in response | |
| 49 | | `.offset(n)` | `.range(from, to)` | |
| 50 | | `app.uploadFile()` (legacy NoSQL upload) | `app.storage.from('bucket').upload(key, file)` | |
| 51 | | `app.getTempFileURL()` (legacy NoSQL URL) | `app.storage.from('bucket').createSignedUrl(key, expiresIn)` | |
| 52 | | `app.storage.from()` (no bucket name) | `app.storage.from('bucket')` — **must** pass bucket name | |
| 53 | |
| 54 | **If you find yourself typing `.where()` or `.orderBy()` or `.count()` — stop and use the correct method from the right column.** |
| 55 | |
| 56 | 0. **First, confirm this environment actually has PostgreSQL provisioned.** Call `envQuery(action="info", envId=...)` and read the derived `EnvInfo.RuntimeBackends` block (`{ postgresql, nosql, mysql }`) along with `EnvInfo.RuntimeMode`. It is only safe to apply this skill's PG-specific guidance when `RuntimeBackends.postgresql === true` (equivalently, `EnvInfo.PostgreSQL` is non-empty AND/OR `EnvInfo.Meta` contains `postgresql=enable`). |
| 57 | - PG mode is a **new-environment mode** |