@protobase/cli 0.54.1 → 0.54.3
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/dev/api-process.js +3 -1
- package/dist/dev/api-support.d.ts +2 -1
- package/dist/dev/api-support.js +2 -1
- package/dist/dev/dev-prune.d.ts +5 -0
- package/dist/dev/dev-prune.js +18 -0
- package/dist/dev/entry.js +2 -0
- package/dist/serve/lifecycle.js +3 -1
- package/dist/supabase/report-api-keys.js +15 -0
- package/dist/supabase/report.js +2 -0
- package/package.json +7 -7
- package/skills/protobase/references/reference/cli.md +1 -1
- package/skills/protobase/references/reference/supabase-realtime.md +2 -2
- package/skills/supabase-move/SKILL.md +4 -0
package/dist/cli/package.js
CHANGED
package/dist/dev/api-process.js
CHANGED
|
@@ -46,7 +46,9 @@ const listen = (server) => new Promise((resolve, reject) => {
|
|
|
46
46
|
const stop = async () => {
|
|
47
47
|
server?.close();
|
|
48
48
|
server?.closeAllConnections();
|
|
49
|
-
|
|
49
|
+
const devSupport = await vite.ssrLoadModule(support);
|
|
50
|
+
await devSupport.stopDevJobs();
|
|
51
|
+
await devSupport.stopDevRealtimePrune();
|
|
50
52
|
await vite.close();
|
|
51
53
|
process.exit(process.exitCode ?? 0);
|
|
52
54
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { apiWebSocketServer } from "../project/api-websocket-server.js";
|
|
2
2
|
import { stopDevJobs } from "./dev-jobs.js";
|
|
3
|
-
|
|
3
|
+
import { stopDevRealtimePrune } from "./dev-prune.js";
|
|
4
|
+
export { apiWebSocketServer, stopDevJobs, stopDevRealtimePrune };
|
package/dist/dev/api-support.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { stopDevJobs } from "./dev-jobs.js";
|
|
2
|
+
import { stopDevRealtimePrune } from "./dev-prune.js";
|
|
2
3
|
import { apiWebSocketServer } from "../project/api-websocket-server.js";
|
|
3
|
-
export { apiWebSocketServer, stopDevJobs };
|
|
4
|
+
export { apiWebSocketServer, stopDevJobs, stopDevRealtimePrune };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/dev/dev-prune.ts
|
|
2
|
+
const store = globalThis;
|
|
3
|
+
/**
|
|
4
|
+
* Prunes the realtime tables in the dev server, from its first load on; `realtime.processes` changed later is the
|
|
5
|
+
* prune's from the next start.
|
|
6
|
+
*/
|
|
7
|
+
const devRealtimePrune = (admin) => {
|
|
8
|
+
if (store.__protobaseRealtimePrune) return;
|
|
9
|
+
store.__protobaseRealtimePrune = admin.startRealtimePrune();
|
|
10
|
+
};
|
|
11
|
+
/** Stops the prune, after one in progress, when the dev server closes. */
|
|
12
|
+
const stopDevRealtimePrune = async () => {
|
|
13
|
+
const prune = store.__protobaseRealtimePrune;
|
|
14
|
+
delete store.__protobaseRealtimePrune;
|
|
15
|
+
await prune?.stop();
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { devRealtimePrune, stopDevRealtimePrune };
|
package/dist/dev/entry.js
CHANGED
|
@@ -3,6 +3,7 @@ import { projectIcons } from "../build/app-icons.js";
|
|
|
3
3
|
import { projectErrorReporter } from "../project/error-reporter.js";
|
|
4
4
|
import { projectAdmin } from "../project/project-admin.js";
|
|
5
5
|
import { devJobs } from "./dev-jobs.js";
|
|
6
|
+
import { devRealtimePrune } from "./dev-prune.js";
|
|
6
7
|
import { devDatabase, loadDevConfig } from "./project.js";
|
|
7
8
|
import { withDevServiceWorker } from "./service-worker-route.js";
|
|
8
9
|
import { setMissing, supabaseEnv } from "./supabase-env.js";
|
|
@@ -49,6 +50,7 @@ const ui = {
|
|
|
49
50
|
};
|
|
50
51
|
const { admin, jobs } = projectAdmin(project, db, ui, reporter, upgradeWebSocket);
|
|
51
52
|
await devJobs(db, jobs, project.mailer);
|
|
53
|
+
devRealtimePrune(admin);
|
|
52
54
|
var entry_default = withDevServiceWorker(new Hono(), Boolean(project.notifications)).route("/", admin);
|
|
53
55
|
/** Whether the auth store has a user yet, for the banner's sign-in line; undefined without one. */
|
|
54
56
|
const anyUsers = () => project.auth ? hasUsers(project.auth) : Promise.resolve(void 0);
|
package/dist/serve/lifecycle.js
CHANGED
|
@@ -83,11 +83,12 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
83
83
|
server,
|
|
84
84
|
sockets,
|
|
85
85
|
jobs,
|
|
86
|
+
prune: admin.startRealtimePrune(),
|
|
86
87
|
resources,
|
|
87
88
|
files: project.files
|
|
88
89
|
};
|
|
89
90
|
};
|
|
90
|
-
const { server, sockets, jobs, resources, files } = await startJobsAndListen().catch(async (error) => {
|
|
91
|
+
const { server, sockets, jobs, prune, resources, files } = await startJobsAndListen().catch(async (error) => {
|
|
91
92
|
await db.destroy();
|
|
92
93
|
throw error;
|
|
93
94
|
});
|
|
@@ -103,6 +104,7 @@ const startServe = async ({ config, env, openDb = (url) => openAppDatabase(pg, u
|
|
|
103
104
|
await closed;
|
|
104
105
|
await backgroundSettled();
|
|
105
106
|
await timer?.stop();
|
|
107
|
+
await prune.stop();
|
|
106
108
|
await jobs?.stop();
|
|
107
109
|
await db.destroy();
|
|
108
110
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { apiKeyVariables } from "@protobase/server";
|
|
2
|
+
//#region src/supabase/report-api-keys.ts
|
|
3
|
+
/** What the app needs before supabase-js's clients reach `/api/sb`, in the words of the Supabase client API reference. */
|
|
4
|
+
const apiKeysSection = () => `## API keys
|
|
5
|
+
|
|
6
|
+
The app serves supabase-js's \`/api/sb/rest/v1\`, \`/api/sb/realtime/v1\` and \`/api/sb/storage/v1\` only with API keys, and admits calls to \`/api/sb/functions/v1\` by them. The keys are \`apiKeys\` in \`protobase.config.ts\`, \`{ publishable_key, secret_key }\`, or else \`${apiKeyVariables.publishable_key}\` and \`${apiKeyVariables.secret_key}\` in the app's environment. Without either, or with \`apiKeys: false\`, the app serves none of them. The publishable key takes the place of the Supabase project's anon or publishable key and is safe in a browser; the secret key takes the place of its service_role or secret key and stays on servers.
|
|
7
|
+
|
|
8
|
+
Then point each client at the app's \`/api/sb\` with the publishable key, in place of the project's URL and anon key:
|
|
9
|
+
|
|
10
|
+
\`\`\`ts
|
|
11
|
+
const supabase = createClient('https://<the app's origin>/api/sb', '<the publishable key>')
|
|
12
|
+
\`\`\`
|
|
13
|
+
`;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { apiKeysSection };
|
package/dist/supabase/report.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { providerFate } from "./identity-providers.js";
|
|
2
2
|
import { convertedCronJobs } from "./cron-plan.js";
|
|
3
|
+
import { apiKeysSection } from "./report-api-keys.js";
|
|
3
4
|
//#region src/supabase/report.ts
|
|
4
5
|
/** Protobase Cloud's Starter plan holds this much data; the import reports a larger database, it does not refuse it. */
|
|
5
6
|
const starterBytes = 524288e3;
|
|
@@ -72,6 +73,7 @@ const importReport = (manifest, doctor, jobsWired, live, providers) => [
|
|
|
72
73
|
`The imported tables take ${megabytes(manifest.bytes)} in the source database${manifest.bytes > starterBytes ? `, more than the ${megabytes(starterBytes)} of the Starter plan: pick a larger plan` : `, within the ${megabytes(starterBytes)} of the Starter plan`}.\n`,
|
|
73
74
|
`The migration leaves out ${manifest.leftOut} statement${manifest.leftOut === 1 ? "" : "s"} of the dump, as comments: grants to Supabase's own roles and the like.\n`,
|
|
74
75
|
"## Rows loaded\n\nEach count matched the source before the load committed.\n\n| Table | Rows |\n| --- | --- |\n" + manifest.tables.map((table) => `| ${table.schema}.${table.table} | ${table.rows} |`).join("\n") + "\n",
|
|
76
|
+
apiKeysSection(),
|
|
75
77
|
signInSection(providers),
|
|
76
78
|
section("Made again", "A dump cannot carry these. The load made Vault's secrets and pgmq's queues again through each extension's own API, in the same transaction, and scheduled pg_cron's jobs again with `cron.schedule` where the project's database has pg_cron; elsewhere the import made them the app's recurring jobs, on the same schedule. pg_net sends the HTTP triggers' calls from the project's database, Database Webhooks' through the `supabase_functions.http_request` the migration creates.", carried(manifest)),
|
|
77
79
|
...recurringJobs(manifest, jobsWired),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.54.
|
|
3
|
+
"version": "0.54.3",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@better-auth/core": "^1.7.12",
|
|
44
44
|
"@hono/node-server": "^2.1.3",
|
|
45
|
-
"@protobase/config": "0.54.
|
|
46
|
-
"@protobase/layout": "0.54.
|
|
47
|
-
"@protobase/query": "0.54.
|
|
48
|
-
"@protobase/schema": "0.54.
|
|
49
|
-
"@protobase/server": "0.54.
|
|
50
|
-
"@protobase/ui": "0.54.
|
|
45
|
+
"@protobase/config": "0.54.3",
|
|
46
|
+
"@protobase/layout": "0.54.3",
|
|
47
|
+
"@protobase/query": "0.54.3",
|
|
48
|
+
"@protobase/schema": "0.54.3",
|
|
49
|
+
"@protobase/server": "0.54.3",
|
|
50
|
+
"@protobase/ui": "0.54.3",
|
|
51
51
|
"@react-email/render": "^2.1.0",
|
|
52
52
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
53
53
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -540,7 +540,7 @@ Turns a Supabase project's database into the project in the current directory, i
|
|
|
540
540
|
|
|
541
541
|
1. **The first run** takes the Supabase database's connection string, for its `postgres` role (the session pooler's or the direct one; the transaction pooler cannot hold the snapshot the dumps share). It fails unless the database has Supabase's `auth` and `storage` schemas and its `supabase_admin` role, and while `auth.users` has single sign-on (SAML) users, which Supabase opens only through their identity provider and Better Auth would find by email: merge or delete them in Supabase first. It notes the Supabase CLI's `supabase/config.toml`, `supabase/migrations/` and `supabase/functions/` when the checkout has them. It converts `supabase/functions` into the project's `functions/` (see [functions moved from Supabase](../guides/api-functions.md#functions-moved-from-supabase)): `Deno.serve(handler)` and std's `serve(handler)` become `export default defineFunction({ supabase: true }, { fetch: handler })`, an existing default export is wrapped the same way, so each function also answers at `/api/sb/functions/v1/<name>`, `npm:`, `jsr:` and esm.sh imports become bare imports of packages it adds to `package.json`, `Deno.env.get(name)` becomes `process.env[name]`, `EdgeRuntime.waitUntil` becomes `waitUntil` of `@protobase/server`, a function with `verify_jwt = false` in `config.toml` becomes public (`{ public: true, supabase: true }`), and `_shared` and the like are converted beside them. It stops before anything else when `functions/` already has one of their names. It dumps `auth`, `storage` and every schema the app made, schema and data apart, as of one snapshot, leaving out the platform's own migration tables, and writes the schemas as the project's next migration, `NNN_supabase_schema.sql`. It asks the project's database which of the app's extensions its role may create, by trying each in a transaction it rolls back: Postgres alone allows the trusted ones, Supabase's Postgres image all it allowlists, such as pg_net, pgmq and Vault. The migration creates those first, then, where pg_net is among them and the app has Database Webhooks, the `supabase_functions.http_request` function their triggers call, over pg_net; then the dump without what fails there, as comments: grants and default privileges for `dashboard_user`, `supabase_*`, `authenticator` and `postgres`, statements about the `public` schema, Realtime's publication, pgsodium's security labels, the views that decrypt with it and the triggers that encrypt with it, database webhooks without pg_net, functions in plv8, plls or plcoffee where the database has no such language, and a timescaledb hypertable's insert-blocking trigger. It then writes `NNN_supabase_users.sql`, the nullable columns Better Auth needs on `auth.users` (`name`, `email_verified`, `image`, `app_role`, `banned`, `ban_reason`, `ban_expires`) and GoTrue's `'authenticated'` as the default of `role` and `aud`. It writes `NNN_supabase_realtime.sql`, which makes `realtime.messages`, `realtime.topic()`, and Supabase's `realtime.send()` and `realtime.broadcast_changes()`, so the app's triggers and SQL keep [broadcasting from the database](supabase-realtime.md#broadcast-from-the-database), with the source's row security policies on `realtime.messages`, so its [private channels](supabase-realtime.md#private-channels) keep their access; a policy that names only Supabase's own roles is left out as a comment. It points the app at `auth.users`: the `auth` of `protobase.config.ts` gets `users: { table: 'users', columns: { role: 'app_role' }, metadata: 'raw_user_meta_data' }`, `passwordHashes: ['bcrypt']` and `generateUserId: 'uuid'`, or the config gets an `auth` of them when it has none (see [an existing users table](auth.md#an-existing-users-table)). It removes the migrations `protobase auth migration` or `protobase migration` wrote for Protobase's own user table, since `auth.users` replaces it, and stops before writing anything when the project has no `protobase.config.ts`, or one whose `auth` is not an object it can see, or when the project's database has a schema the dump creates already, such as the `auth` schema those migrations made. The project's database needs the roles `anon`, `authenticated` and `service_role` that the dump's grants and policies name; the command makes them when its role may, and otherwise stops, naming them. The data dump goes to `supabase-import/`, which it adds to `.gitignore`, since it holds every row and the users' password hashes. Where the project's database can create Vault, pgmq and pg_cron, `supabase-import/replay.sql` holds what a dump cannot carry: Vault's secrets with their values, read decrypted since only Supabase's key opens their ciphertext, pgmq's queues with their messages, since pgmq owns their tables, and pg_cron's jobs, which live in its own schema.
|
|
542
542
|
2. **Apply the migration** with the project's other migrations, such as `bun run db:migrate`.
|
|
543
|
-
3. **The second run**, without a connection string, loads the data in one transaction, with the app's triggers off so a sign-up trigger on `auth.users` does not run again for users who already have their rows, and fails the transaction unless every table holds the source's number of rows. In the same transaction it makes Vault's secrets and pgmq's queues again through `vault.create_secret`, `pgmq.create` and `pgmq.send`, each message with its headers and the time it becomes visible. Where the project's database has pg_cron, as Supabase's Postgres image does when it serves that database, it schedules pg_cron's jobs again there with `cron.schedule`, run by the importing role, an inactive one inactive. Elsewhere it writes each job of plain SQL as a [recurring job](jobs.md#recurring-jobs) of its own in `jobs/`, of the same name, schedule and `cron.timezone`, that runs its SQL as the app's database role, tried once each time as pg_cron did, and declares it in the `jobs` of `protobase.config.ts` (or writes one); they run once [`migration`](#migration) has added the jobs schema. Recurring jobs wake an app that sleeps, so they run where a host stops an idle app too. A job that calls what the database lacks, such as pg_net's `net.http_*`, `cron` or Vault, an inactive one and a schedule recurring jobs do not take, such as `30 seconds` or `$`, stay in the report, as does a job of another database. It loads only into empty tables, deletes the data dump and the replay, runs [`scaffold`](#scaffold) on the imported tables of the app's schemas (not `auth` or `storage`), giving the tables of the `supabase_realtime` publication [`.live()`](live.md) so [`/api/sb/realtime/v1`](supabase-realtime.md) keeps sending their `postgres_changes` once [`migration`](#migration) has written their capture triggers, writes Better Auth's other tables next to `auth.users` as [`auth migration`](#auth-migration) does (`NNN_auth.sql`), then `NNN_supabase_accounts.sql`, and writes `supabase-import/report.md`: the rows loaded, the imported tables' size against the Starter plan's 500 MB, each sign-in provider's identities, what it made again, the tables it made live, and what needs a person: the pg_cron jobs it could not carry over, each with why, Realtime tables it made no resource of, Vault secrets by name and pgmq queues where the database has no such extension (and partitioned queues), the columns pgsodium encrypts, still holding Supabase's ciphertext, whose values to export decrypted in Supabase before declaring them [`.encrypted()`](data-config.md#encrypted-fields) and running [`encryption apply`](#encryption-apply), the extensions it cannot create, hypertables and plv8, plls or plcoffee functions to convert, triggers that call out over HTTP without pg_net, the converted Edge Functions with the packages to install and the code the conversion left (`deno.land/x` imports, Deno's file, KV and WebSocket APIs, `Supabase.ai`), and the indexes [`doctor`](#doctor) finds missing. `NNN_supabase_accounts.sql` fills the user columns from what Supabase Auth recorded and leaves them empty where it recorded nothing: the name from `raw_user_meta_data`'s `full_name` or `name`, the picture from its `avatar_url` or `picture`, `email_verified` from `email_confirmed_at`, and a ban from `banned_until`, which Better Auth lifts once it has passed. It gives each password of a confirmed address, as Supabase hashed it, a `credential` account (a user who never confirmed theirs signs in by code or resets the password, since GoTrue refused their password sign-in too), and each identity of a social provider an account under Better Auth's name for it (`azure` is `microsoft`, keyed on the `oid` claim; `linkedin_oidc` is `linkedin`, `slack_oidc` is `slack`, `x` is `twitter`), unless its user has an address they never confirmed, since GoTrue refused that sign-in too. Email, phone, anonymous and single sign-on identities and sessions do not carry over. <gap>The import cannot carry over MFA factors because that is not implemented.</gap> <gap>The import cannot carry over passkeys because that is not implemented.</gap>
|
|
543
|
+
3. **The second run**, without a connection string, loads the data in one transaction, with the app's triggers off so a sign-up trigger on `auth.users` does not run again for users who already have their rows, and fails the transaction unless every table holds the source's number of rows. In the same transaction it makes Vault's secrets and pgmq's queues again through `vault.create_secret`, `pgmq.create` and `pgmq.send`, each message with its headers and the time it becomes visible. Where the project's database has pg_cron, as Supabase's Postgres image does when it serves that database, it schedules pg_cron's jobs again there with `cron.schedule`, run by the importing role, an inactive one inactive. Elsewhere it writes each job of plain SQL as a [recurring job](jobs.md#recurring-jobs) of its own in `jobs/`, of the same name, schedule and `cron.timezone`, that runs its SQL as the app's database role, tried once each time as pg_cron did, and declares it in the `jobs` of `protobase.config.ts` (or writes one); they run once [`migration`](#migration) has added the jobs schema. Recurring jobs wake an app that sleeps, so they run where a host stops an idle app too. A job that calls what the database lacks, such as pg_net's `net.http_*`, `cron` or Vault, an inactive one and a schedule recurring jobs do not take, such as `30 seconds` or `$`, stay in the report, as does a job of another database. It loads only into empty tables, deletes the data dump and the replay, runs [`scaffold`](#scaffold) on the imported tables of the app's schemas (not `auth` or `storage`), giving the tables of the `supabase_realtime` publication [`.live()`](live.md) so [`/api/sb/realtime/v1`](supabase-realtime.md) keeps sending their `postgres_changes` once [`migration`](#migration) has written their capture triggers, writes Better Auth's other tables next to `auth.users` as [`auth migration`](#auth-migration) does (`NNN_auth.sql`), then `NNN_supabase_accounts.sql`, and writes `supabase-import/report.md`: the rows loaded, the API keys `/api/sb` needs and the `createClient` change to the app's `/api/sb` and its publishable key, the imported tables' size against the Starter plan's 500 MB, each sign-in provider's identities, what it made again, the tables it made live, and what needs a person: the pg_cron jobs it could not carry over, each with why, Realtime tables it made no resource of, Vault secrets by name and pgmq queues where the database has no such extension (and partitioned queues), the columns pgsodium encrypts, still holding Supabase's ciphertext, whose values to export decrypted in Supabase before declaring them [`.encrypted()`](data-config.md#encrypted-fields) and running [`encryption apply`](#encryption-apply), the extensions it cannot create, hypertables and plv8, plls or plcoffee functions to convert, triggers that call out over HTTP without pg_net, the converted Edge Functions with the packages to install and the code the conversion left (`deno.land/x` imports, Deno's file, KV and WebSocket APIs, `Supabase.ai`), and the indexes [`doctor`](#doctor) finds missing. `NNN_supabase_accounts.sql` fills the user columns from what Supabase Auth recorded and leaves them empty where it recorded nothing: the name from `raw_user_meta_data`'s `full_name` or `name`, the picture from its `avatar_url` or `picture`, `email_verified` from `email_confirmed_at`, and a ban from `banned_until`, which Better Auth lifts once it has passed. It gives each password of a confirmed address, as Supabase hashed it, a `credential` account (a user who never confirmed theirs signs in by code or resets the password, since GoTrue refused their password sign-in too), and each identity of a social provider an account under Better Auth's name for it (`azure` is `microsoft`, keyed on the `oid` claim; `linkedin_oidc` is `linkedin`, `slack_oidc` is `slack`, `x` is `twitter`), unless its user has an address they never confirmed, since GoTrue refused that sign-in too. Email, phone, anonymous and single sign-on identities and sessions do not carry over. <gap>The import cannot carry over MFA factors because that is not implemented.</gap> <gap>The import cannot carry over passkeys because that is not implemented.</gap>
|
|
544
544
|
4. **Apply the migrations** again. Supabase's users then sign in with their own passwords, and with a social provider once it is in the `socialProviders` of the config's `auth`; new users get a UUID in `auth.users`, so the app's triggers there run for them.
|
|
545
545
|
|
|
546
546
|
5. **Storage's files**: with `--storage-url https://<ref>.supabase.co` and the project's secret key in the variable `--storage-key-env` names, `SUPABASE_SERVICE_ROLE_KEY` by default, the second run, or any run after it, copies the bytes of every object in `storage.objects` from the Supabase project's Storage API into the app's [Storage file provider](supabase-storage.md#where-things-are-kept), where [`/api/sb/storage/v1`](supabase-storage.md) serves them, with the type and cache control the rows recorded. It streams each object, checks its byte count against the size Supabase recorded and its MD5 against the ETag where that is one, and deletes a copy that does not match. It first prints each bucket's size and stops when what is left to copy and what the provider holds exceed the provider's `max_bytes`, unless `--yes`. An object that fails does not stop the rest; the run then fails, listing them in `supabase-import/storage.md`, and a rerun copies only what the provider does not hold yet. The key goes only in the requests' headers, never in a file.
|
|
@@ -48,7 +48,7 @@ Limits, near Supabase's Free plan, apply per socket and per topic. A socket send
|
|
|
48
48
|
|
|
49
49
|
### Several processes
|
|
50
50
|
|
|
51
|
-
By default, one process serves the app, and broadcasts and presence go between its channels. When several processes serve it behind one address, set [`realtime: { processes: 'many' }`](config/api.md#realtime) and apply the migration [`protobase migration`](cli.md#migration) writes. Every channel on a topic then hears its broadcasts and presence, whichever process it joined, and so do broadcasts over the REST endpoint and from the database. Private and public channels of a topic stay apart across processes as on one. The processes share them through the `realtime_relay` schema of the app's database: each adds what it sends, and reads what the others sent ten times a second while one of its sockets is open, so a broadcast reaches another process's channels within about 100 ms. A topic's 100 broadcasts a second are counted across all the processes. A process that stops gracefully removes the presence its channels tracked; one that is killed has it removed by the others about 15 seconds after its last heartbeat, and their channels hear the leaves.
|
|
51
|
+
By default, one process serves the app, and broadcasts and presence go between its channels. When several processes serve it behind one address, set [`realtime: { processes: 'many' }`](config/api.md#realtime) and apply the migration [`protobase migration`](cli.md#migration) writes. Every channel on a topic then hears its broadcasts and presence, whichever process it joined, and so do broadcasts over the REST endpoint and from the database. Private and public channels of a topic stay apart across processes as on one. The processes share them through the `realtime_relay` schema of the app's database: each adds what it sends, and reads what the others sent ten times a second while one of its sockets is open, so a broadcast reaches another process's channels within about 100 ms. A topic's 100 broadcasts a second are counted across all the processes. Every 10 minutes, whether or not a socket is open, each process deletes the frames older than a minute and the counts of seconds before it. A process that stops gracefully removes the presence its channels tracked; one that is killed has it removed by the others about 15 seconds after its last heartbeat, and their channels hear the leaves.
|
|
52
52
|
|
|
53
53
|
### Broadcast without a channel
|
|
54
54
|
|
|
@@ -84,7 +84,7 @@ supabase
|
|
|
84
84
|
.subscribe()
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
-
Each call inserts a message into `realtime.messages` in the caller's transaction, as on Supabase, so a transaction rolled back sends nothing. Within a second of its commit, the server takes the message out of the table and sends it to the channels joined on its topic, in the order the transaction sent them, with the message's id in the payload's `id` and in the broadcast's `meta.id`. `broadcast_changes()` sends `{ operation, table, schema, record, old_record }`, `record` and `old_record` each the whole row or `null`. `private` is `true` unless the call says `false`, as on Supabase: a private message reaches only the topic's private channels whose [policies](#private-channels) let them receive broadcasts, and a public one only its public channels. A message goes under the topic's 100 broadcasts a second, and one whose topic or event is over 255 bytes or whose payload is over 256 KiB is dropped. The server reads the table while one of its sockets is open, and a message no channel hears is dropped, as on Supabase. A call as a role the policies on `realtime.messages` do not let insert sends nothing and raises a warning, as Supabase's does, so a trigger function that sends for its callers is `security definer`.
|
|
87
|
+
Each call inserts a message into `realtime.messages` in the caller's transaction, as on Supabase, so a transaction rolled back sends nothing. Within a second of its commit, the server takes the message out of the table and sends it to the channels joined on its topic, in the order the transaction sent them, with the message's id in the payload's `id` and in the broadcast's `meta.id`. `broadcast_changes()` sends `{ operation, table, schema, record, old_record }`, `record` and `old_record` each the whole row or `null`. `private` is `true` unless the call says `false`, as on Supabase: a private message reaches only the topic's private channels whose [policies](#private-channels) let them receive broadcasts, and a public one only its public channels. A message goes under the topic's 100 broadcasts a second, and one whose topic or event is over 255 bytes or whose payload is over 256 KiB is dropped. The server reads the table while one of its sockets is open, and a message no channel hears is dropped, as on Supabase. A call as a role the policies on `realtime.messages` do not let insert sends nothing and raises a warning, as Supabase's does, so a trigger function that sends for its callers is `security definer`. Every process serving the app deletes the broadcast messages more than 48 hours old, whether or not a socket is open: once it starts, then every 10 minutes. The margin covers `inserted_at`, a time without a zone, stamped in the sending session's time zone. <gap>A project that was not imported cannot call `realtime.send()` without making Supabase's functions in a migration of its own, because Protobase's migrations do not make them.</gap>
|
|
88
88
|
|
|
89
89
|
## Private channels
|
|
90
90
|
|
|
@@ -36,6 +36,10 @@ description: Finish a move from Supabase to Protobase after `protobase import su
|
|
|
36
36
|
|
|
37
37
|
Nothing to do: each table's count matched the source before the load committed.
|
|
38
38
|
|
|
39
|
+
### API keys
|
|
40
|
+
|
|
41
|
+
Unless `protobase.config.ts` sets `apiKeys`, add `PROTOBASE_PUBLISHABLE_KEY` and `PROTOBASE_SECRET_KEY` to `.env.example` with empty values: the user enters the keys, never you. Then point every `createClient` at the app's `/api/sb` with the publishable key, in place of the Supabase project's URL and anon key, reading both from the app's own settings, not the Supabase ones. See [Supabase client API](../protobase/references/reference/supabase-rest.md#keys-and-roles).
|
|
42
|
+
|
|
39
43
|
### Sign-in
|
|
40
44
|
|
|
41
45
|
Passwords need nothing: the import's migrations carry them over. For each provider listed with accounts:
|