@protobase/cli 0.130.1 → 0.131.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.
@@ -1,17 +1,17 @@
1
1
  //#region src/build/pdfkit-fonts.ts
2
2
  const nodeBuild = /[\\/]pdfkit[\\/]js[\\/]pdfkit\.node\.mjs$/;
3
- const fontLoad = /\b[\w$]+\('#standard-fonts\/(\w+)'\)/g;
3
+ const fontLoad = /\b[\w$]+\('\.\/standard-fonts\/(\w+)\.cjs'\)/g;
4
4
  /**
5
5
  * Bundles pdfkit's standard fonts, which React PDF's renderer writes text in. pdfkit's Node build loads each with a
6
- * `require` of its own subpath import, `#standard-fonts/Helvetica`, made at run time, which a bundle cannot resolve
7
- * from its own folder; this turns each into an import of the font's module beside it.
6
+ * `require` of the font's CommonJS file beside it, `./standard-fonts/Helvetica.cjs`, made at run time, which a bundle
7
+ * cannot resolve from its own folder; this turns each into an import of the font's ES module beside it.
8
8
  */
9
9
  const pdfkitFonts = () => ({
10
10
  name: "protobase-pdfkit-fonts",
11
11
  transform(code, id) {
12
12
  if (!nodeBuild.test(id)) return;
13
13
  const fonts = new Set([...code.matchAll(fontLoad)].map(([, font]) => font));
14
- if (fonts.size === 0) this.error("pdfkit no longer loads its standard fonts as `require(\"#standard-fonts/<Font>\")`; update pdfkitFonts");
14
+ if (fonts.size === 0) this.error("pdfkit no longer loads its standard fonts as `require(\"./standard-fonts/<Font>.cjs\")`; update pdfkitFonts");
15
15
  return {
16
16
  code: [...fonts].map((font) => `import __pdfkitFont${font} from './standard-fonts/${font}.mjs'\n`).join("") + code.replace(fontLoad, (_, font) => `__pdfkitFont${font}`),
17
17
  map: null
@@ -2,6 +2,7 @@ import { moduleFile } from "../module-file.js";
2
2
  import { viteBundle } from "./vite-bundle.js";
3
3
  import { npmWs } from "./npm-ws.js";
4
4
  import { pdfkitFonts } from "./pdfkit-fonts.js";
5
+ import { unicodePropertiesTrie } from "./unicode-properties-trie.js";
5
6
  import { fileURLToPath } from "node:url";
6
7
  //#region src/build/serve-runtime.ts
7
8
  const cliRoot = fileURLToPath(new URL("../..", import.meta.url));
@@ -12,7 +13,11 @@ const buildServeRuntime = async ({ outFile, bun }) => {
12
13
  entry: serveMain,
13
14
  outFile,
14
15
  bun,
15
- plugins: [npmWs(), pdfkitFonts()]
16
+ plugins: [
17
+ npmWs(),
18
+ pdfkitFonts(),
19
+ unicodePropertiesTrie()
20
+ ]
16
21
  });
17
22
  };
18
23
  //#endregion
@@ -0,0 +1,18 @@
1
+ import path from "node:path";
2
+ //#region src/build/unicode-properties-trie.ts
3
+ const entry = /[\\/]unicode-properties[\\/]index\.js$/;
4
+ /**
5
+ * Bundles the Unicode data that React PDF's text layout reads through unicode-properties. Its Node build reads the
6
+ * file `data.trie` beside it at run time, which a bundle does not carry; this takes the build that embeds the same data
7
+ * as base64 instead.
8
+ */
9
+ const unicodePropertiesTrie = () => ({
10
+ name: "protobase-unicode-properties-trie",
11
+ enforce: "pre",
12
+ resolveId(id, importer) {
13
+ if (id !== "#binary-trie" || !importer || !entry.test(importer)) return;
14
+ return path.join(path.dirname(importer), "binaryTrie.browser.js");
15
+ }
16
+ });
17
+ //#endregion
18
+ export { unicodePropertiesTrie };
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.130.1";
2
+ var version = "0.131.0";
3
3
  //#endregion
4
4
  export { version };
@@ -1,18 +1,18 @@
1
- import { stepsOfVersions } from "@protobase/server/internal";
1
+ import { versionRecordRefusal, versionRecordTable } from "@protobase/server/internal";
2
2
  import postgres from "postgres";
3
3
  //#region src/migration/baseline/read-live-store.ts
4
4
  /**
5
5
  * The auth store at `url` as its schema has it, read once in a read-only transaction: every relation of the store's
6
- * schema with its kind and columns, and the parts of steps it recorded: in `auth_steps`, or for a store without it, by
7
- * version in `auth_migrations`. Refuses a store with neither, one made before 0.48, which `protobase auth migration`
8
- * adopts first.
6
+ * schema with its kind and columns, and the parts of steps it recorded in `auth_steps`. Refuses a store without it:
7
+ * one that records versions instead, which Protobase 0.130 moves to `auth_steps` first, or one made before 0.48, which
8
+ * `protobase auth migration` adopts first.
9
9
  */
10
10
  const readLiveStore = async (url, names) => {
11
11
  const sql = postgres(url, {
12
12
  max: 1,
13
13
  onnotice: () => {}
14
14
  });
15
- const record = names.names.table("auth_migrations");
15
+ const record = versionRecordTable(names);
16
16
  const steps = names.names.table("auth_steps");
17
17
  try {
18
18
  return await sql.begin("read only", async (tx) => {
@@ -35,12 +35,8 @@ const readLiveStore = async (url, names) => {
35
35
  relations
36
36
  };
37
37
  }
38
- if (!relations[record.name]) throw new Error(`The auth store has neither ${steps.name} nor ${record.name}, as a store made before 0.48: adopt it with \`protobase auth migration\` and apply that file first`);
39
- const versions = await tx.unsafe(`select ${String(record.columns.version)} as version from ${String(record)} order by 1`);
40
- return {
41
- applied: stepsOfVersions(versions.map(({ version }) => Number(version))),
42
- relations
43
- };
38
+ if (relations[record.name]) throw new Error(versionRecordRefusal(record.name));
39
+ throw new Error(`The auth store has no ${steps.name}, as a store made before 0.48: adopt it with \`protobase auth migration\` and apply that file first`);
44
40
  });
45
41
  } finally {
46
42
  await sql.end();
@@ -5,11 +5,10 @@ import { refuseInconsistent } from "../snapshot/consistency.js";
5
5
  import { writeMigrationFile } from "../snapshot/write-file.js";
6
6
  import { describedModules, readLiveModules } from "./read-live-modules.js";
7
7
  import { readLiveStore } from "./read-live-store.js";
8
- import { baselineStore, stepRecordMigration, storeModel, targetIds } from "@protobase/server/internal";
8
+ import { baselineStore, storeModel, targetIds } from "@protobase/server/internal";
9
9
  //#region src/migration/baseline/write-baseline.ts
10
10
  const intro = `-- Written by \`protobase migration baseline\` from the database: the auth store as the project's earlier migrations made it.
11
- -- It drops nothing, and changes nothing but the record of the store's steps, made from auth_migrations where the store
12
- -- has none; it starts ${snapshotFile}, and \`protobase migration\` writes what the store lacks from it.
11
+ -- It changes nothing; it starts ${snapshotFile}, and \`protobase migration\` writes what the store lacks from it.
13
12
  `;
14
13
  const modulesIntro = `-- Written by \`protobase migration baseline\` from the database: the schema modules the project's earlier migrations
15
14
  -- made, which ${snapshotFile} did not record. It changes nothing; \`protobase migration\` writes what they lack from it.
@@ -17,10 +16,10 @@ const modulesIntro = `-- Written by \`protobase migration baseline\` from the da
17
16
  /**
18
17
  * `protobase migration baseline`: describes, as the database has them, the auth store of a project without a snapshot
19
18
  * and each schema module the config needs that the snapshot lacks, such as one an earlier version's migration made,
20
- * in a numbered migration that only records itself, and the store's steps where it records them by version alone,
21
- * and the snapshot that ends at it, once. Each module of the store that is on is at the step `auth_migrations` records,
22
- * a module that is off but has tables is kept, organizations count as ever on when a table whose rows belong to one has
23
- * the column that names it, and a user table another system made is external. A schema module is at the step its
19
+ * in a numbered migration that only records itself, and the snapshot that ends at it, once. Each module of the store
20
+ * that is on is at the step `auth_steps` records, a module that is off but has tables is kept, organizations count as
21
+ * ever on when a table whose rows belong to one has the column that names it, and a user table another system made is
22
+ * external. A schema module is at the step its
24
23
  * catalogue shows (`SchemaModule.read`). Returns the file's path.
25
24
  */
26
25
  const writeBaseline = async ({ projectDir, dir, auth, modules, url, protobaseVersion, newId }) => {
@@ -50,7 +49,7 @@ const writeBaseline = async ({ projectDir, dir, auth, modules, url, protobaseVer
50
49
  if (!auth && !found) throw new Error("Sign-in is off in the project's config, and the database has none of the schema modules it needs: there is nothing to describe, and `protobase migration` writes them");
51
50
  const store = auth && baselineStore(auth.names, await readLiveStore(url, auth.names));
52
51
  const modulesText = found ? `${described}\n` : "";
53
- const body = !store ? `${modulesIntro}${modulesText}` : store.stepRecord ? `${intro}${modulesText}` : `${intro}${modulesText}\n${stepRecordMigration(auth.names)}\n`;
52
+ const body = store ? `${intro}${modulesText}` : `${modulesIntro}${modulesText}`;
54
53
  const decisions = {
55
54
  modules: {
56
55
  kept: store?.kept ?? [],
@@ -47,9 +47,10 @@ const columnChanges = (relation, before, after, keepsValues = tables.has(relatio
47
47
  });
48
48
  const requiredColumns = (relation, before, after) => after.filter((column) => !before.some((had) => had.name === column.name) && column.notNull && !column.hasDefault && !column.generated).map((column) => `adds the required column ${relation.name}.${column.name} without a default`);
49
49
  const newLimits = (relation, what, before, after) => after.filter((limit) => !before.some((had) => had.name === limit.name && had.definition === limit.definition)).map((limit) => `adds the ${what} ${limit.name} to ${relation.name}, which rows written by older code may break`);
50
- const relationChanges = (before, after, relation) => {
50
+ const relationChanges = (before, after, relation, dropped) => {
51
51
  const now = after.relations.find((found) => found.name === relation.name);
52
52
  const kind = kindNames[relation.kind];
53
+ if (!now && dropped.has(relation.oid)) return [];
53
54
  if (!now) return [`drops, renames or moves ${kind} ${relation.name}`];
54
55
  if (now.kind !== relation.kind) return [`makes ${kind} ${relation.name} a ${kindNames[now.kind]}`];
55
56
  const columns = [byRelation(before.columns, relation.oid), byRelation(after.columns, now.oid)];
@@ -76,9 +77,12 @@ const enumChanges = (before, after) => before.enums.flatMap((had) => {
76
77
  if (!now) return [`drops, renames or moves type ${had.name}`];
77
78
  return had.labels.filter((label) => !now.labels.includes(label)).map((label) => `removes the value ${label} of type ${had.name}`);
78
79
  });
79
- /** What the change from `before` to `after` takes from older code, one line each; none when it only adds. */
80
- const contractions = (before, after) => [
81
- ...before.relations.flatMap((relation) => relationChanges(before, after, relation)),
80
+ /**
81
+ * What the change from `before` to `after` takes from older code, one line each; none when it only adds. `dropped`: the
82
+ * oids of the tables a step of the auth store drops, which no older code reads (`Step.drops`), whose drop takes nothing.
83
+ */
84
+ const contractions = (before, after, dropped = /* @__PURE__ */ new Set()) => [
85
+ ...before.relations.flatMap((relation) => relationChanges(before, after, relation, dropped)),
82
86
  ...functionChanges(before, after),
83
87
  ...enumChanges(before, after)
84
88
  ];
@@ -9,10 +9,10 @@ const lockNotAvailable = "55P03";
9
9
  /**
10
10
  * Applies `sections` to the database at `url` in one transaction it rolls back, reading its schema before them and
11
11
  * after each, so nothing changes: what the whole file takes from older code, each line under the sections that take
12
- * it. Sections that take nothing are
13
- * left out.
12
+ * it. Sections that take nothing are left out, and so is the drop of a table of `dropped`, as SQL text, which a step
13
+ * of the auth store drops and no older code reads (`droppedTableIds`).
14
14
  */
15
- const trialContractions = async (url, sections) => {
15
+ const trialContractions = async (url, sections, dropped = []) => {
16
16
  const sql = postgres(url, {
17
17
  max: 1,
18
18
  onnotice: () => {}
@@ -23,14 +23,19 @@ const trialContractions = async (url, sections) => {
23
23
  await tx.unsafe(`set local lock_timeout = '${lockTimeout}'`);
24
24
  await tx.unsafe(`select set_config('${forceSetting}', 'true', true)`);
25
25
  const before = await readCatalog(tx);
26
+ const droppedOids = /* @__PURE__ */ new Set();
27
+ for (const table of dropped) {
28
+ const [found] = await tx`select to_regclass(${table})::oid::text as oid`;
29
+ if (found?.oid) droppedOids.add(found.oid);
30
+ }
26
31
  const own = [];
27
32
  const sinceStart = [];
28
33
  let previous = before;
29
34
  for (const section of sections) {
30
35
  await tx.unsafe(section.text);
31
36
  const now = await readCatalog(tx);
32
- own.push(contractions(previous, now));
33
- sinceStart.push(contractions(before, now));
37
+ own.push(contractions(previous, now, droppedOids));
38
+ sinceStart.push(contractions(before, now, droppedOids));
34
39
  previous = now;
35
40
  }
36
41
  const whole = sinceStart.at(-1) ?? [];
@@ -67,7 +67,7 @@ const registerMigration = (program) => {
67
67
  const database = project && url ? {
68
68
  url,
69
69
  parts: migrationParts(project),
70
- contractions: (sections) => trialContractions(url, sections),
70
+ contractions: (sections, dropped) => trialContractions(url, sections, dropped),
71
71
  readModule: (id, input) => schemaModules[id].read(project.db, input)
72
72
  } : void 0;
73
73
  const modules = project ? project.modules : await configModules(config);
@@ -12,7 +12,7 @@ import { revivedRows } from "./revival-rows.js";
12
12
  import { breaksOlderCodeNote, olderCodeRefusal } from "../older-code/refusal.js";
13
13
  import { moduleSections } from "./module-sections.js";
14
14
  import { runPreconditions } from "./preconditions.js";
15
- import { schemaModules } from "@protobase/server/internal";
15
+ import { droppedTableIds, schemaModules } from "@protobase/server/internal";
16
16
  //#region src/migration/snapshot/run-migration.ts
17
17
  const checkRevivals = async (url, run, revived) => {
18
18
  if (revived.length === 0 || run.force) return;
@@ -75,7 +75,7 @@ const runMigration = async (run) => {
75
75
  ];
76
76
  if (sections.length === 0) return;
77
77
  const own = /* @__PURE__ */ new Set(["auth", ...written.sections.map(({ name }) => name)]);
78
- const found = database ? await database.contractions(sections) : [];
78
+ const found = database ? await database.contractions(sections, auth ? droppedTableIds(auth.names) : []) : [];
79
79
  const refused = found.filter(({ name }) => !own.has(name));
80
80
  if (refused.length > 0) throw new Error(olderCodeRefusal(refused));
81
81
  const label = (name) => name === "auth" ? "The sign-in modules' steps" : schemaModules[name].title;
@@ -1,5 +1,5 @@
1
1
  import { tableKey } from "../db/model.js";
2
- import { storeRecordNames, storeTableNames } from "@protobase/server/auth-store";
2
+ import { storeRecordName, storeTableNames } from "@protobase/server/auth-store";
3
3
  import { definitionsSchema, userTablesSchema } from "@protobase/server/config-exports";
4
4
  //#region src/scaffold/protobase-tables.ts
5
5
  const storeCore = [
@@ -17,7 +17,7 @@ const authStore = (schema, tables) => {
17
17
  if (schema === "auth") return tables;
18
18
  const has = (name) => tables.some((table) => table.name === name);
19
19
  const user = userTableOf(schema, tables);
20
- if (!storeRecordNames.some(has) && !(storeCore.every(has) && user !== void 0)) return [];
20
+ if (!has(storeRecordName) && !(storeCore.every(has) && user !== void 0)) return [];
21
21
  if (schema !== "public") return tables;
22
22
  return tables.filter((table) => storeTableNames.includes(table.name) || table.name === user);
23
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.130.1",
3
+ "version": "0.131.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.130.1",
47
- "@protobase/layout": "0.130.1",
48
- "@protobase/query": "0.130.1",
49
- "@protobase/schema": "0.130.1",
50
- "@protobase/server": "0.130.1",
51
- "@protobase/ui": "0.130.1",
52
- "@protobase/workflows": "0.130.1",
46
+ "@protobase/config": "0.131.0",
47
+ "@protobase/layout": "0.131.0",
48
+ "@protobase/query": "0.131.0",
49
+ "@protobase/schema": "0.131.0",
50
+ "@protobase/server": "0.131.0",
51
+ "@protobase/ui": "0.131.0",
52
+ "@protobase/workflows": "0.131.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",
@@ -8,7 +8,7 @@ Sign-in methods, users, roles, organizations and tokens.
8
8
  - [Sign-in page](../reference/client.md#the-admin-app): The app signs people in at its own address, where the browser's Back returns to the step before, and signing in comes back to the page they were on.
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
- - [Versioned sign-in tables](../reference/auth.md#migrations): The sign-in tables come from numbered steps that ship with Protobase, a chain for each module of sign-in, written as the project's own migrations and recorded in the database, so a deploy checks them without comparing tables. Every step only adds, and one that assumes something of the rows already there checks it first and names the rows to fix. A feature's tables exist only once the config turns it on, and turning it on is the next migration. Turning it off keeps its tables and rows, and the columns it adds to other tables, counting by hour the writes older code still makes to them, and turning it on again goes on from them, refusing while they hold rows unless `protobase migrate --force` brings them back. Archiving or deleting them is coming soon.
11
+ - [Versioned sign-in tables](../reference/auth.md#migrations): The sign-in tables come from numbered steps that ship with Protobase, a chain for each module of sign-in, written as the project's own migrations and recorded in the database, so a deploy checks them without comparing tables. Every step only adds, but the one that drops `auth_migrations`, the former record of versions no code reads since 0.130, and one that assumes something of the rows already there checks it first and names the rows to fix. A feature's tables exist only once the config turns it on, and turning it on is the next migration. Turning it off keeps its tables and rows, and the columns it adds to other tables, counting by hour the writes older code still makes to them, and turning it on again goes on from them, refusing while they hold rows unless `protobase migrate --force` brings them back. Archiving or deleting them is coming soon.
12
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.
13
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.
14
14
  - [Users page](../reference/auth.md#users-page): Admins find people, set roles, block them, add accounts and invite people by email.
@@ -26,7 +26,7 @@ Users, sessions and signing keys stay apart from the application's tables, in a
26
26
 
27
27
  ### Migrations
28
28
 
29
- The store's tables come from steps that ship with Protobase, and are part of the project's migrations, committed in the repository like the application's own: the examples carry them as `db/migrations/*_auth.sql`, and their `db:migrate` applies both. Each module of sign-in has its own numbered chain of steps, the only source of its tables: `auth` (users, sessions, accounts, codes and signing keys), `two_factor`, `passkeys`, `sign_in_policy`, `staff_sign_in`, `organizations`, `mcp`, `personal_access_tokens`, `mail_senders` and `platform_devices`. A step is written against the store's [names](#table-and-column-names), so it makes the tables and columns under the names the app configures, and a step that adds columns to another module's table, such as `organizations` adding the organization of each user, session and personal access token, adds them only while that module is on. The store records each step it applied in its `auth_steps` table, one row per module, step and the module whose tables it changes, so the columns one module adds to another's tables are recorded apart from the step's own tables. A store an earlier Protobase made recorded versions instead, in `auth_migrations`, the numbers of the single chain the store had before its modules had chains of their own: the next file makes `auth_steps` from them, each version as the steps that shared it, such as version 13 as `auth` 4, `passkeys` 2, `staff_sign_in` 2 and `organizations` 2, and `auth_migrations` is read no more. When an upgrade of Protobase brings new steps, write them as the project's next migration:
29
+ The store's tables come from steps that ship with Protobase, and are part of the project's migrations, committed in the repository like the application's own: the examples carry them as `db/migrations/*_auth.sql`, and their `db:migrate` applies both. Each module of sign-in has its own numbered chain of steps, the only source of its tables: `auth` (users, sessions, accounts, codes and signing keys), `two_factor`, `passkeys`, `sign_in_policy`, `staff_sign_in`, `organizations`, `mcp`, `personal_access_tokens`, `mail_senders` and `platform_devices`. A step is written against the store's [names](#table-and-column-names), so it makes the tables and columns under the names the app configures, and a step that adds columns to another module's table, such as `organizations` adding the organization of each user, session and personal access token, adds them only while that module is on. The store records each step it applied in its `auth_steps` table, one row per module, step and the module whose tables it changes, so the columns one module adds to another's tables are recorded apart from the step's own tables. A store an earlier Protobase made recorded versions instead, in `auth_migrations`, the numbers of the single chain the store had before its modules had chains of their own: the migrations of Protobase 0.130 made `auth_steps` from them, and `auth` step 6 drops `auth_migrations`. A store that still has `auth_migrations` without `auth_steps` is refused: bring the project to Protobase 0.130 first, write and apply its migration there, then upgrade. When an upgrade of Protobase brings new steps, write them as the project's next migration:
30
30
 
31
31
  ```sh
32
32
  bun run db:migrate # the database at the project's current schema
@@ -56,7 +56,7 @@ A store made before 0.48, when `protobase auth migration` compared the database
56
56
 
57
57
  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:
58
58
 
59
- - `auth`: `user`, `session`, `account`, `verification`, `jwks`, `auth_steps` and `auth_migrations`.
59
+ - `auth`: `user`, `session`, `account`, `verification`, `jwks` and `auth_steps`.
60
60
  - `two_factor`: `two_factor`, and the user's `two_factor_enabled`.
61
61
  - `passkeys`: `passkey`.
62
62
  - `sign_in_policy`: `sign_in_policy`.
@@ -51,7 +51,7 @@ protobase scaffold [connection string | --env VAR] [target] [options]
51
51
 
52
52
  Without a connection string or `--env`, the URL is `DATABASE_URL`, from the environment or the nearest `.env` at or above the current directory, as `dev` reads it. `target` is `all` (default), `schema`, `schema.table` or `schema.table.column`. Tables are introspected from `pg_catalog`; `config/<resource>/data.ts` is created or extended. A table that a written one points to with a foreign key is written too, outside the target or excluded, unless it has a resource already, since the app refuses a relation to a resource it does not have; a line names each.
53
53
 
54
- Protobase's own tables are left out, since they hold password hashes, OAuth tokens and signing keys: the auth store, which is the `auth` schema or another schema with the store's `auth_steps` or `auth_migrations` table, or with Better Auth's `session`, `account` and `verification` tables whose sessions point at a user table (in `public`, only the tables of the store's [migrations](auth.md#migrations) and that user table, whatever it is called), pg-boss's `jobs` schema, and the `migrations` schema whose `applied` table records the migrations applied. A line names each one skipped. The auth store is left out whatever the target names; a target naming the `jobs` or `migrations` schema scaffolds it anyway. A resource an earlier run made over one of them gets a warning to remove it, and `dev` and `serve` refuse to start with a resource over the auth store.
54
+ Protobase's own tables are left out, since they hold password hashes, OAuth tokens and signing keys: the auth store, which is the `auth` schema or another schema with the store's `auth_steps` table, or with Better Auth's `session`, `account` and `verification` tables whose sessions point at a user table (in `public`, only the tables of the store's [migrations](auth.md#migrations) and that user table, whatever it is called), pg-boss's `jobs` schema, and the `migrations` schema whose `applied` table records the migrations applied. A line names each one skipped. The auth store is left out whatever the target names; a target naming the `jobs` or `migrations` schema scaffolds it anyway. A resource an earlier run made over one of them gets a warning to remove it, and `dev` and `serve` refuse to start with a resource over the auth store.
55
55
 
56
56
  | Option | Effect |
57
57
  | --- | --- |
@@ -681,17 +681,17 @@ 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 the assistant's 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`, and for a snapshot whose store has no `auth_steps` yet, that table first, made from `auth_migrations`. 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.
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 the assistant's 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
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.
687
687
 
688
688
  #### Changes that break older code
689
689
 
690
- Every file is additive, so the code still running while it deploys, and the version before it once rolled back, still runs on the database, or it breaks older code, and that code refuses to start rather than fail on a request, when the file changes the model the record holds (see [The record of migrations](../guides/deploy.md#the-record-of-migrations)). With `DATABASE_URL` set, `protobase migration` applies the file to the database in a transaction it rolls back, reads the schema before and after, and names what older code loses: a table, column, sequence, function or enum value dropped, renamed or moved, a trigger dropped, disabled or firing on fewer events, a table or column made again with its rows or values lost, a column whose type changes or that becomes `not null`, a required column without a default or one losing its default, and a new constraint or unique index on a table there already, which rows older code writes may break. A view, function, trigger or generated column made again is not lost, and taking back a privilege, which only narrows access, is always allowed. What the sign-in modules' steps take, such as the organization every personal access token needs once organizations turn on, is Protobase's own path: the file then says `-- protobase:breaks-older-code` in its header, with what the steps take under it, and is recorded as not additive. What another part would take is refused before anything is written, naming it, with the way through: write the change by hand with `--custom` and mark the file `-- protobase:breaks-older-code`. Protobase's own parts keep what older code still reads, such as the triggers of a resource that no longer has events, history or live updates while another resource is still captured, so the dispatch job drains what they capture; they follow the resource's fields, so a field made sensitive is no longer copied. Once no resource is captured, the change capture drops them, in a file that says `-- protobase:breaks-older-code`; so does the function and trigger of a rollup field the config no longer has, which the next file drops. A rename or a move is always one file that breaks older code, with no view or trigger in between. A column Protobase adds is retired rather than dropped once the config no longer needs it: the column of a rollup or formula field the config no longer has stays as it is, and putting the field back finds it, with its values; the columns a [sign-in module turned off](auth.md#turning-a-module-off) adds to the tables still on stay under their names, watched for the writes older code still makes, and are in use again, with their values, once it is on again. A resource field's column is the project's own, as is its table: removing the field writes nothing, and dropping the column is a hand-written file marked `-- protobase:breaks-older-code`. [`contract` and `delete`](#signing-off-an-update) write their statements under `-- protobase:contract <id>`, naming the migration that stopped older code from using what they take. <gap>A sign-in step that takes from older code cannot carry `-- protobase:contract` because steps naming the migration that stopped older code from using what they take is not implemented.</gap> A [time rollup](data-config.md#time-rollups) that changes has its table made again and filled from its source, which loses no rows, as its comment marks it as Protobase's: only the columns older code reads that it no longer has are named.
690
+ Every file is additive, so the code still running while it deploys, and the version before it once rolled back, still runs on the database, or it breaks older code, and that code refuses to start rather than fail on a request, when the file changes the model the record holds (see [The record of migrations](../guides/deploy.md#the-record-of-migrations)). With `DATABASE_URL` set, `protobase migration` applies the file to the database in a transaction it rolls back, reads the schema before and after, and names what older code loses: a table, column, sequence, function or enum value dropped, renamed or moved, a trigger dropped, disabled or firing on fewer events, a table or column made again with its rows or values lost, a column whose type changes or that becomes `not null`, a required column without a default or one losing its default, and a new constraint or unique index on a table there already, which rows older code writes may break. A view, function, trigger or generated column made again is not lost, and taking back a privilege, which only narrows access, is always allowed. What the sign-in modules' steps take, such as the organization every personal access token needs once organizations turn on, is Protobase's own path: the file then says `-- protobase:breaks-older-code` in its header, with what the steps take under it, and is recorded as not additive. The drop of `auth_migrations`, the record of versions no code reads since 0.130, takes nothing, and leaves the file additive. What another part would take is refused before anything is written, naming it, with the way through: write the change by hand with `--custom` and mark the file `-- protobase:breaks-older-code`. Protobase's own parts keep what older code still reads, such as the triggers of a resource that no longer has events, history or live updates while another resource is still captured, so the dispatch job drains what they capture; they follow the resource's fields, so a field made sensitive is no longer copied. Once no resource is captured, the change capture drops them, in a file that says `-- protobase:breaks-older-code`; so does the function and trigger of a rollup field the config no longer has, which the next file drops. A rename or a move is always one file that breaks older code, with no view or trigger in between. A column Protobase adds is retired rather than dropped once the config no longer needs it: the column of a rollup or formula field the config no longer has stays as it is, and putting the field back finds it, with its values; the columns a [sign-in module turned off](auth.md#turning-a-module-off) adds to the tables still on stay under their names, watched for the writes older code still makes, and are in use again, with their values, once it is on again. A resource field's column is the project's own, as is its table: removing the field writes nothing, and dropping the column is a hand-written file marked `-- protobase:breaks-older-code`. [`contract` and `delete`](#signing-off-an-update) write their statements under `-- protobase:contract <id>`, naming the migration that stopped older code from using what they take. <gap>A sign-in step that takes from older code cannot carry `-- protobase:contract` because steps naming the migration that stopped older code from using what they take is not implemented.</gap> A [time rollup](data-config.md#time-rollups) that changes has its table made again and filled from its source, which loses no rows, as its comment marks it as Protobase's: only the columns older code reads that it no longer has are named.
691
691
 
692
692
  - `--custom <name>` writes an empty numbered file, `NNN_<name>.sql`, with Protobase's lines and `-- protobase:custom`, for statements you write by hand, and makes the snapshot end at it. Say what it is among its `-- protobase:` lines, which `check` requires: `-- protobase:additive` once it only adds, which `check` verifies with Postgres's own parser, statement by statement, passing only what adds, such as a new table (not `if not exists`, which may find one with rows), a nullable or defaulted column, a plain index, a constraint or unique index on a table the file makes, a new enum value, a trigger dropped and made again on its table, and `create or replace` of a view or function, which Postgres refuses when its columns, arguments or result change; a dropped default, a renamed enum value and a `delete` inside an `insert` or `update` count as taking from older code; or `-- protobase:breaks-older-code` when it takes from older code what it reads, such as a rename or a dropped column. Either way `migrate` records it as not additive unless it says `-- protobase:additive`. Write the statements above the statement that records it, which stays last; `migrate` fills in its hash and whether it is marked additive from the finished file. With `--record-config`, the snapshot takes the sign-in store's names as the config has them now, each module at the step it was: the file is where you make the store match, such as a rename, and it says `-- protobase:breaks-older-code`. With `--after`, it also writes an empty `NNN_<name>.after.sql` beside it, for statements that cannot run in a transaction, such as `create index concurrently if not exists`, which `migrate` runs once the file commits (see [The record of migrations](../guides/deploy.md#the-record-of-migrations)).
693
693
  - `check`, for CI, writes nothing and exits 1 with a line for each problem: a config or Protobase version that needs steps the migrations lack, of the sign-in store or a schema module, or a schema module the snapshot does not record at all, a name the config changed, two files that share a number when Protobase wrote one of them, a snapshot that does not end at the newest file Protobase wrote or whose model does not match its `modelHash`, a hand-written file that says neither `-- protobase:additive` nor `-- protobase:breaks-older-code`, says both, has a statement marked `-- protobase:contract`, which only Protobase writes, or is marked additive while a statement does not only add, and a `-- protobase:contract <id>` that names no file before its own. It also prints a `warning:` line, which leaves the exit code alone, for each statement the `squawk-cli` linter finds that holds a lock blocking reads while it scans or rewrites a table, such as `set not null` or a column type change, and for each statement of a file Protobase wrote that takes from older code without `-- protobase:contract`, such as a formula's column made again.
694
- - `baseline` describes, once, what the project's earlier migrations made that the snapshot does not record: each schema module the config needs, such as a jobs schema an earlier version's `protobase migration` wrote, read from its catalogue as the step pg-boss's version is at and the version Protobase's functions carry, and refused at a pg-boss version no step records, or a change capture, read as its first step once the outbox is there, `capture()` at its version when its body is the one this version writes, and each resource whose table has triggers calling it, which the next `protobase migration` writes again when they are not the ones the config makes, and refused for an outbox without its `database_role` column or a history table without its indexes, or the rollups and formulas, read as their first step once the `rollups` schema is there, and each rollup's column, formula's column, rollup's function and trigger, and time rollup's table and refresh function found, current when it is what this or, for a rollup or formula, an earlier version made of the config, else made again by the next `protobase migration`, as a time rollup an earlier version made is, and refused where the column or table is the project's own or a rollup's column is of another type, or the `derived` schema, read as its first step once its tables, sequence and indexes are there, with each value `derived.declared` marks, and refused without the sequence, the pending table or their indexes, or the schemas of user tables, read as their first step once every part is there, and refused for a definitions table made before organizations, or the tables of webhooks, workflows and notifications, each read as its first step once its tables are there with every index and, for a devices or history table of the app's own, each column under its configured name and the foreign key to the users, the webhooks' functions at the version their comments carry and the workflows' at version 28, the statuses table read as its first step once it has its columns and the foreign key to the users, the calls schema as its first step once its tables are there and its second once its guest tables are too, the `realtime_relay` and `channels` schemas as their first step once their tables are there, `channels.send()` too, the comments, mail feedback and opt-outs tables as their first step once each is there with every index, the query role as its first step once it and the `query` schema are there, with its function at version 1 when it is the one this version writes, owned by the role and not executable by everyone, each resource whose table it reads, and each table it reads that no resource has, which the next `protobase migration` takes back, and the relay's trigger and `realtime.members` functions at their versions with each listed channel whose triggers are the ones this version writes, enabled on its table and its partitions, else written again by the next `protobase migration`, and refused at an older version or shape no step records, such as webhooks without the indexes their version 2 added, a devices table without its session column, a feedback table whose recipient a complaint cannot leave out, or `realtime.members` functions before their version 3; in a project without a snapshot, the sign-in store too. It writes `NNN_baseline.sql`, which changes nothing and records itself, and the snapshot with them, after which `protobase migration` writes only what they lack. For the sign-in store, it starts the snapshot of a project whose store came from auth migrations written before it, such as an app's existing `db/migrations/*_auth.sql`, once: run it with `DATABASE_URL` pointing at the database with those migrations applied. In one read-only transaction it reads the steps the store records in `auth_steps`, or for a store an earlier Protobase made, the versions it records in `auth_migrations`, and the tables of the store's schema, and writes `NNN_baseline.sql`, which drops nothing, changes nothing but making `auth_steps` from `auth_migrations` where the store lacks it, and records itself in `migrations.history`, and `protobase.snapshot.json` describing the store as it is: each module the config has on at the step its recorded versions reach, so the former chain's versions 1 to 8 put each module at its first step; a module that is off but has tables as kept; organizations as ever on when a table whose rows belong to an organization, such as `member`, has the column that names it; and the user table as external when the config reads it through [`users.keyTable`](auth.md#a-view-over-another-systems-users), so no step writes to it; a user table the database has as a view needs `users.keyTable`, naming the table that holds the user ids, and is refused without it. `auth_migrations` stays as it is, read no more. Apply the file with the project's other migrations, then run `protobase migration`, which writes only the steps the store lacks, and nothing for a current store. It refuses a project whose snapshot records every schema module the database has, a store with neither record, one made before 0.48, which [`auth migration`](#auth-migration) adopts first, a version this Protobase does not ship, and a table a recorded step made that the schema lacks under the name the config gives it, such as one renamed since, naming each. <gap>`baseline` cannot refuse a column renamed since a step made it because recording which columns each step adds is not implemented.</gap> The first `protobase migration` after it keeps the organization of each personal access token that has one, and refuses one without, naming it, rather than give it the [default organization](auth.md#the-default-organization): no other column says where a token works.
694
+ - `baseline` describes, once, what the project's earlier migrations made that the snapshot does not record: each schema module the config needs, such as a jobs schema an earlier version's `protobase migration` wrote, read from its catalogue as the step pg-boss's version is at and the version Protobase's functions carry, and refused at a pg-boss version no step records, or a change capture, read as its first step once the outbox is there, `capture()` at its version when its body is the one this version writes, and each resource whose table has triggers calling it, which the next `protobase migration` writes again when they are not the ones the config makes, and refused for an outbox without its `database_role` column or a history table without its indexes, or the rollups and formulas, read as their first step once the `rollups` schema is there, and each rollup's column, formula's column, rollup's function and trigger, and time rollup's table and refresh function found, current when it is what this or, for a rollup or formula, an earlier version made of the config, else made again by the next `protobase migration`, as a time rollup an earlier version made is, and refused where the column or table is the project's own or a rollup's column is of another type, or the `derived` schema, read as its first step once its tables, sequence and indexes are there, with each value `derived.declared` marks, and refused without the sequence, the pending table or their indexes, or the schemas of user tables, read as their first step once every part is there, and refused for a definitions table made before organizations, or the tables of webhooks, workflows and notifications, each read as its first step once its tables are there with every index and, for a devices or history table of the app's own, each column under its configured name and the foreign key to the users, the webhooks' functions at the version their comments carry and the workflows' at version 28, the statuses table read as its first step once it has its columns and the foreign key to the users, the calls schema as its first step once its tables are there and its second once its guest tables are too, the `realtime_relay` and `channels` schemas as their first step once their tables are there, `channels.send()` too, the comments, mail feedback and opt-outs tables as their first step once each is there with every index, the query role as its first step once it and the `query` schema are there, with its function at version 1 when it is the one this version writes, owned by the role and not executable by everyone, each resource whose table it reads, and each table it reads that no resource has, which the next `protobase migration` takes back, and the relay's trigger and `realtime.members` functions at their versions with each listed channel whose triggers are the ones this version writes, enabled on its table and its partitions, else written again by the next `protobase migration`, and refused at an older version or shape no step records, such as webhooks without the indexes their version 2 added, a devices table without its session column, a feedback table whose recipient a complaint cannot leave out, or `realtime.members` functions before their version 3; in a project without a snapshot, the sign-in store too. It writes `NNN_baseline.sql`, which changes nothing and records itself, and the snapshot with them, after which `protobase migration` writes only what they lack. For the sign-in store, it starts the snapshot of a project whose store came from auth migrations written before it, such as an app's existing `db/migrations/*_auth.sql`, once: run it with `DATABASE_URL` pointing at the database with those migrations applied. In one read-only transaction it reads the steps the store records in `auth_steps` and the tables of the store's schema, and writes `NNN_baseline.sql`, which changes nothing and records itself in `migrations.history`, and `protobase.snapshot.json` describing the store as it is: each module the config has on at the step it records; a module that is off but has tables as kept; organizations as ever on when a table whose rows belong to an organization, such as `member`, has the column that names it; and the user table as external when the config reads it through [`users.keyTable`](auth.md#a-view-over-another-systems-users), so no step writes to it; a user table the database has as a view needs `users.keyTable`, naming the table that holds the user ids, and is refused without it. `auth_migrations` stays as it is, read no more. Apply the file with the project's other migrations, then run `protobase migration`, which writes only the steps the store lacks, and nothing for a current store. It refuses a project whose snapshot records every schema module the database has, a store that records versions in `auth_migrations` without `auth_steps`, which Protobase 0.130 moves to `auth_steps` first, a store without either record, one made before 0.48, which [`auth migration`](#auth-migration) adopts first, a version this Protobase does not ship, and a table a recorded step made that the schema lacks under the name the config gives it, such as one renamed since, naming each. <gap>`baseline` cannot refuse a column renamed since a step made it because recording which columns each step adds is not implemented.</gap> The first `protobase migration` after it keeps the organization of each personal access token that has one, and refuses one without, naming it, rather than give it the [default organization](auth.md#the-default-organization): no other column says where a token works.
695
695
  - `drop` deletes the newest file Protobase wrote and takes the snapshot back to the one before it, from that file's lines, or removes the snapshot with the first file. It refuses while two files share a number or the snapshot does not end at the newest file, so it never deletes another branch's file, and after a file that recorded a changed config, or one `contract` or `delete` wrote, whose snapshot before it only version control has.
696
696
  - `up` rewrites the snapshot in this version's format. Every other command refuses a snapshot of an older format, and one of a newer format, which only a newer Protobase reads.
697
697
 
@@ -732,7 +732,7 @@ Prints the app's entry for the apps file of [Realtime](realtime-relay.md), as JS
732
732
  protobase auth migration [--dir db/migrations] [--name auth]
733
733
  ```
734
734
 
735
- Run inside a project, against its database with the project's migrations applied. It reads the steps the store applied from its `auth_steps` table, or for a store an earlier Protobase made, the versions it applied from `auth_migrations`, which the file then records by step in `auth_steps`, and writes the steps of the modules the config has on that it has not, each followed by its row there, as the next migration in `--dir`: `009_auth.sql` after `008_...`, with the store's schema, user table, columns and id type as the config's `auth` names them. Nothing is written when the store is current and the project has a snapshot, nor with sign-in off, when it says so and exits 0. The file only adds, never drops; apply it with the project's other migrations. It starts with Protobase's lines, ends with the statement that records it in `migrations.history`, and starts the project's `protobase.snapshot.json`, or moves it on, with the store at every step, so [`migration`](#migration) goes on from it. A project without a snapshot whose store is current, such as one whose auth migrations an earlier Protobase wrote, gets a file without statements that starts it, and one whose store is current but not in `migrations.history`, such as one migrated before that record, a file that only records it. For a store made before 0.48, with neither record, it writes the step that adopts it once, and refuses one that matches no version, naming what differs. See [migrations](auth.md#migrations).
735
+ Run inside a project, against its database with the project's migrations applied. It reads the steps the store applied from its `auth_steps` table, refusing a store that records versions in `auth_migrations` without it, which Protobase 0.130 moves there first, and writes the steps of the modules the config has on that it has not, each followed by its row there, as the next migration in `--dir`: `009_auth.sql` after `008_...`, with the store's schema, user table, columns and id type as the config's `auth` names them. Nothing is written when the store is current and the project has a snapshot, nor with sign-in off, when it says so and exits 0. The file only adds, and drops nothing but `auth_migrations`, the record of versions `auth_steps` replaced; apply it with the project's other migrations. It starts with Protobase's lines, ends with the statement that records it in `migrations.history`, and starts the project's `protobase.snapshot.json`, or moves it on, with the store at every step, so [`migration`](#migration) goes on from it. A project without a snapshot whose store is current, such as one whose auth migrations an earlier Protobase wrote, gets a file without statements that starts it, and one whose store is current but not in `migrations.history`, such as one migrated before that record, a file that only records it. For a store made before 0.48, with neither record, it writes the step that adopts it once, and refuses one that matches no version, naming what differs. See [migrations](auth.md#migrations).
736
736
 
737
737
  ## `import supabase`
738
738