@protobase/cli 0.120.0 → 0.121.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/supabase/auth-config.js +27 -4
- package/package.json +8 -8
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
- package/skills/protobase/references/reference/auth.md +33 -4
- package/skills/protobase/references/reference/cli.md +1 -1
- package/skills/protobase/references/reference/config/sign-in.md +17 -4
- package/skills/protobase/references/reference/config.md +1 -1
- package/skills/protobase/references/reference/jobs.md +1 -1
- package/skills/protobase/references/reference/notifications.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -6,9 +6,11 @@ import { Node } from "ts-morph";
|
|
|
6
6
|
//#region src/supabase/auth-config.ts
|
|
7
7
|
/** The `auth` settings for Supabase's auth.users as the user table, on a copy of the database the import owns. */
|
|
8
8
|
const supabaseUsers = {
|
|
9
|
+
tables: { user: {
|
|
10
|
+
name: "users",
|
|
11
|
+
columns: { role: "app_role" }
|
|
12
|
+
} },
|
|
9
13
|
users: {
|
|
10
|
-
table: "users",
|
|
11
|
-
columns: { role: "app_role" },
|
|
12
14
|
metadata: "raw_user_meta_data",
|
|
13
15
|
guardedSchemas: ["auth"]
|
|
14
16
|
},
|
|
@@ -20,6 +22,7 @@ const sharedUsersSchema = "app_auth";
|
|
|
20
22
|
/** The `auth` settings for a view over Supabase's auth.users, on a Supabase database the app shares with Supabase Auth. */
|
|
21
23
|
const supabaseUsersView = {
|
|
22
24
|
schema: sharedUsersSchema,
|
|
25
|
+
tables: supabaseUsers.tables,
|
|
23
26
|
users: {
|
|
24
27
|
...supabaseUsers.users,
|
|
25
28
|
keyTable: {
|
|
@@ -58,7 +61,8 @@ const literal = (value) => {
|
|
|
58
61
|
const settingsText = ({ settings, comment }, indent) => [...comment.map((line) => `// ${line}`), ...Object.entries(settings).map(([key, value]) => `${key}: ${literal(value)},`)].map((line) => `${indent}${line}`).join("\n");
|
|
59
62
|
/**
|
|
60
63
|
* protobase.config.ts with the settings first in its `auth`, or with an `auth` of them when it has none, sign-in being
|
|
61
|
-
* on by default; fails, naming what to add, when it exports no object the import can see
|
|
64
|
+
* on by default; fails, naming what to add, when it exports no object the import can see, its `auth` is not one, or
|
|
65
|
+
* its `auth.tables` is not one or names a table the settings name.
|
|
62
66
|
*/
|
|
63
67
|
const withSupabaseUsers = (text, file, users) => {
|
|
64
68
|
const config = exportedConfigObject(text).object;
|
|
@@ -72,10 +76,29 @@ const withSupabaseUsers = (text, file, users) => {
|
|
|
72
76
|
}
|
|
73
77
|
const object = Node.isPropertyAssignment(auth) ? auth.getInitializer() : void 0;
|
|
74
78
|
if (!object || !Node.isObjectLiteralExpression(object)) throw refused();
|
|
79
|
+
const ownTables = ownTablesOf(object, users, refused);
|
|
80
|
+
const { tables: settingsTables, ...settings } = users.settings;
|
|
81
|
+
const merged = ownTables && settingsTables ? withTables(text, ownTables.getStart() + 1, settingsTables, ownTables.getProperties().length > 0) : text;
|
|
75
82
|
const first = object.getProperties()[0];
|
|
76
83
|
const indent = first ? " ".repeat(first.getStartLinePos() === first.getStart() ? 0 : first.getStart() - first.getStartLinePos()) : " ";
|
|
77
84
|
const at = object.getStart() + 1;
|
|
78
|
-
|
|
85
|
+
const written = {
|
|
86
|
+
...users,
|
|
87
|
+
settings: ownTables ? settings : users.settings
|
|
88
|
+
};
|
|
89
|
+
return `${merged.slice(0, at)}\n${settingsText(written, indent)}${first ? "" : "\n"}${merged.slice(at)}`;
|
|
90
|
+
};
|
|
91
|
+
const ownTablesOf = (auth, users, refused) => {
|
|
92
|
+
const tables = auth.getProperty("tables");
|
|
93
|
+
if (!tables) return;
|
|
94
|
+
const own = Node.isPropertyAssignment(tables) ? tables.getInitializer() : void 0;
|
|
95
|
+
if (!own || !Node.isObjectLiteralExpression(own)) throw refused();
|
|
96
|
+
if (Object.keys(users.settings.tables ?? {}).some((table) => own.getProperty(table))) throw refused();
|
|
97
|
+
return own;
|
|
98
|
+
};
|
|
99
|
+
const withTables = (text, at, tables, more) => {
|
|
100
|
+
const entries = Object.entries(tables).map(([table, names]) => `${table}: ${literal(names)}`).join(", ");
|
|
101
|
+
return `${text.slice(0, at)} ${entries}${more ? "," : " "}${text.slice(at)}`;
|
|
79
102
|
};
|
|
80
103
|
/** Where the app's Better Auth settings live, and what they become; fails before anything is written when it cannot. */
|
|
81
104
|
const planAuthConfig = async (projectDir, users) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.121.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.121.0",
|
|
47
|
+
"@protobase/layout": "0.121.0",
|
|
48
|
+
"@protobase/query": "0.121.0",
|
|
49
|
+
"@protobase/schema": "0.121.0",
|
|
50
|
+
"@protobase/server": "0.121.0",
|
|
51
|
+
"@protobase/ui": "0.121.0",
|
|
52
|
+
"@protobase/workflows": "0.121.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",
|
|
@@ -9,6 +9,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
9
9
|
- [First admin](../reference/auth.md#first-run): No account can be made over the web while the app has no users. You create the first admin from the terminal, and the last active admin cannot be deleted, demoted or blocked.
|
|
10
10
|
- [Users from a script](../reference/auth.md#first-run): A seed or another script of the project creates and lists users, and mints their tokens, on the app's own sign-in.
|
|
11
11
|
- [Versioned sign-in tables](../reference/auth.md#migrations): The sign-in tables come from numbered migrations that ship with Protobase, written as the project's own and recorded in the database, so a deploy checks them without comparing tables. Every feature has its tables from the start, so turning one on or off needs no migration.
|
|
12
|
+
- [Table and column names](../reference/auth.md#table-and-column-names): Every sign-in table can take another name or a prefix, and every column but `id` another name, from the config, and the migrations, sign-in and Protobase's own queries all use it.
|
|
12
13
|
- [Existing users table](../reference/auth.md#an-existing-users-table): Sign-in can use the users table another system keeps in the same database.
|
|
13
14
|
- [Users page](../reference/auth.md#users-page): Admins find people, set roles, block them, add accounts and invite people by email.
|
|
14
15
|
- [Account page](../reference/auth.md#account-page): Everyone signed in has an account page for their profile, sign-in and security, devices, connected apps and access tokens, and you add, hide or reorder its tabs.
|
|
@@ -38,7 +38,7 @@ Each version's statements are followed by its row in `auth_migrations`. The file
|
|
|
38
38
|
|
|
39
39
|
Every store has the tables of every feature, whether the app turns the feature on or not: [passkeys](#passkeys), [two-factor authentication](#two-factor-authentication), [organizations](#organizations), the [OAuth provider for MCP](#oauth-for-mcp-clients) and [personal access tokens](personal-access-tokens.md). Turning a feature on or off needs no migration and drops nothing; the columns a feature adds to the user and session tables are empty until it is on. SAML providers and open sign-up keep nothing in the store.
|
|
40
40
|
|
|
41
|
-
The
|
|
41
|
+
The names the app configures, the store's schema ([`auth.schema`](config/sign-in.md#authschema)), its [tables and columns](#table-and-column-names), and uuid ids (`generateUserId: 'uuid'`), are the ones in effect when the file is written. Changing one later is a migration of the project's own, such as a rename. <gap>`protobase auth migration` cannot rename a table or column the store has already because writing a rename from a changed name is not implemented.</gap>
|
|
42
42
|
|
|
43
43
|
The server never changes the schema, and never compares it with what Better Auth needs. `protobase serve` and `protobase dev` read `auth_migrations` at startup and refuse to start while a version of this Protobase is not applied, naming it and `protobase auth migration`, or while the store has a version newer than this Protobase knows. The examples' `db:migrate` applies all pending files in one transaction, so a migration that fails leaves the database as the running version expects it. The host must guarantee the rest: nothing but the migrations writes while they run, and the new version serves only after they succeeded. Only [`protobase dev`](cli.md#dev), on the developer's machine, compares the store's tables with what the app's Better Auth needs, and warns at startup about each table, column or index that drifted, such as one changed by hand.
|
|
44
44
|
|
|
@@ -46,19 +46,47 @@ No resource may be over a table of the store, which holds password hashes, sessi
|
|
|
46
46
|
|
|
47
47
|
A store made before 0.48, when `protobase auth migration` compared the database with Better Auth's tables, has no `auth_migrations`. For it, `protobase auth migration` writes the step that adopts it, once: it runs each version in a scratch schema, in a transaction it rolls back, to find the tables and columns that version makes, records each version whose tables and columns the store has, with their types, as applied, and writes the versions whose tables it has none of, such as MCP's for an app that never turned MCP on. The file checks again, when it is applied, that the store has every table and column it adopts, and stops otherwise, naming them. A store that has only some of a version's tables and columns, or has them with other types, is refused, naming what differs: bring it to the schema of Protobase 0.47 first, with that version's `protobase auth migration`. A store set up by Protobase 0.6, with Better Auth's camelCase names, or by `auth:migrate` before it, goes through 0.47 the same way.
|
|
48
48
|
|
|
49
|
+
### Table and column names
|
|
50
|
+
|
|
51
|
+
Each module of the store declares its tables and columns once, under built-in names, snake_case like the app's (`sign_in_policy.platform_sign_in`, `session.user_id`); the code and the API keep Better Auth's camelCase names. The modules and their tables:
|
|
52
|
+
|
|
53
|
+
- `auth`: `user`, `session`, `account`, `verification`, `jwks` and `auth_migrations`.
|
|
54
|
+
- `two_factor`: `two_factor`, and the user's `two_factor_enabled`.
|
|
55
|
+
- `passkeys`: `passkey`.
|
|
56
|
+
- `sign_in_policy`: `sign_in_policy`.
|
|
57
|
+
- `staff_sign_in`: `staff_sign_in`.
|
|
58
|
+
- `organizations`: `organization`, `member` and `invitation`, whose rows each belong to one organization, and the user's `last_organization_id`, the session's `active_organization_id` and the personal access token's `organization_id`.
|
|
59
|
+
- `personal_access_tokens`: `personal_access_token`.
|
|
60
|
+
- `mcp`: the OAuth provider's `oauth_client`, `oauth_resource`, `oauth_client_resource`, `oauth_refresh_token`, `oauth_access_token`, `oauth_consent` and `oauth_client_assertion`.
|
|
61
|
+
- `mail_senders`: `mail_sender`.
|
|
62
|
+
- `platform_devices`: `refused_account` and `device_session`.
|
|
63
|
+
|
|
64
|
+
[`auth.tables`](config/sign-in.md#authtables) gives any of them another name in the database: `prefix` goes before the name of every table it does not name, and each table, by its built-in name, takes its own `name` and `columns`, each column by its built-in name. A name it leaves out stays built-in, and `id` always keeps its name. The migrations make the tables and columns under these names, and sign-in, sessions, tokens and Protobase's own queries of the store read and write them so.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
auth: {
|
|
68
|
+
tables: { prefix: 'app_', user: { name: 'people', columns: { role: 'app_role' } }, session: { columns: { user_id: 'person_id' } } },
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Here the user table is `people`, with its roles in `app_role`, and every other table starts with `app_`, such as `app_session`, whose `person_id` holds its user.
|
|
73
|
+
|
|
74
|
+
Postgres keeps the first 63 bytes of a name and drops the rest, so the server refuses to start with a name `auth.tables` gives past 63 bytes, naming the setting and its length. It refuses a table or column the store does not have, `id`, and a name two tables, or two columns of one table, would share. Each index is named after its table, such as `app_session_user_id_idx` for `session_user_id_idx`; a prefixed table name or an index name past 63 bytes is cut to its start and `_` and the first 8 hex digits of its SHA-256, the same every time.
|
|
75
|
+
|
|
49
76
|
### An existing users table
|
|
50
77
|
|
|
51
78
|
The store can use a users table another system made, such as Supabase's `auth.users`, so its rows keep signing in and every foreign key, trigger and function that names the table keeps working:
|
|
52
79
|
|
|
53
80
|
```ts
|
|
54
81
|
auth: {
|
|
55
|
-
|
|
82
|
+
tables: { user: { name: 'users', columns: { role: 'app_role' } } },
|
|
83
|
+
users: { metadata: 'raw_user_meta_data', guardedSchemas: ['auth'] },
|
|
56
84
|
passwordHashes: ['bcrypt'],
|
|
57
85
|
generateUserId: 'uuid',
|
|
58
86
|
}
|
|
59
87
|
```
|
|
60
88
|
|
|
61
|
-
- `
|
|
89
|
+
- `tables.user.name` names the table, default `user`. `tables.user.columns` maps a column, by its built-in name (`name`, `email`, `email_verified`, `email_confirmed_at`, `image`, `created_at`, `updated_at`, `role`, `banned`, `ban_reason`, `ban_expires`, `two_factor_enabled`, `last_role`, `last_organization_id`), to the table's own; here the app's roles go to `app_role`, since Supabase's `role` holds the Postgres role. The other tables point at this one (see [Table and column names](#table-and-column-names)).
|
|
62
90
|
- `users.guardedSchemas` names the schemas where the other system keeps the rest of its sign-in data, such as Supabase Auth's `auth`, with its identities, sessions, refresh tokens and two-factor secrets. Every table in them, including one the other system adds later, counts among the store's tables: no resource may be over it and the assistant's queries never read it. Name only a schema that holds none of the app's own tables.
|
|
63
91
|
- `users.metadata` names a JSON column for each user's metadata, which the migrations add as `jsonb` when the table lacks it: `createUser(auth, { ..., metadata: { full_name: 'Carol' } })` writes it, so a trigger that reads `raw_user_meta_data->>'full_name'` sees it.
|
|
64
92
|
- `passwordHashes: ['bcrypt']` also verifies bcrypt hashes (`$2a$`, `$2b$`, `$2y$`), and stores the password again as Better Auth's own scrypt after its first sign-in. The 12-character minimum holds for new passwords only, so a shorter existing one still signs in.
|
|
@@ -73,7 +101,8 @@ Where the app may not change the other system's users table, as on a Supabase da
|
|
|
73
101
|
```ts
|
|
74
102
|
auth: {
|
|
75
103
|
schema: 'app_auth',
|
|
76
|
-
|
|
104
|
+
tables: { user: { name: 'users', columns: { role: 'app_role' } } },
|
|
105
|
+
users: { keyTable: { schema: 'auth', table: 'users' }, guardedSchemas: ['auth'], metadata: 'raw_user_meta_data' },
|
|
77
106
|
passwordHashes: ['bcrypt'],
|
|
78
107
|
generateUserId: 'uuid',
|
|
79
108
|
}
|
|
@@ -663,7 +663,7 @@ protobase import supabase [<connection> | --source-env <variable>] [--env DATABA
|
|
|
663
663
|
|
|
664
664
|
Turns a Supabase project's database into the project in the current directory, in two runs with the project's migrations between them. It needs PostgreSQL's `pg_dump` and `psql` on `PATH`, of the Supabase database's major version or newer, and reads the `.env` nearest the current directory for the project's database (`--env`).
|
|
665
665
|
|
|
666
|
-
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, so the import cannot carry them over. It then says how many share their address with another user and how many have one of their own, and prints `select id, email from auth.users where is_sso_user` to list them rather than their addresses. Deleting a user in Supabase deletes or breaks the app's rows that reference it, so what to do about these users is the developer's decision, made in Supabase before importing again. 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 `
|
|
666
|
+
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, so the import cannot carry them over. It then says how many share their address with another user and how many have one of their own, and prints `select id, email from auth.users where is_sso_user` to list them rather than their addresses. Deleting a user in Supabase deletes or breaks the app's rows that reference it, so what to do about these users is the developer's decision, made in Supabase before importing again. 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 `tables: { user: { name: 'users', columns: { role: 'app_role' } } }`, `users: { metadata: 'raw_user_meta_data', guardedSchemas: ['auth'] }`, `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.
|
|
667
667
|
2. **Apply the migration** with the project's other migrations, such as `bun run db:migrate`.
|
|
668
668
|
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>
|
|
669
669
|
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.
|
|
@@ -222,16 +222,29 @@ Lets the signed-in person delete their own account from the account page, as app
|
|
|
222
222
|
export default defineConfig({ auth: { accountDeletion: false } })
|
|
223
223
|
```
|
|
224
224
|
|
|
225
|
+
## auth.tables
|
|
226
|
+
|
|
227
|
+
- **Type:** `{ prefix?: string }`, and for each [built-in table](../auth.md#table-and-column-names), by its name, `{ name?: string; columns?: { [column]?: string } }` with its built-in columns as keys
|
|
228
|
+
- **Default:** the built-in names
|
|
229
|
+
|
|
230
|
+
The names of the auth store's tables and columns in the database, where the app wants others than the built-in ones: `prefix` goes before the name of every table it does not name, and each table, by its built-in name, takes its own `name` and `columns`, each column by its built-in name. `id` keeps its name. A name past Postgres's 63 bytes is refused. See [Table and column names](../auth.md#table-and-column-names).
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
export default defineConfig({
|
|
234
|
+
auth: { tables: { prefix: 'app_', user: { name: 'users', columns: { role: 'app_role' } } } },
|
|
235
|
+
})
|
|
236
|
+
```
|
|
237
|
+
|
|
225
238
|
## auth.users
|
|
226
239
|
|
|
227
|
-
- **Type:** `{
|
|
228
|
-
- **Default:**
|
|
240
|
+
- **Type:** `{ metadata?: string; keyTable?: { schema: string; table: string }; guardedSchemas?: string[] }`
|
|
241
|
+
- **Default:** none
|
|
229
242
|
|
|
230
|
-
The user table, when another system made it, such as Supabase's `auth.users`:
|
|
243
|
+
The user table, when another system made it, such as Supabase's `auth.users`: a JSON column for each user's metadata, and what else the store must know of it; [`auth.tables`](#authtables)`.user` names it and its columns. See [An existing users table](../auth.md#an-existing-users-table). `keyTable` makes the user table a view of the app's own over another system's, the table it names, which holds the user ids: the store's migrations leave the view to the app and point their foreign keys at that table. See [A view over another system's users](../auth.md#a-view-over-another-systems-users). `guardedSchemas` names the schemas the other system keeps the rest of its sign-in data in, such as Supabase Auth's `auth`: no resource may be over any table in them, and the assistant's queries never read one.
|
|
231
244
|
|
|
232
245
|
```ts
|
|
233
246
|
export default defineConfig({
|
|
234
|
-
auth: { schema: 'auth',
|
|
247
|
+
auth: { schema: 'auth', tables: { user: { name: 'users', columns: { role: 'app_role' } } }, users: { metadata: 'raw_user_meta_data', guardedSchemas: ['auth'] } },
|
|
235
248
|
})
|
|
236
249
|
```
|
|
237
250
|
|
|
@@ -106,7 +106,7 @@ The app's database is `DATABASE_URL`'s, with the pool size of `PROTOBASE_DB_CONN
|
|
|
106
106
|
}
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
JSON cannot branch on the command or compute a value; a config that needs to is written in TypeScript. `$schema` points the editor at the file's JSON Schema, which `@protobase/config` ships as `schema.json`, made from the same types as a TypeScript config: it completes and checks every key and value as it is typed, and takes an `$env` value wherever a
|
|
109
|
+
JSON cannot branch on the command or compute a value; a config that needs to is written in TypeScript. `$schema` points the editor at the file's JSON Schema, which `@protobase/config` ships as `schema.json`, made from the same types as a TypeScript config: it completes and checks every key and value as it is typed, and takes an `$env` value wherever text, a number or a list goes, but not for a boolean or an object, which `$env` text cannot be. Protobase itself leaves `$schema` out. Where a key holds the settings of a library underneath, such as `auth.socialProviders`, the schema takes any object, and the app checks it when it starts.
|
|
110
110
|
|
|
111
111
|
## One config per project
|
|
112
112
|
|
|
@@ -100,7 +100,7 @@ export default (async (event, trx) => {
|
|
|
100
100
|
| `key` and `mode` | One waiting job per key: with `mode: 'dedupe'` (the default) an enqueue while one waits returns that one's id and leaves it as it is; with `mode: 'replace'` the waiting job takes this payload and these options. A job that is running does not count, so a change made while it runs gets a job of its own. |
|
|
101
101
|
| `group` | The group of an [ordered](#ordered-groups) job: required there, refused elsewhere. |
|
|
102
102
|
|
|
103
|
-
A job
|
|
103
|
+
A job this process enqueues starts at once when this process runs its jobs, and one enqueued in a transaction starts once that transaction commits, never when it rolls back; a wake starts up to the job's `concurrency` of its due jobs. A job enqueued by another process, or from SQL, is picked up within the poll interval, 2 seconds, and so is one enqueued in a transaction of a Kysely instance the app built itself rather than its `db`.
|
|
104
104
|
|
|
105
105
|
Each worker takes one job per poll, so a queue that fills faster drains one job per worker every 2 seconds at first. Once the queue maintenance, about every minute, counts more jobs ready than the job's `concurrency`, a worker that found a job fetches the next one at once, until a fetch finds none: a backlog then drains as fast as its jobs run.
|
|
106
106
|
|
|
@@ -443,7 +443,7 @@ The default store keeps devices in the table `devices` of the schema `notificati
|
|
|
443
443
|
|
|
444
444
|
`protobase migration` adds `session_id` to a devices table written before devices kept their session.
|
|
445
445
|
|
|
446
|
-
You rename the schema, the table and each column, as auth takes `
|
|
446
|
+
You rename the schema, the table and each column, as auth takes `tables`, such as to keep devices in a table you already have:
|
|
447
447
|
|
|
448
448
|
```ts
|
|
449
449
|
notifications: {
|