@protobase/cli 0.131.0 → 0.132.0
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/cli/package.js +1 -1
- package/dist/config/project-modules.js +5 -2
- package/dist/config/read-only-queries.js +3 -3
- package/dist/dev/entry.js +1 -1
- package/dist/migration/migration-project.js +4 -1
- package/dist/serve/startup-checks.js +1 -1
- package/package.json +8 -8
- package/skills/protobase/references/features/build-and-run.md +1 -0
- package/skills/protobase/references/guides/deploy.md +49 -1
- package/skills/protobase/references/reference/assistant.md +1 -1
- package/skills/protobase/references/reference/cli.md +2 -2
- package/skills/protobase/references/reference/jobs.md +1 -1
- package/skills/protobase/references/reference/mcp.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -30,7 +30,7 @@ const builtModules = (project) => neededModules({
|
|
|
30
30
|
realtime: project.realtime,
|
|
31
31
|
events: project.events,
|
|
32
32
|
userTables: project.userTables,
|
|
33
|
-
readOnlyQueries: readOnlyQueriesOn(project.options
|
|
33
|
+
readOnlyQueries: readOnlyQueriesOn(project.options ?? {}, process.env)
|
|
34
34
|
});
|
|
35
35
|
/** The model the app `project` reads of its database's record of migrations (`runtimeModel`). */
|
|
36
36
|
const builtRuntimeModel = (project) => runtimeModel(project.auth, builtModules(project));
|
|
@@ -57,7 +57,10 @@ const configModules = async (config) => {
|
|
|
57
57
|
realtime: config.realtime,
|
|
58
58
|
events: config.events,
|
|
59
59
|
userTables: userTablesOn(config),
|
|
60
|
-
readOnlyQueries: readOnlyQueriesOn(
|
|
60
|
+
readOnlyQueries: readOnlyQueriesOn({
|
|
61
|
+
assistant: config.assistant,
|
|
62
|
+
mcp: config.mcpEndpoint
|
|
63
|
+
}, process.env)
|
|
61
64
|
});
|
|
62
65
|
};
|
|
63
66
|
//#endregion
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { assistantSettings } from "@protobase/server";
|
|
2
2
|
//#region src/config/read-only-queries.ts
|
|
3
3
|
/**
|
|
4
|
-
* Whether the built-in assistant
|
|
5
|
-
* role of their own, which the query module makes.
|
|
4
|
+
* Whether read-only queries run: those of the built-in assistant, with its key set in `env` or the options, or of the
|
|
5
|
+
* MCP endpoint's `sql`. They run as a role of their own, which the query module makes.
|
|
6
6
|
*/
|
|
7
|
-
const readOnlyQueriesOn = (assistant, env) => assistantSettings(assistant, env)?.kind === "built-in";
|
|
7
|
+
const readOnlyQueriesOn = ({ assistant, mcp }, env) => assistantSettings(assistant, env)?.kind === "built-in" || mcp !== false && mcp?.sql === true;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { readOnlyQueriesOn };
|
package/dist/dev/entry.js
CHANGED
|
@@ -38,7 +38,7 @@ if (store.__protobaseRecordChecked !== modelHash(model)) {
|
|
|
38
38
|
}
|
|
39
39
|
await project.auth?.pinnedOrganization();
|
|
40
40
|
if (project.auth) await checkResourcesOutsideAuthStore(db, resources.map((resource) => resource.toModel()), project.auth);
|
|
41
|
-
if (readOnlyQueriesOn(project.options
|
|
41
|
+
if (readOnlyQueriesOn(project.options ?? {}, process.env)) await checkQueryRoleSafety(db, project.auth ? authStoreTables(project.auth) : {
|
|
42
42
|
tables: [],
|
|
43
43
|
schemas: []
|
|
44
44
|
});
|
|
@@ -42,7 +42,10 @@ const migrationProject = async (config, url) => {
|
|
|
42
42
|
realtime: config.realtime,
|
|
43
43
|
events: config.events,
|
|
44
44
|
userTables: userTablesOn(config),
|
|
45
|
-
readOnlyQueries: readOnlyQueriesOn(
|
|
45
|
+
readOnlyQueries: readOnlyQueriesOn({
|
|
46
|
+
assistant: config.assistant,
|
|
47
|
+
mcp: config.mcpEndpoint
|
|
48
|
+
}, process.env)
|
|
46
49
|
};
|
|
47
50
|
return {
|
|
48
51
|
models,
|
|
@@ -18,7 +18,7 @@ const checkStartup = async (project, db) => {
|
|
|
18
18
|
await checkMigrationRecord(db, builtRuntimeModel(project), protobaseVersion);
|
|
19
19
|
await project.auth?.pinnedOrganization();
|
|
20
20
|
if (project.auth) await checkResourcesOutsideAuthStore(db, models, project.auth);
|
|
21
|
-
if (readOnlyQueriesOn(project.options
|
|
21
|
+
if (readOnlyQueriesOn(project.options ?? {}, process.env)) await checkQueryRoleSafety(db, project.auth ? authStoreTables(project.auth) : {
|
|
22
22
|
tables: [],
|
|
23
23
|
schemas: []
|
|
24
24
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.132.0",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.132.0",
|
|
47
|
+
"@protobase/layout": "0.132.0",
|
|
48
|
+
"@protobase/query": "0.132.0",
|
|
49
|
+
"@protobase/schema": "0.132.0",
|
|
50
|
+
"@protobase/server": "0.132.0",
|
|
51
|
+
"@protobase/ui": "0.132.0",
|
|
52
|
+
"@protobase/workflows": "0.132.0",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -32,6 +32,7 @@ Develop, build and run an app, on servers, in containers and on phones.
|
|
|
32
32
|
- [Self-hosted image](../guides/deploy.md#a-self-hosted-image): One image with the app inside that serves, migrates and creates the first admin.
|
|
33
33
|
- [Protobase Cloud deploys](../guides/deploy.md#protobase-cloud): A push to the app's GitHub branch builds it, migrates and checks its database in one transaction, and switches to the new version once it answers its health check.
|
|
34
34
|
- [Deploy checks in CI](../guides/deploy.md#check-a-change-before-it-merges): One step in an app's GitHub workflow runs the checks a Protobase Cloud deploy runs, the server's startup checks included, on a fresh Postgres of its own, so a change that would not deploy or start fails before it merges.
|
|
35
|
+
- [The version before in CI](../guides/deploy.md#test-the-version-that-serves-on-the-new-schema) (beta): A workflow to copy into an app runs the tests of the version that serves now on a database with a branch's migrations applied, so a migration that takes what that version reads fails before it deploys.
|
|
35
36
|
- [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, also on your own iPhone, with sign-in, and builds signed store releases from a section in its config. Your app shows its own home-screen icon on iOS and Android, generated from one image you name in your config. It can open on a splash screen of its own, an image on a colour, in light and dark mode.
|
|
36
37
|
- [Files from the phone](../guides/mobile-app.md#files-from-the-phone) (beta): In the iOS and Android app, Import and file fields open the phone's file picker, offering Excel, CSV and JSON files from the device and its cloud drives.
|
|
37
38
|
- [Mobile releases](../reference/cli.md#mobile-releases) (in development): The server offers the mobile app a newer copy of its files, signed, and any host that serves bundles can offer the same from the bundle's files without running its config.
|
|
@@ -46,7 +46,55 @@ The server reads the record once at startup, with the model it builds from the c
|
|
|
46
46
|
The database is behind Protobase 0.128.0, so the server will not start: the auth store's passkeys module is at step 1 (passkeys), and this version needs step 2 (rp_id_index). To bring the database up to 0.128.0, run `protobase migrate --plan` to see the migrations it will apply, then `protobase migrate`. Or run Protobase 0.127.5, the version the database matches.
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
It refuses as well on a database ahead of it by a migration that is not additive after the newest one recording the model it reads, saying that rolling back to it is blocked and naming the version the database matches, while a unique index of an `.after.sql` is still building, and on a database that records no migration while the app reads the sign-in store or a schema module, such as one migrated before this record: `protobase auth migration` then writes the file that records the store, and [`protobase migration baseline`](../reference/cli.md#migration) the one that records a schema an earlier version's migration made. An unfinished plain index does not keep it from starting. The server never migrates the database itself, and never turns a feature off because its tables are missing. Besides the record, with the built-in assistant it checks what the database has given the [query role](../reference/assistant.md#the-built-in-backend), which a migration cannot promise. <gap>A migration that breaks older code without changing the model the record holds, such as a hand-written rename of a resource's column, cannot stop the version before from starting because recording the app's own release in `migrations.history` is not implemented.</gap>
|
|
49
|
+
It refuses as well on a database ahead of it by a migration that is not additive after the newest one recording the model it reads, saying that rolling back to it is blocked and naming the version the database matches, while a unique index of an `.after.sql` is still building, and on a database that records no migration while the app reads the sign-in store or a schema module, such as one migrated before this record: `protobase auth migration` then writes the file that records the store, and [`protobase migration baseline`](../reference/cli.md#migration) the one that records a schema an earlier version's migration made. An unfinished plain index does not keep it from starting. The server never migrates the database itself, and never turns a feature off because its tables are missing. Besides the record, with the built-in assistant it checks what the database has given the [query role](../reference/assistant.md#the-built-in-backend), which a migration cannot promise. <gap>A migration that breaks older code without changing the model the record holds, such as a hand-written rename of a resource's column, cannot stop the version before from starting because recording the app's own release in `migrations.history` is not implemented.</gap>
|
|
50
|
+
|
|
51
|
+
### Test the version that serves on the new schema
|
|
52
|
+
|
|
53
|
+
:::caution[Beta]
|
|
54
|
+
<gap>The workflow cannot find the version that serves by itself because recording the app's deployed release is not implemented.</gap>
|
|
55
|
+
:::
|
|
56
|
+
|
|
57
|
+
While a deploy migrates, the version that serves now keeps running on the new schema until the new one takes over. This workflow, as `.github/workflows/older-code.yml`, applies a branch's migrations to an empty Postgres 18 and runs the tests of the version that serves now, checked out with its own packages, against that database through `DATABASE_URL`. A failing test names what the version before needs and the branch's migrations take, such as a column they drop. It checks what the app's tests read from the database, so it proves as much as those tests open. Run it from the Actions tab, giving the tag, branch or commit that serves; add `pull_request:` under `on:` to run it on every pull request, against the branch it merges into. A migration marked `-- protobase:breaks-older-code` is expected to fail it, since the version before refuses to start on it, but it does so only through a test that starts that version's server or reads what the migration changed: tests that do neither still pass.
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
name: older-code
|
|
61
|
+
on:
|
|
62
|
+
workflow_dispatch:
|
|
63
|
+
inputs:
|
|
64
|
+
previous:
|
|
65
|
+
description: The tag, branch or commit that serves now
|
|
66
|
+
default: main
|
|
67
|
+
jobs:
|
|
68
|
+
older-code:
|
|
69
|
+
runs-on: ubuntu-latest
|
|
70
|
+
services:
|
|
71
|
+
postgres:
|
|
72
|
+
image: postgres:18
|
|
73
|
+
env:
|
|
74
|
+
POSTGRES_USER: app
|
|
75
|
+
POSTGRES_PASSWORD: app
|
|
76
|
+
POSTGRES_DB: app
|
|
77
|
+
ports:
|
|
78
|
+
- 5432:5432
|
|
79
|
+
options: --health-cmd "pg_isready -U app -d app" --health-interval 2s --health-retries 30
|
|
80
|
+
env:
|
|
81
|
+
DATABASE_URL: postgres://app:app@localhost:5432/app
|
|
82
|
+
PREVIOUS: ${{ inputs.previous || github.base_ref || 'main' }}
|
|
83
|
+
steps:
|
|
84
|
+
- uses: actions/checkout@v4
|
|
85
|
+
with:
|
|
86
|
+
fetch-depth: 0
|
|
87
|
+
- uses: oven-sh/setup-bun@v2
|
|
88
|
+
# This branch's migrations, the app's and the auth schema's, on an empty database.
|
|
89
|
+
- run: bun install --frozen-lockfile
|
|
90
|
+
- run: bun run db:migrate
|
|
91
|
+
# The version that serves now, with its own packages, and its tests on that database.
|
|
92
|
+
- run: |
|
|
93
|
+
commit=$(git rev-parse --verify --quiet "origin/$PREVIOUS^{commit}" || git rev-parse --verify "$PREVIOUS^{commit}")
|
|
94
|
+
git worktree add --detach "$RUNNER_TEMP/previous" "$commit"
|
|
95
|
+
- working-directory: ${{ runner.temp }}/previous
|
|
96
|
+
run: bun install --frozen-lockfile && bun run test
|
|
97
|
+
```
|
|
50
98
|
|
|
51
99
|
## Images
|
|
52
100
|
|
|
@@ -66,7 +66,7 @@ It lives at `/api/assistant` on the app's own origin and answers with the user's
|
|
|
66
66
|
|
|
67
67
|
Both run **outside Protobase's access rules and tenant scoping**: whoever has the `admin` or `ai` role can read every resource's table, and with approval change everything the app's database role can, since `propose_write_query` still runs as that role. Give the app a database role without superuser rights, and those roles only to people who may see all of the data.
|
|
68
68
|
|
|
69
|
-
Making the query role needs `CREATEROLE` once, for the role that applies the migrations; that role becomes a member of it and may run the function. The query role bypasses row-level security only when the migrating role may grant that, a superuser or, on Postgres 16 and later, a role with `BYPASSRLS`; otherwise it reads what the tables' policies give it. When the app serves as another database role than the one that migrates, grant that role `usage on schema query` and `execute on function query.run_read_only(text, integer)`. `protobase migration` writes the role
|
|
69
|
+
Making the query role needs `CREATEROLE` once, for the role that applies the migrations; that role becomes a member of it and may run the function. The query role bypasses row-level security only when the migrating role may grant that, a superuser or, on Postgres 16 and later, a role with `BYPASSRLS`; otherwise it reads what the tables' policies give it. When the app serves as another database role than the one that migrates, grant that role `usage on schema query` and `execute on function query.run_read_only(text, integer)`. `protobase migration` writes the role when it finds the built-in assistant's key, `PROTOBASE_ASSISTANT_API_KEY` in the `.env` it reads or `assistant.apiKey` of the config, so run it with the key set even when only production has the real one, or when [`mcpEndpoint.sql`](mcp.md#sql-for-admins) is on, whose `run_read_only_query` runs as the same role. The server does not start while the [record of migrations](../guides/deploy.md#the-record-of-migrations) lacks the role, its function or a resource's grants, while the role can read an auth table, or while it may call a `SECURITY DEFINER` function, other than a trigger function, whose owner can read one: the statement would read the auth store through it, so revoke `execute` on such a function from `PUBLIC`, or keep it in a schema without a resource. Adding a resource writes its grants into the next migration, and removing one takes them back.
|
|
70
70
|
|
|
71
71
|
### The app's own tools
|
|
72
72
|
|
|
@@ -681,9 +681,9 @@ Writes what the config and this version of Protobase need beyond the project's `
|
|
|
681
681
|
|
|
682
682
|
A sign-in module the config turns off is [kept](auth.md#turning-a-module-off): on a terminal it asks what becomes of its tables, keep, archive or delete, keep being the default, and without one it needs `--off`. Archive and delete keep it as keep does until [`contract`](#signing-off-an-update) signs the update off. A kept module turned on again goes on from its step; with `DATABASE_URL` set and rows in its tables, it asks on a terminal whether to bring them back, and needs `--force` without one, and the file it writes then applies with `protobase migrate --force`.
|
|
683
683
|
|
|
684
|
-
The snapshot describes the schema the project's migrations make: the sign-in store as the runtime reads it, each module that is on with its tables, columns and indexes under the names the config gives them, its last step, and whether every table whose rows belong to an organization has the column that names it, with `modelHash`, the SHA-256 of exactly that; what the migrations decided, the file it ends at with its id, its `format` and the version of Protobase that wrote it, the modules kept or archived, whether organizations were ever on and the default organization, and in `external` the store's relations Protobase did not make, such as the user view of [`users.keyTable`](auth.md#a-view-over-another-systems-users), which no step alters; and `physical`, every schema, table, column and index name the store has. Its `model.modules` holds each built-in schema, each a module with numbered steps, such as the [jobs schema](jobs.md#the-jobs-schema) (`jobs`), the [change capture](events.md#migrations-and-startup) (`changes`) and its [history](history.md#the-table) and [notices](live.md#the-table) tables (`history`, `notices`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks` (`webhooks`) and their delivery log with `deliveryLog` (`webhook_delivery_log`), the [workflows, versions and runs](workflows.md#turning-them-on) of `workflows` (`workflows`) with their storage configurations and custom steps while those are on (`workflow_storage`, `workflow_custom_steps`), the [devices and history tables](notifications.md#table-names) of `notifications` (`notification_devices`, `notification_history`), each unless a store of the app's own replaces it, the [comments table](comments.md#the-table) (`comments`), the table of the bounces and complaints of [`mailFeedback`](email.md#bounces-and-complaints) (`mail_feedback`), written before the change capture whose triggers capture its events, and the table of who unsubscribed from bulk mail of [`unsubscribe`](email.md#unsubscribe) (`unsubscribes`), and the [query role](assistant.md#the-built-in-backend) of
|
|
684
|
+
The snapshot describes the schema the project's migrations make: the sign-in store as the runtime reads it, each module that is on with its tables, columns and indexes under the names the config gives them, its last step, and whether every table whose rows belong to an organization has the column that names it, with `modelHash`, the SHA-256 of exactly that; what the migrations decided, the file it ends at with its id, its `format` and the version of Protobase that wrote it, the modules kept or archived, whether organizations were ever on and the default organization, and in `external` the store's relations Protobase did not make, such as the user view of [`users.keyTable`](auth.md#a-view-over-another-systems-users), which no step alters; and `physical`, every schema, table, column and index name the store has. Its `model.modules` holds each built-in schema, each a module with numbered steps, such as the [jobs schema](jobs.md#the-jobs-schema) (`jobs`), the [change capture](events.md#migrations-and-startup) (`changes`) and its [history](history.md#the-table) and [notices](live.md#the-table) tables (`history`, `notices`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks` (`webhooks`) and their delivery log with `deliveryLog` (`webhook_delivery_log`), the [workflows, versions and runs](workflows.md#turning-them-on) of `workflows` (`workflows`) with their storage configurations and custom steps while those are on (`workflow_storage`, `workflow_custom_steps`), the [devices and history tables](notifications.md#table-names) of `notifications` (`notification_devices`, `notification_history`), each unless a store of the app's own replaces it, the [comments table](comments.md#the-table) (`comments`), the table of the bounces and complaints of [`mailFeedback`](email.md#bounces-and-complaints) (`mail_feedback`), written before the change capture whose triggers capture its events, and the table of who unsubscribed from bulk mail of [`unsubscribe`](email.md#unsubscribe) (`unsubscribes`), and the [query role](assistant.md#the-built-in-backend) of read-only queries (`query`), each at its last step and the version of the functions over it, with the names it takes from the config, such as the schema `events`, `webhooks.schema` or `workflows.schema` names, the notifications tables' names and columns and the users table they point at, and the triggers of each captured resource at a digest of their statements; it keeps one the config no longer needs as the migrations left it. That part of the file comes from the snapshot alone too, after the store's: the module's steps after its last one, then its functions where the snapshot has another version, then the triggers of each resource whose statements differ, such as one added or one whose field became sensitive; a file that replaces them with a version the code before does not run on says `-- protobase:breaks-older-code`. A name the config changes, such as `events.schema`, `webhooks.schema` or a notifications table's column, is refused, since Protobase does not write renames; so is turning sign-in on under notifications tables made without it, whose user column then points at no users table. With `DATABASE_URL` set, it refuses to write a module from its first step onto a database that has it already, as made by an earlier version's migration, and names `baseline`. The sign-in store's part of the file comes from the snapshot alone, without a database: the [steps](auth.md#migrations) after each module's last one, those a newer Protobase ships included, each followed by its row in `auth_steps`; a snapshot whose store has no `auth_steps` yet, as a Protobase before 0.130 wrote it, is refused, naming 0.130 as the release to migrate through first. Each runs only while `auth_steps` lacks it, so a database that has it already, such as one [`migrate-release`](#release-steps) brought to a newer release, skips it. With `DATABASE_URL` set, the checks of those steps run first against the database's rows, in a read-only transaction, and refuse as the step would, such as on two accounts with one provider and account id. A name the store has that the config changes, such as a table renamed in [`auth.tables`](auth.md#table-and-column-names), is refused with what changed, since Protobase does not write renames: write it by hand with `--custom` and `--record-config`. A store a newer Protobase describes otherwise with no step to apply, such as personal access tokens now holding an organization's rows, gets a file that records it anew and changes nothing in the database. A step whose work cannot run in a transaction leaves it to the file's `.after.sql`, such as the batches that give each personal access token the [default organization](auth.md#the-default-organization) when organizations turn on, and the index it builds concurrently. With organizations on or ever on, the file needs `organizations.default` in the config, and turning them on the first time over a store that may hold users needs `organizations.existingUsersRole`; it refuses without them, as `migration check` reports.
|
|
685
685
|
|
|
686
|
-
The rest of the file is what the config still needs of the database, compared with it, under its own comment and named in the file name as in brackets: with [`userTables`](user-tables.md#the-switch), the delete of the definitions of tables that resources in code [own now](user-tables.md#taking-a-table-over-as-code) (`owned_definitions`). It is compared only with `DATABASE_URL` set, against the database with the project's migrations applied, and the command says so without it. The jobs schema is written when the config has jobs, `webhooks`, `workflows`, `notifications` or `mailFeedback`, or uses the relay, or a resource has events, history, comments or an [AI field](ai.md) or is a [time rollup](data-config.md#keeping-it-up-to-date). The rollups and formulas module is written when a resource has [rollup or formula fields](data-config.md#rollups-and-formulas) or is a [time rollup](data-config.md#time-rollups) (`computed`): the `rollups` schema, then per field and rollup the columns, the functions and triggers that keep the rollups, and the tables, indexes and refresh functions of time rollups; a changed one is dropped and made again, and what sets a rollup's values or fills a time rollup goes in the file's `.after.sql`, which runs once its transaction commits. The `derived` schema is written when a resource has [derived values](derived.md), with each value declared and its fill enqueued, and a value no longer declared loses its state. The schemas of user tables (`user_tables`) are written with [`userTables`](user-tables.md#the-switch); the tables users add inside them are data, made while the app serves. The change capture is written when a resource has events, history, live updates or derived values, another's derived values or live updates read it, or `mailFeedback` is on; its history table with history, and its notices table with live updates. The webhooks, workflows, notifications, [status](status.md), [calls](calls.md), comments, mail feedback and unsubscribe modules, the `realtime_relay` schema of [`realtime: { processes: 'many' }`](supabase-realtime.md#several-processes) and the `channels` schema of [`realtime: { sqlSends: true }`](channels.md#from-sql) are written while the config turns their feature on, and none of them while it is off; turning a feature off later leaves its tables as they are. Calls write the notices table too, which rings reach open pages through. The [relay](realtime-relay.md#sessions) module, the trigger that ends a deleted session's sockets and `realtime.members` with the triggers that keep it from channel records that list their members, is written with `realtime.relay`, and for an app with sign-in and a live resource whose conversation page has `members`, after the auth store's steps, since its trigger is on the sessions table. The query module, the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as with the function they run through, is written last when the command finds the built-in assistant's key (`query`), with the role's grants on each resource's table but those of the auth store: a resource added writes only its grants, and one removed takes them back. It reads the config merged with those of `--extend` as `dev` merges them, and the `.env` nearest the current directory.
|
|
686
|
+
The rest of the file is what the config still needs of the database, compared with it, under its own comment and named in the file name as in brackets: with [`userTables`](user-tables.md#the-switch), the delete of the definitions of tables that resources in code [own now](user-tables.md#taking-a-table-over-as-code) (`owned_definitions`). It is compared only with `DATABASE_URL` set, against the database with the project's migrations applied, and the command says so without it. The jobs schema is written when the config has jobs, `webhooks`, `workflows`, `notifications` or `mailFeedback`, or uses the relay, or a resource has events, history, comments or an [AI field](ai.md) or is a [time rollup](data-config.md#keeping-it-up-to-date). The rollups and formulas module is written when a resource has [rollup or formula fields](data-config.md#rollups-and-formulas) or is a [time rollup](data-config.md#time-rollups) (`computed`): the `rollups` schema, then per field and rollup the columns, the functions and triggers that keep the rollups, and the tables, indexes and refresh functions of time rollups; a changed one is dropped and made again, and what sets a rollup's values or fills a time rollup goes in the file's `.after.sql`, which runs once its transaction commits. The `derived` schema is written when a resource has [derived values](derived.md), with each value declared and its fill enqueued, and a value no longer declared loses its state. The schemas of user tables (`user_tables`) are written with [`userTables`](user-tables.md#the-switch); the tables users add inside them are data, made while the app serves. The change capture is written when a resource has events, history, live updates or derived values, another's derived values or live updates read it, or `mailFeedback` is on; its history table with history, and its notices table with live updates. The webhooks, workflows, notifications, [status](status.md), [calls](calls.md), comments, mail feedback and unsubscribe modules, the `realtime_relay` schema of [`realtime: { processes: 'many' }`](supabase-realtime.md#several-processes) and the `channels` schema of [`realtime: { sqlSends: true }`](channels.md#from-sql) are written while the config turns their feature on, and none of them while it is off; turning a feature off later leaves its tables as they are. Calls write the notices table too, which rings reach open pages through. The [relay](realtime-relay.md#sessions) module, the trigger that ends a deleted session's sockets and `realtime.members` with the triggers that keep it from channel records that list their members, is written with `realtime.relay`, and for an app with sign-in and a live resource whose conversation page has `members`, after the auth store's steps, since its trigger is on the sessions table. The query module, the role the [assistant's read-only queries](assistant.md#the-built-in-backend) and those of [`mcpEndpoint.sql`](mcp.md#sql-for-admins) run as with the function they run through, is written last when the command finds the built-in assistant's key or `mcpEndpoint.sql` is on (`query`), with the role's grants on each resource's table but those of the auth store: a resource added writes only its grants, and one removed takes them back. It reads the config merged with those of `--extend` as `dev` merges them, and the `.env` nearest the current directory.
|
|
687
687
|
|
|
688
688
|
#### Changes that break older code
|
|
689
689
|
|
|
@@ -114,7 +114,7 @@ select jobs.enqueue('send-invoice', '{"invoiceId": 7}', run_at => now() + interv
|
|
|
114
114
|
select jobs.enqueue('sync-customer', '{"customerId": 3, "fields": ["email"]}', group_key => 'customer:3');
|
|
115
115
|
```
|
|
116
116
|
|
|
117
|
-
`jobs.enqueue(job_name, payload, run_at, key, group_key, priority)` returns the job's id. The job works in no organization
|
|
117
|
+
`jobs.enqueue(job_name, payload, run_at, key, group_key, priority)` returns the job's id. The job works in no organization, whatever its payload holds: the runtime keeps a job's organization under a top-level `~organization` key beside the payload, and a payload with a `~organization` key of its own reaches the job whole, as payload. A `key` dedupes as `mode: 'dedupe'` does. The job takes its retry settings from its definition, as the workers last saw it; a job no worker has started yet gets pg-boss's defaults until one does.
|
|
118
118
|
|
|
119
119
|
## Mail
|
|
120
120
|
|
|
@@ -147,7 +147,7 @@ A definition the save check refuses comes back as `{ "error": "invalid-workflow"
|
|
|
147
147
|
export default defineConfig({ auth: { mcp: true }, mcpEndpoint: { sql: true } })
|
|
148
148
|
```
|
|
149
149
|
|
|
150
|
-
It runs one `SELECT` in a read-only transaction
|
|
150
|
+
It runs one `SELECT` in a read-only transaction as the query role, `<database>_query`, **outside the access rules and tenant scoping**: whoever has one of those roles reads every resource's table through it. Give those roles only to people who may see all of the data. [`protobase migration`](cli.md#migration) writes that role with `mcpEndpoint.sql` on, as it does for the built-in assistant, and the server does not start while the [record of migrations](../guides/deploy.md#the-record-of-migrations) lacks it; the assistant's page says [what it may read](assistant.md#the-built-in-backend).
|
|
151
151
|
|
|
152
152
|
### Writes
|
|
153
153
|
|