@rebasepro/cli 0.29.0 → 0.29.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{apps-Dg0NnmmJ.js → apps-MKQbgDtN.js} +3 -3
- package/dist/{apps-Dg0NnmmJ.js.map → apps-MKQbgDtN.js.map} +1 -1
- package/dist/{auth-DifFaOyq.js → auth-Bv0rTbQX.js} +3 -3
- package/dist/{auth-DifFaOyq.js.map → auth-Bv0rTbQX.js.map} +1 -1
- package/dist/{build-1Zo35L6a.js → build-BuKTnec8.js} +3 -3
- package/dist/{build-1Zo35L6a.js.map → build-BuKTnec8.js.map} +1 -1
- package/dist/{bundle-CTkzO2WG.js → bundle-BAH4FCju.js} +2 -2
- package/dist/{bundle-CTkzO2WG.js.map → bundle-BAH4FCju.js.map} +1 -1
- package/dist/{cloud-CFotGK2-.js → cloud-DWL-lxU_.js} +6 -6
- package/dist/cloud-DWL-lxU_.js.map +1 -0
- package/dist/commands/cloud/context.d.ts +1 -1
- package/dist/commands/doctor.d.ts +1 -0
- package/dist/{console-BXB6-8GT.js → console-CdwIYOMV.js} +2 -2
- package/dist/{console-BXB6-8GT.js.map → console-CdwIYOMV.js.map} +1 -1
- package/dist/{context-DN1b9pCR.js → context-AXdAh-q8.js} +2 -2
- package/dist/{context-DN1b9pCR.js.map → context-AXdAh-q8.js.map} +1 -1
- package/dist/{db-KzlqddGD.js → db-DBbKpjYX.js} +35 -6
- package/dist/{db-KzlqddGD.js.map → db-DBbKpjYX.js.map} +1 -1
- package/dist/{dev-CzOazEHW.js → dev-C93d4QIv.js} +2 -2
- package/dist/{dev-CzOazEHW.js.map → dev-C93d4QIv.js.map} +1 -1
- package/dist/{doctor-BuqSHNrd.js → doctor-BBPQUO2g.js} +12 -4
- package/dist/{doctor-BuqSHNrd.js.map → doctor-BBPQUO2g.js.map} +1 -1
- package/dist/eject-DABcDnPN.js.map +1 -1
- package/dist/{fold-static-vbZJeo37.js → fold-static-BWzxNn06.js} +2 -2
- package/dist/{fold-static-vbZJeo37.js.map → fold-static-BWzxNn06.js.map} +1 -1
- package/dist/{generate_sdk-DCUUogIP.js → generate_sdk-DNmNuFuW.js} +2 -2
- package/dist/{generate_sdk-DCUUogIP.js.map → generate_sdk-DNmNuFuW.js.map} +1 -1
- package/dist/index.es.js +21 -21
- package/dist/{init-YzfyEffT.js → init-vL1DWOeC.js} +2 -2
- package/dist/{init-YzfyEffT.js.map → init-vL1DWOeC.js.map} +1 -1
- package/dist/manifest-BtzDy7KQ.js.map +1 -1
- package/dist/{normalize-imports-xpSL_GuU.js → normalize-imports-Bd5Y4yLp.js} +2 -2
- package/dist/{normalize-imports-xpSL_GuU.js.map → normalize-imports-Bd5Y4yLp.js.map} +1 -1
- package/dist/resources/status.d.ts +2 -2
- package/dist/{schema-CApM25cs.js → schema-DtLPsXbT.js} +3 -3
- package/dist/{schema-CApM25cs.js.map → schema-DtLPsXbT.js.map} +1 -1
- package/dist/schema-reconcile-DkArN9jF.js +2 -0
- package/dist/{start-28EztR4R.js → start-YOr3X5Zm.js} +2 -2
- package/dist/{start-28EztR4R.js.map → start-YOr3X5Zm.js.map} +1 -1
- package/dist/status-BREvtzJm.js.map +1 -1
- package/dist/{verify-D7UsV_qe.js → verify-Y3rWSgfA.js} +2 -2
- package/dist/{verify-D7UsV_qe.js.map → verify-Y3rWSgfA.js.map} +1 -1
- package/package.json +8 -8
- package/templates/generated-schemas/blank.ts +8 -8
- package/templates/generated-schemas/blog.ts +33 -33
- package/templates/generated-schemas/ecommerce.ts +23 -23
- package/templates/overlays/baas/ai-instructions.md +1 -1
- package/templates/template/.cursorrules +1 -1
- package/templates/template/.github/copilot-instructions.md +1 -1
- package/templates/template/.windsurfrules +1 -1
- package/templates/template/AGENTS.md +1 -1
- package/templates/template/CLAUDE.md +1 -1
- package/templates/template/ai-instructions.md +1 -1
- package/templates/template/backend/functions/hello.ts +4 -3
- package/dist/cloud-CFotGK2-.js.map +0 -1
- package/dist/schema-reconcile-CX1_6Xqm.js +0 -2
|
@@ -15,11 +15,11 @@ export const categories = pgTable("categories", {
|
|
|
15
15
|
description: text("description"),
|
|
16
16
|
icon: text("icon")
|
|
17
17
|
}, (table) => ([
|
|
18
|
-
pgPolicy("categories_all_c924b8e", { as: "permissive", for: "all", to: ["
|
|
19
|
-
pgPolicy("categories_default_admin_read", { as: "permissive", for: "select", to: ["
|
|
20
|
-
pgPolicy("categories_default_admin_write_insert", { as: "permissive", for: "insert", to: ["
|
|
21
|
-
pgPolicy("categories_default_admin_write_update", { as: "permissive", for: "update", to: ["
|
|
22
|
-
pgPolicy("categories_default_admin_write_delete", { as: "permissive", for: "delete", to: ["
|
|
18
|
+
pgPolicy("categories_all_c924b8e", { as: "permissive", for: "all", to: ["rebase_admin"], using: sql`(SELECT string_to_array(rebase.roles(), ',') && ARRAY['admin'])`, withCheck: sql`(SELECT string_to_array(rebase.roles(), ',') && ARRAY['admin'])` }),
|
|
19
|
+
pgPolicy("categories_default_admin_read", { as: "permissive", for: "select", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
20
|
+
pgPolicy("categories_default_admin_write_insert", { as: "permissive", for: "insert", to: ["rebase_admin"], withCheck: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
21
|
+
pgPolicy("categories_default_admin_write_update", { as: "permissive", for: "update", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))`, withCheck: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
22
|
+
pgPolicy("categories_default_admin_write_delete", { as: "permissive", for: "delete", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
23
23
|
])).enableRLS();
|
|
24
24
|
|
|
25
25
|
export const orders = pgTable("orders", {
|
|
@@ -30,11 +30,11 @@ export const orders = pgTable("orders", {
|
|
|
30
30
|
notes: text("notes"),
|
|
31
31
|
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).default(sql`now()`)
|
|
32
32
|
}, (table) => ([
|
|
33
|
-
pgPolicy("orders_all_c924b8e", { as: "permissive", for: "all", to: ["
|
|
34
|
-
pgPolicy("orders_default_admin_read", { as: "permissive", for: "select", to: ["
|
|
35
|
-
pgPolicy("orders_default_admin_write_insert", { as: "permissive", for: "insert", to: ["
|
|
36
|
-
pgPolicy("orders_default_admin_write_update", { as: "permissive", for: "update", to: ["
|
|
37
|
-
pgPolicy("orders_default_admin_write_delete", { as: "permissive", for: "delete", to: ["
|
|
33
|
+
pgPolicy("orders_all_c924b8e", { as: "permissive", for: "all", to: ["rebase_admin"], using: sql`(SELECT string_to_array(rebase.roles(), ',') && ARRAY['admin'])`, withCheck: sql`(SELECT string_to_array(rebase.roles(), ',') && ARRAY['admin'])` }),
|
|
34
|
+
pgPolicy("orders_default_admin_read", { as: "permissive", for: "select", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
35
|
+
pgPolicy("orders_default_admin_write_insert", { as: "permissive", for: "insert", to: ["rebase_admin"], withCheck: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
36
|
+
pgPolicy("orders_default_admin_write_update", { as: "permissive", for: "update", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))`, withCheck: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
37
|
+
pgPolicy("orders_default_admin_write_delete", { as: "permissive", for: "delete", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
38
38
|
])).enableRLS();
|
|
39
39
|
|
|
40
40
|
export const products = pgTable("products", {
|
|
@@ -47,11 +47,11 @@ export const products = pgTable("products", {
|
|
|
47
47
|
categoryId: integer("category_id").references((): AnyPgColumn => categories.id, { onDelete: "set null" })
|
|
48
48
|
}, (table) => ([
|
|
49
49
|
index("products_category_id_ix_066548f").on(table.categoryId.asc().nullsLast()),
|
|
50
|
-
pgPolicy("products_all_c924b8e", { as: "permissive", for: "all", to: ["
|
|
51
|
-
pgPolicy("products_default_admin_read", { as: "permissive", for: "select", to: ["
|
|
52
|
-
pgPolicy("products_default_admin_write_insert", { as: "permissive", for: "insert", to: ["
|
|
53
|
-
pgPolicy("products_default_admin_write_update", { as: "permissive", for: "update", to: ["
|
|
54
|
-
pgPolicy("products_default_admin_write_delete", { as: "permissive", for: "delete", to: ["
|
|
50
|
+
pgPolicy("products_all_c924b8e", { as: "permissive", for: "all", to: ["rebase_admin"], using: sql`(SELECT string_to_array(rebase.roles(), ',') && ARRAY['admin'])`, withCheck: sql`(SELECT string_to_array(rebase.roles(), ',') && ARRAY['admin'])` }),
|
|
51
|
+
pgPolicy("products_default_admin_read", { as: "permissive", for: "select", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
52
|
+
pgPolicy("products_default_admin_write_insert", { as: "permissive", for: "insert", to: ["rebase_admin"], withCheck: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
53
|
+
pgPolicy("products_default_admin_write_update", { as: "permissive", for: "update", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))`, withCheck: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
54
|
+
pgPolicy("products_default_admin_write_delete", { as: "permissive", for: "delete", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
55
55
|
])).enableRLS();
|
|
56
56
|
|
|
57
57
|
export const users = rebaseSchema.table("users", {
|
|
@@ -68,14 +68,14 @@ export const users = rebaseSchema.table("users", {
|
|
|
68
68
|
createdAt: timestamp("created_at", { withTimezone: true, mode: 'string' }).default(sql`now()`),
|
|
69
69
|
updatedAt: timestamp("updated_at", { withTimezone: true, mode: 'string' }).default(sql`now()`)
|
|
70
70
|
}, (table) => ([
|
|
71
|
-
pgPolicy("users_select_5f32f06", { as: "permissive", for: "select", to: ["
|
|
72
|
-
pgPolicy("users_insert_3561e70_0", { as: "permissive", for: "insert", to: ["
|
|
73
|
-
pgPolicy("users_update_3561e70_1", { as: "permissive", for: "update", to: ["
|
|
74
|
-
pgPolicy("users_delete_3561e70_2", { as: "permissive", for: "delete", to: ["
|
|
75
|
-
pgPolicy("users_default_admin_read", { as: "permissive", for: "select", to: ["
|
|
76
|
-
pgPolicy("users_default_admin_write_insert", { as: "permissive", for: "insert", to: ["
|
|
77
|
-
pgPolicy("users_default_admin_write_update", { as: "permissive", for: "update", to: ["
|
|
78
|
-
pgPolicy("users_default_admin_write_delete", { as: "permissive", for: "delete", to: ["
|
|
71
|
+
pgPolicy("users_select_5f32f06", { as: "permissive", for: "select", to: ["rebase_admin"], using: sql`(SELECT string_to_array(rebase.roles(), ',') && ARRAY['admin'])` }),
|
|
72
|
+
pgPolicy("users_insert_3561e70_0", { as: "permissive", for: "insert", to: ["rebase_admin"], withCheck: sql`(SELECT string_to_array(rebase.roles(), ',') && ARRAY['admin'])` }),
|
|
73
|
+
pgPolicy("users_update_3561e70_1", { as: "permissive", for: "update", to: ["rebase_admin"], using: sql`(SELECT string_to_array(rebase.roles(), ',') && ARRAY['admin'])`, withCheck: sql`(SELECT string_to_array(rebase.roles(), ',') && ARRAY['admin'])` }),
|
|
74
|
+
pgPolicy("users_delete_3561e70_2", { as: "permissive", for: "delete", to: ["rebase_admin"], using: sql`(SELECT string_to_array(rebase.roles(), ',') && ARRAY['admin'])` }),
|
|
75
|
+
pgPolicy("users_default_admin_read", { as: "permissive", for: "select", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
76
|
+
pgPolicy("users_default_admin_write_insert", { as: "permissive", for: "insert", to: ["rebase_admin"], withCheck: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
77
|
+
pgPolicy("users_default_admin_write_update", { as: "permissive", for: "update", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))`, withCheck: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
78
|
+
pgPolicy("users_default_admin_write_delete", { as: "permissive", for: "delete", to: ["rebase_admin"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
79
79
|
pgPolicy("users_default_self_read", { as: "permissive", for: "select", to: ["public"], using: sql`(id)::text = (SELECT rebase.uid())` }),
|
|
80
80
|
pgPolicy("users_require_admin_write_insert", { as: "restrictive", for: "insert", to: ["public"], withCheck: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
81
81
|
pgPolicy("users_require_admin_write_update", { as: "restrictive", for: "update", to: ["public"], using: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))`, withCheck: sql`(SELECT (rebase.uid() IS NULL) OR (string_to_array(rebase.roles(), ',') && ARRAY['admin']))` }),
|
|
@@ -26,7 +26,7 @@ This is a **headless** Rebase project: a REST API, auth, storage and realtime ov
|
|
|
26
26
|
- **Never edit `.env`.** It holds generated secrets and the connection string. Add a variable by asking, and document it in `.env.example`.
|
|
27
27
|
- **Never edit `rebase.resources.json`.** It is generated from `config/resources.ts` — declare there, then `rebase resources --write`.
|
|
28
28
|
- **Never pass `--allow-destructive`** to anything pointed at a database that is not the local development one. It drops columns and tables.
|
|
29
|
-
- **Never read or write application rows
|
|
29
|
+
- **Never read or write application rows as the database owner from code.** The schema is SQL here; owner-level data access (`rebase.sql()`, a Drizzle client) is not, because it skips row-level security, validation and hooks. Analytics have an SDK form — `aggregate()` with `countDistinct`, `mode`, `percentile`, `distinct`, groups by `lower(…)`, `day(…)` or `unnest(tags)`, and `fingerprint()` to know whether a table changed — and bulk writes are `createMany` / `updateMany`, one statement per batch. When those do not fit, `getSql(c)` in a function runs one statement as the caller, under the same policies as the API: read-only unless `{ write: true }`, the query text yours and every value in `params`.
|
|
30
30
|
|
|
31
31
|
## Core rules
|
|
32
32
|
|
|
@@ -6,7 +6,7 @@ The Rebase skills for this assistant live in `.cursor/rules/`. If they are not t
|
|
|
6
6
|
|
|
7
7
|
These hold before you have opened ai-instructions.md, and in every session:
|
|
8
8
|
|
|
9
|
-
- **A table is a collection.** Declare it in `config/collections/<name>.ts` with `defineCollection`, and `pnpm dev` creates it. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never
|
|
9
|
+
- **A table is a collection.** Declare it in `config/collections/<name>.ts` with `defineCollection`, and `pnpm dev` creates it. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never SQL as the database owner against an application table: `rebase.sql()` skips row-level security, validation and callbacks, so keep it for server work that needs every row and for reading a column marked `excludeFromApi`. When the SDK cannot express a query, run it as the caller with `getSql(c)` — the same row-level security as the SDK, read-only unless `{ write: true }`, every value in `params`. A table that already exists gets its collection from `pnpm schema:introspect`.
|
|
10
10
|
- **Data goes through the SDK:** `rebase.dataAsAdmin.<slug>` in functions and crons, `getDriver(c)` to act as the caller.
|
|
11
11
|
- **A route in `backend/functions/` is public until you guard it** with `requireAuth` or `requireAdmin` from `@rebasepro/server/functions`.
|
|
12
12
|
- **Never deploy, never edit `.env`, never edit generated files** (`backend/src/schema.generated.ts`, `rebase.resources.json`).
|
|
@@ -6,7 +6,7 @@ The Rebase skills for this assistant live in `.github/instructions/`. If they ar
|
|
|
6
6
|
|
|
7
7
|
These hold before you have opened ai-instructions.md, and in every session:
|
|
8
8
|
|
|
9
|
-
- **A table is a collection.** Declare it in `config/collections/<name>.ts` with `defineCollection`, and `pnpm dev` creates it. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never
|
|
9
|
+
- **A table is a collection.** Declare it in `config/collections/<name>.ts` with `defineCollection`, and `pnpm dev` creates it. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never SQL as the database owner against an application table: `rebase.sql()` skips row-level security, validation and callbacks, so keep it for server work that needs every row and for reading a column marked `excludeFromApi`. When the SDK cannot express a query, run it as the caller with `getSql(c)` — the same row-level security as the SDK, read-only unless `{ write: true }`, every value in `params`. A table that already exists gets its collection from `pnpm schema:introspect`.
|
|
10
10
|
- **Data goes through the SDK:** `rebase.dataAsAdmin.<slug>` in functions and crons, `getDriver(c)` to act as the caller.
|
|
11
11
|
- **A route in `backend/functions/` is public until you guard it** with `requireAuth` or `requireAdmin` from `@rebasepro/server/functions`.
|
|
12
12
|
- **Never deploy, never edit `.env`, never edit generated files** (`backend/src/schema.generated.ts`, `rebase.resources.json`).
|
|
@@ -6,7 +6,7 @@ The Rebase skills for this assistant live in `.windsurf/rules/`. If they are not
|
|
|
6
6
|
|
|
7
7
|
These hold before you have opened ai-instructions.md, and in every session:
|
|
8
8
|
|
|
9
|
-
- **A table is a collection.** Declare it in `config/collections/<name>.ts` with `defineCollection`, and `pnpm dev` creates it. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never
|
|
9
|
+
- **A table is a collection.** Declare it in `config/collections/<name>.ts` with `defineCollection`, and `pnpm dev` creates it. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never SQL as the database owner against an application table: `rebase.sql()` skips row-level security, validation and callbacks, so keep it for server work that needs every row and for reading a column marked `excludeFromApi`. When the SDK cannot express a query, run it as the caller with `getSql(c)` — the same row-level security as the SDK, read-only unless `{ write: true }`, every value in `params`. A table that already exists gets its collection from `pnpm schema:introspect`.
|
|
10
10
|
- **Data goes through the SDK:** `rebase.dataAsAdmin.<slug>` in functions and crons, `getDriver(c)` to act as the caller.
|
|
11
11
|
- **A route in `backend/functions/` is public until you guard it** with `requireAuth` or `requireAdmin` from `@rebasepro/server/functions`.
|
|
12
12
|
- **Never deploy, never edit `.env`, never edit generated files** (`backend/src/schema.generated.ts`, `rebase.resources.json`).
|
|
@@ -6,7 +6,7 @@ The Rebase skills for this assistant live in `.agents/skills/`. If they are not
|
|
|
6
6
|
|
|
7
7
|
These hold before you have opened ai-instructions.md, and in every session:
|
|
8
8
|
|
|
9
|
-
- **A table is a collection.** Declare it in `config/collections/<name>.ts` with `defineCollection`, and `pnpm dev` creates it. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never
|
|
9
|
+
- **A table is a collection.** Declare it in `config/collections/<name>.ts` with `defineCollection`, and `pnpm dev` creates it. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never SQL as the database owner against an application table: `rebase.sql()` skips row-level security, validation and callbacks, so keep it for server work that needs every row and for reading a column marked `excludeFromApi`. When the SDK cannot express a query, run it as the caller with `getSql(c)` — the same row-level security as the SDK, read-only unless `{ write: true }`, every value in `params`. A table that already exists gets its collection from `pnpm schema:introspect`.
|
|
10
10
|
- **Data goes through the SDK:** `rebase.dataAsAdmin.<slug>` in functions and crons, `getDriver(c)` to act as the caller.
|
|
11
11
|
- **A route in `backend/functions/` is public until you guard it** with `requireAuth` or `requireAdmin` from `@rebasepro/server/functions`.
|
|
12
12
|
- **Never deploy, never edit `.env`, never edit generated files** (`backend/src/schema.generated.ts`, `rebase.resources.json`).
|
|
@@ -6,7 +6,7 @@ The Rebase skills for this assistant live in `.claude/skills/`. If they are not
|
|
|
6
6
|
|
|
7
7
|
These hold before you have opened ai-instructions.md, and in every session:
|
|
8
8
|
|
|
9
|
-
- **A table is a collection.** Declare it in `config/collections/<name>.ts` with `defineCollection`, and `pnpm dev` creates it. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never
|
|
9
|
+
- **A table is a collection.** Declare it in `config/collections/<name>.ts` with `defineCollection`, and `pnpm dev` creates it. Never `CREATE TABLE`, `ALTER TABLE` or `CREATE INDEX` in code, and never SQL as the database owner against an application table: `rebase.sql()` skips row-level security, validation and callbacks, so keep it for server work that needs every row and for reading a column marked `excludeFromApi`. When the SDK cannot express a query, run it as the caller with `getSql(c)` — the same row-level security as the SDK, read-only unless `{ write: true }`, every value in `params`. A table that already exists gets its collection from `pnpm schema:introspect`.
|
|
10
10
|
- **Data goes through the SDK:** `rebase.dataAsAdmin.<slug>` in functions and crons, `getDriver(c)` to act as the caller.
|
|
11
11
|
- **A route in `backend/functions/` is public until you guard it** with `requireAuth` or `requireAdmin` from `@rebasepro/server/functions`.
|
|
12
12
|
- **Never deploy, never edit `.env`, never edit generated files** (`backend/src/schema.generated.ts`, `rebase.resources.json`).
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
## Never
|
|
24
24
|
|
|
25
|
-
- **Never create or change a table in code, and never write
|
|
25
|
+
- **Never create or change a table in code, and never write SQL as the database owner against application tables.** A table is a collection (core rule 1), and one that already exists gets its collection from `pnpm schema:introspect`. `rebase.sql()` runs as the owner — no row-level security, validation or hooks — so it is for server work that genuinely needs every row, and for reading a column marked `excludeFromApi`, which the API never returns; it logs a warning naming the fix when it is used to create, alter, drop or index a table. Prefer the SDK where it fits: `aggregate()` with `countDistinct`, `mode`, `percentile`, `distinct` and groups by `lower(…)`, `day(…)` or `unnest(tags)`; `fingerprint()` instead of hashing a table; `updateMany` with a value per row and `createMany` (one statement for the batch); `array-contains-all` / `array-contained-by` filters; a collection with `view: { query }` for a query worth naming. For anything else, write the SQL **as the caller**: `getSql(c)` in a function runs one statement in the caller's transaction under the same row-level security as the SDK, read-only unless `{ write: true }`. The query text is yours and every value goes in `params` (`$1`, `$2`, …) — never interpolate into the string. Columns the caller may not read (`excludeFromApi`, `access.read`) are dropped from what it returns when the query names them plainly, not when it computes from them; read hooks, validation and save hooks do not run.
|
|
26
26
|
- **Never deploy.** `pnpm deploy`, `rebase cloud deploy`, `firebase deploy`, `gcloud run deploy` — print the command and let the human run it, even when the task list ends in "deploy" and the tests are green.
|
|
27
27
|
- **Never edit `.env`.** It holds generated secrets and the connection string. Add a variable by asking, and document it in `.env.example`.
|
|
28
28
|
- **Never edit `backend/src/schema.generated.ts`.** It is overwritten by `pnpm schema:generate`; the collection file is the source.
|
|
@@ -61,9 +61,10 @@ import {
|
|
|
61
61
|
* `policy.serverContext()` is false for it (that arm means "no uid at all"),
|
|
62
62
|
* and anything an `admin` user can reach, it can reach too. For request-scoped
|
|
63
63
|
* data access use `getUser(c)` and `getDriver(c)`, which carry the caller's
|
|
64
|
-
* identity
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* identity, and `getSql(c)` for SQL the SDK cannot express, run as the caller
|
|
65
|
+
* under the same policies. `rebase.sql()` is the real bypass — owner
|
|
66
|
+
* connection, no policies, and the one accessor that is Node-only. (`rebase`
|
|
67
|
+
* also exposes auth, storage, email.)
|
|
67
68
|
*
|
|
68
69
|
* Two habits worth keeping from the start, because both are free here and
|
|
69
70
|
* expensive to retrofit later:
|