@protobase/cli 0.129.0 → 0.129.1

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,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.129.0";
2
+ var version = "0.129.1";
3
3
  //#endregion
4
4
  export { version };
@@ -0,0 +1,36 @@
1
+ import postgres from "postgres";
2
+ //#region src/migration/baseline/read-live-store.ts
3
+ /**
4
+ * The auth store at `url` as its schema has it, read once in a read-only transaction: every relation of the store's
5
+ * schema with its kind and columns, and the versions its `auth_migrations` records. Refuses a store without that
6
+ * table, one made before 0.48, which `protobase auth migration` adopts first.
7
+ */
8
+ const readLiveStore = async (url, names) => {
9
+ const sql = postgres(url, {
10
+ max: 1,
11
+ onnotice: () => {}
12
+ });
13
+ const record = names.names.table("auth_migrations");
14
+ try {
15
+ return await sql.begin("read only", async (tx) => {
16
+ const rows = await tx`
17
+ select c.relname as name, c.relkind as kind,
18
+ array(select a.attname::text from pg_catalog.pg_attribute a where a.attrelid = c.oid and a.attnum > 0 and not a.attisdropped order by a.attnum) as columns
19
+ from pg_catalog.pg_class c join pg_catalog.pg_namespace n on n.oid = c.relnamespace
20
+ where n.nspname = coalesce(${names.schema ?? null}::text, current_schema()) and c.relkind in ('r', 'p', 'v', 'm', 'f')`;
21
+ const relations = Object.fromEntries(rows.map(({ name, kind, columns }) => [name, {
22
+ kind,
23
+ columns
24
+ }]));
25
+ if (!relations[record.name]) throw new Error(`The auth store has no ${record.name} table, as a store made before 0.48: adopt it with \`protobase auth migration\` and apply that file first`);
26
+ return {
27
+ versions: (await tx.unsafe(`select ${String(record.columns.version)} as version from ${String(record)} order by 1`)).map(({ version }) => Number(version)),
28
+ relations
29
+ };
30
+ });
31
+ } finally {
32
+ await sql.end();
33
+ }
34
+ };
35
+ //#endregion
36
+ export { readLiveStore };
@@ -0,0 +1,47 @@
1
+ import { readSnapshot, snapshotFile } from "../snapshot/snapshot-file.js";
2
+ import { readMigrationFiles } from "../snapshot/migration-files.js";
3
+ import { refuseInconsistent } from "../snapshot/consistency.js";
4
+ import { writeMigrationFile } from "../snapshot/write-file.js";
5
+ import { readLiveStore } from "./read-live-store.js";
6
+ import { baselineStore, storeModel } from "@protobase/server/internal";
7
+ //#region src/migration/baseline/write-baseline.ts
8
+ const body = `-- Written by \`protobase migration baseline\` from the database: the auth store as the project's earlier migrations made it.
9
+ -- It changes nothing and drops nothing; it starts ${snapshotFile}, and \`protobase migration\` writes what the store lacks from it.
10
+ `;
11
+ /**
12
+ * `protobase migration baseline`: describes the auth store of a project without a snapshot, as its database has it,
13
+ * in a numbered migration that only records itself and the snapshot that ends at it, once. Each module that is on is
14
+ * at the step `auth_migrations` records, a module that is off but has tables is kept, organizations count as ever on
15
+ * when a table whose rows belong to one has the column that names it, and a user table another system made is
16
+ * external. Returns the file's path.
17
+ */
18
+ const writeBaseline = async ({ projectDir, dir, auth, url, protobaseVersion, newId }) => {
19
+ if (await readSnapshot(projectDir)) throw new Error(`The project has ${snapshotFile} already: a baseline only starts it, and \`protobase migration\` goes on from it`);
20
+ refuseInconsistent(void 0, await readMigrationFiles(dir));
21
+ const store = baselineStore(auth.names, await readLiveStore(url, auth.names));
22
+ const decisions = {
23
+ modules: {
24
+ kept: store.kept,
25
+ archived: []
26
+ },
27
+ organizations: {
28
+ everOn: store.organizationsEverOn,
29
+ defaultOrganization: null
30
+ },
31
+ external: store.external
32
+ };
33
+ const draft = {
34
+ previous: void 0,
35
+ auth: storeModel(auth.names, store.lastSteps),
36
+ organizationsOn: auth.organizationsOn,
37
+ protobaseVersion,
38
+ decisions
39
+ };
40
+ return writeMigrationFile(projectDir, dir, {
41
+ name: "baseline",
42
+ body,
43
+ additive: true
44
+ }, draft, newId());
45
+ };
46
+ //#endregion
47
+ export { writeBaseline };
@@ -85,6 +85,22 @@ const registerMigration = (program) => {
85
85
  out(found.map((line) => `${line}\n`).join(""));
86
86
  process.exitCode = 1;
87
87
  });
88
+ folderOptions(migration.command("baseline").description("Start protobase.snapshot.json of a project whose auth migrations came before it from DATABASE_URL, read once, with a numbered migration that changes nothing")).action(async (opts) => {
89
+ const { auth } = await loadAuthTarget(opts);
90
+ if (!auth) throw new Error("sign-in is off in the project's config, so there is no auth store to describe");
91
+ const url = process.env.DATABASE_URL;
92
+ if (!url) throw new Error("No database: set DATABASE_URL to the project's database with its migrations applied");
93
+ const { writeBaseline } = await import("./baseline/write-baseline.js");
94
+ const file = await writeBaseline({
95
+ projectDir: process.cwd(),
96
+ dir: path.resolve(opts.dir),
97
+ auth,
98
+ url,
99
+ protobaseVersion,
100
+ newId: randomUUID
101
+ });
102
+ out(`wrote ${path.relative(process.cwd(), file)} and protobase.snapshot.json: apply it with the project's migrations, then run \`protobase migration\`\n`);
103
+ });
88
104
  migration.command("drop").description("Delete the newest migration `protobase migration` wrote and take protobase.snapshot.json back to the one before it").option("--dir <dir>", "migrations folder", "db/migrations").action(async (opts) => {
89
105
  const { dropMigration } = await import("./snapshot/drop.js");
90
106
  out(`deleted ${await dropMigration(process.cwd(), path.resolve(opts.dir))} and took protobase.snapshot.json back\n`);
@@ -13,6 +13,13 @@ const authRefusals = (snapshot, target) => {
13
13
  if (!target) return [`sign-in is off while ${snapshotFile} has the auth store, and turning it off is not supported yet`];
14
14
  return nameChanges(before, storeModel(target.names, lastStepsOf(before))).map((change) => `the auth store's ${change}`);
15
15
  };
16
+ /** The steps the store lacks after the snapshot's, which leave alone a user table the snapshot records as external. */
17
+ const stepsAfter = (snapshot, target) => {
18
+ const before = snapshot?.model.auth;
19
+ const user = target.names.names.table("user");
20
+ const userName = target.names.schema === void 0 ? user.name : `${target.names.schema}.${user.name}`;
21
+ return offlineStepsMigration(target.names, before && lastStepsOf(before), snapshot?.decisions.external?.includes(userName) ?? false);
22
+ };
16
23
  /** How to write what the steps cannot, once refused. */
17
24
  const customHint = "Write the change by hand with `protobase migration --custom <name> --record-config`.";
18
25
  /**
@@ -27,11 +34,11 @@ const authDifference = (snapshot, target) => {
27
34
  migration: void 0
28
35
  };
29
36
  const before = snapshot?.model.auth;
30
- const migration = offlineStepsMigration(target.names, before && lastStepsOf(before));
37
+ const migration = stepsAfter(snapshot, target);
31
38
  return {
32
39
  migration,
33
40
  model: storeModel(target.names, migration || !before ? latestSteps(target.names.names.modules) : lastStepsOf(before))
34
41
  };
35
42
  };
36
43
  //#endregion
37
- export { authDifference, authRefusals, customHint, lastStepsOf };
44
+ export { authDifference, authRefusals, customHint, lastStepsOf, stepsAfter };
@@ -1,10 +1,9 @@
1
1
  import { readSnapshot, snapshotFile } from "./snapshot-file.js";
2
- import { authRefusals, lastStepsOf } from "./auth-difference.js";
2
+ import { authRefusals, stepsAfter } from "./auth-difference.js";
3
3
  import { readMigrationFiles } from "./migration-files.js";
4
4
  import { inconsistencies } from "./consistency.js";
5
5
  import "../../auth/migration-file.js";
6
6
  import { lintCustomFiles } from "./lint-custom.js";
7
- import { offlineStepsMigration } from "@protobase/server/internal";
8
7
  //#region src/migration/snapshot/check.ts
9
8
  /**
10
9
  * `protobase migration check`, for CI: what keeps the migrations from matching the config, one line each, from the
@@ -15,11 +14,10 @@ const checkMigrations = async (projectDir, dir, auth) => {
15
14
  const snapshot = await readSnapshot(projectDir);
16
15
  const files = await readMigrationFiles(dir);
17
16
  const found = inconsistencies(snapshot, files);
18
- const before = snapshot?.model.auth;
19
17
  const refusals = authRefusals(snapshot, auth);
20
- if (!snapshot && auth && files.some(({ text }) => text.includes("The auth schema changes this version of Protobase needs"))) found.push(`the project has auth migrations from before ${snapshotFile}: start it with \`protobase auth migration\`, against the database with the project's migrations applied`);
18
+ if (!snapshot && auth && files.some(({ text }) => text.includes("The auth schema changes this version of Protobase needs"))) found.push(`the project has auth migrations from before ${snapshotFile}: start it with \`protobase migration baseline\`, against the database with the project's migrations applied`);
21
19
  else if (refusals.length > 0) found.push(...refusals);
22
- else if (auth && offlineStepsMigration(auth.names, before && lastStepsOf(before))) found.push("the config and this version of Protobase need auth store steps the migrations lack: run `protobase migration`");
20
+ else if (auth && stepsAfter(snapshot, auth)) found.push("the config and this version of Protobase need auth store steps the migrations lack: run `protobase migration`");
23
21
  return [...found, ...lintCustomFiles(files)];
24
22
  };
25
23
  //#endregion
@@ -2,9 +2,18 @@ import { modelHash as modelHash$1 } from "./snapshot-file.js";
2
2
  import { lastStepsOf } from "./auth-difference.js";
3
3
  import { storeNamesList } from "@protobase/server/internal";
4
4
  //#region src/migration/snapshot/next-snapshot.ts
5
- /** The snapshot once the migration `endsAt` is applied: `auth`, the store's model then, and whether organizations are on now. */
6
- const nextSnapshot = (previous, auth, organizationsOn, endsAt, protobaseVersion) => {
5
+ const externalUser = (auth) => {
6
+ const user = auth?.modules.auth?.tables.user;
7
+ if (!auth?.userKeyTable || !user) return [];
8
+ return [auth.schema === null ? user.name : `${auth.schema}.${user.name}`];
9
+ };
10
+ /**
11
+ * The snapshot once the migration `endsAt` is applied: `auth`, the store's model then, and whether organizations are
12
+ * on now. It goes on from `before`, the decisions of the snapshot before it, which a baseline reads from the database.
13
+ */
14
+ const nextSnapshot = (before, auth, organizationsOn, endsAt, protobaseVersion) => {
7
15
  const model = auth ? { auth } : {};
16
+ const external = [.../* @__PURE__ */ new Set([...before?.external ?? [], ...externalUser(auth)])].sort();
8
17
  return {
9
18
  format: 1,
10
19
  protobaseVersion,
@@ -12,14 +21,15 @@ const nextSnapshot = (previous, auth, organizationsOn, endsAt, protobaseVersion)
12
21
  modelHash: modelHash$1(model),
13
22
  model,
14
23
  decisions: {
15
- modules: previous?.decisions.modules ?? {
24
+ modules: before?.modules ?? {
16
25
  kept: [],
17
26
  archived: []
18
27
  },
19
28
  organizations: {
20
- everOn: (previous?.decisions.organizations.everOn ?? false) || organizationsOn,
21
- defaultOrganization: previous?.decisions.organizations.defaultOrganization ?? null
22
- }
29
+ everOn: (before?.organizations.everOn ?? false) || organizationsOn,
30
+ defaultOrganization: before?.organizations.defaultOrganization ?? null
31
+ },
32
+ ...external.length > 0 && { external }
23
33
  },
24
34
  physical: auth ? { auth: storeNamesList(auth) } : {}
25
35
  };
@@ -19,7 +19,7 @@ const runMigration = async ({ projectDir, dir, auth, database, protobaseVersion,
19
19
  const snapshot = await readSnapshot(projectDir);
20
20
  const files = await readMigrationFiles(dir);
21
21
  refuseInconsistent(snapshot, files);
22
- if (!snapshot && auth && files.some(({ text }) => text.includes("The auth schema changes this version of Protobase needs"))) throw new Error(`The project has auth migrations from before ${snapshotFile}: start it with \`protobase auth migration\`, run against the database with the project's migrations applied, then run \`protobase migration\` again`);
22
+ if (!snapshot && auth && files.some(({ text }) => text.includes("The auth schema changes this version of Protobase needs"))) throw new Error(`The project has auth migrations from before ${snapshotFile}: start it with \`protobase migration baseline\`, run against the database with the project's migrations applied, then run \`protobase migration\` again`);
23
23
  const difference = authDifference(snapshot, auth);
24
24
  if (database && difference.migration && difference.migration.checks.length > 0) await runPreconditions(database.url, difference.migration.checks);
25
25
  const compared = [];
@@ -14,7 +14,7 @@ import { mkdir, readdir, writeFile } from "node:fs/promises";
14
14
  const writeMigrationFile = async (projectDir, dir, content, draft, id) => {
15
15
  await mkdir(dir, { recursive: true });
16
16
  const file = nextMigrationName(await readdir(dir), content.name);
17
- const snapshot = nextSnapshot(draft.previous, draft.auth, draft.organizationsOn, {
17
+ const snapshot = nextSnapshot(draft.decisions ?? draft.previous?.decisions, draft.auth, draft.organizationsOn, {
18
18
  file,
19
19
  id
20
20
  }, draft.protobaseVersion);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.129.0",
3
+ "version": "0.129.1",
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.129.0",
47
- "@protobase/layout": "0.129.0",
48
- "@protobase/query": "0.129.0",
49
- "@protobase/schema": "0.129.0",
50
- "@protobase/server": "0.129.0",
51
- "@protobase/ui": "0.129.0",
52
- "@protobase/workflows": "0.129.0",
46
+ "@protobase/config": "0.129.1",
47
+ "@protobase/layout": "0.129.1",
48
+ "@protobase/query": "0.129.1",
49
+ "@protobase/schema": "0.129.1",
50
+ "@protobase/server": "0.129.1",
51
+ "@protobase/ui": "0.129.1",
52
+ "@protobase/workflows": "0.129.1",
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",
@@ -12,7 +12,7 @@ Develop, build and run an app, on servers, in containers and on phones.
12
12
  - [Project scripts](../reference/cli.md#run): `protobase run` runs a seed or a migration script on the CLI's packages.
13
13
  - [Migrate command](../reference/cli.md#migrate): `protobase migrate` applies the project's SQL migrations, with nothing installed, and `--plan` prints the SQL it would apply.
14
14
  - [Migrations from config](../reference/cli.md#migration): Writes the SQL migrations for what the config turns on, as files of the project.
15
- - [Schema snapshot](../reference/cli.md#migration) (beta): `protobase.snapshot.json` in the project describes the schema its migrations make, so each new migration is the next numbered file and the change shows in review. The sign-in tables are worked out from it without a database, `protobase migration check` fails CI when the config has a change the migrations lack, and `drop` takes the newest file back.
15
+ - [Schema snapshot](../reference/cli.md#migration) (beta): `protobase.snapshot.json` in the project describes the schema its migrations make, so each new migration is the next numbered file and the change shows in review. The sign-in tables are worked out from it without a database, `protobase migration check` fails CI when the config has a change the migrations lack, `drop` takes the newest file back, and `protobase migration baseline` starts the snapshot of an existing app from its database, once, without changing or dropping anything.
16
16
  - [User and organization commands](../reference/cli.md#users): Create users, set roles and manage organizations from the terminal.
17
17
  - [Encryption commands](../reference/cli.md#encryption-status): Report and fix plaintext or old-key values of encrypted fields.
18
18
  - [One bundle](../reference/cli.md#build): `protobase build` writes one folder with everything the app needs, without a database or secrets. It fails on a view that filters, sorts or searches by a field its resource does not allow.
@@ -657,25 +657,27 @@ Applies the project's `db/migrations/*.sql` that the database has not applied ye
657
657
  ## `migration`
658
658
 
659
659
  :::caution[Beta]
660
- A project with auth migrations written before the snapshot starts it with [`auth migration`](#auth-migration), against its database with those migrations applied; `migration` and `check` refuse such a project until then.
660
+ A project with auth migrations written before the snapshot starts it with `migration baseline`, against its database with those migrations applied; `migration` and `check` refuse such a project until then.
661
661
  :::
662
662
 
663
663
  ```sh
664
664
  protobase migration [--dir db/migrations] [--extend <dir>]
665
665
  protobase migration --custom <name> [--record-config] [--after]
666
666
  protobase migration check
667
+ protobase migration baseline [--dir db/migrations] [--extend <dir>]
667
668
  protobase migration drop
668
669
  protobase migration up
669
670
  ```
670
671
 
671
672
  Writes what the config and this version of Protobase need beyond the project's `protobase.snapshot.json` as the project's next migration in `--dir`: one numbered file each run, named after what it holds, such as `004_auth.sql` or `005_changes_webhooks.sql`, after the folder's highest number, and rewrites the snapshot to end at it, so both show in the pull request. The file starts with lines Protobase reads back: `-- protobase:id`, a random id of its own, then the version that wrote it, each sign-in module's last step, and the hash of the snapshot's model once it is applied. The file ends with the statement that records it in `migrations.history` with the snapshot's model, which the server reads at startup (see [The record of migrations](../guides/deploy.md#the-record-of-migrations)); it counts as additive when it holds only sign-in steps. It writes nothing, the snapshot included, when nothing differs. Apply the file with the project's other migrations.
672
673
 
673
- 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 `physical`, every schema, table, column and index name the store has. 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 version followed by its row in `auth_migrations`. Each runs only while `auth_migrations` lacks its version, 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`. <gap>`protobase migration` cannot write the sign-in store of a project with auth migrations from before `protobase.snapshot.json` because `protobase migration baseline`, which reads the database once to start the snapshot, is not implemented.</gap>
674
+ 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. 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 version followed by its row in `auth_migrations`. Each runs only while `auth_migrations` lacks its version, 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`.
674
675
 
675
676
  The rest of the file is what the other features the config enables still need of the database, compared with it, each under its own comment and named in the file name as in brackets: the [jobs schema](jobs.md#the-jobs-schema) when the config has jobs, `webhooks`, `workflows`, `notifications` or `mailFeedback`, 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) (`jobs`), the table of the bounces and complaints of [`mailFeedback`](email.md#bounces-and-complaints) (`mail_feedback`), the [capture of events](events.md#migrations-and-startup) and the [history table](history.md#the-table) (`changes`), the columns of [rollup and formula fields](data-config.md#rollups-and-formulas), the triggers that keep the rollups, and the tables, indexes and refresh functions of [time rollups](data-config.md#time-rollups) (`computed`), the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as, when it finds the built-in assistant's key (`query`), the [comments table](comments.md#the-table) (`comments`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks` (`webhooks`), the [workflows, versions, runs and steps](workflows.md#turning-them-on) of `workflows` (`workflows`), the [devices and history tables](notifications.md#table-names) of `notifications` (`notifications`), the table of who unsubscribed from bulk mail of [`unsubscribe`](email.md#unsubscribe) (`unsubscribes`), the `realtime_relay` schema of [`realtime: { processes: 'many' }`](supabase-realtime.md#several-processes) (`realtime_relay`), the `channels` schema of [`realtime: { sqlSends: true }`](channels.md#from-sql) (`channel_sends`), the trigger of [`realtime.relay`](realtime-relay.md#sessions) that ends a deleted session's sockets and `realtime.members` with the triggers that keep it from channel records that list their members, also for an app with sign-in and a live resource whose conversation page has `members` (`relay`), and, with [`userTables`](user-tables.md#the-switch), the schemas of user tables (`user_tables`) and the delete of the definitions of tables that resources in code [own now](user-tables.md#taking-a-table-over-as-code) (`owned_definitions`). Those are compared only with `DATABASE_URL` set, against the database with the project's migrations applied, and the command says so without it. <gap>`protobase migration` cannot write the jobs, change capture, rollup and other feature schemas from the snapshot because recording their models in it is not implemented.</gap> It reads the config merged with those of `--extend` as `dev` merges them, and the `.env` nearest the current directory.
676
677
 
677
678
  - `--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. It counts as not additive; once it only adds, put `-- protobase:additive` among its `-- protobase:` lines and `check` lints it with the lint rules Protobase's own steps pass, such as no dropped table or column, no new required column and no unique constraint without a check of the rows. 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. 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)).
678
679
  - `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, 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`, and a hand-written file marked additive that is not.
680
+ - `baseline` starts the snapshot of a project whose sign-in 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 versions the store records in `auth_migrations` and the tables of the store's schema, and writes `NNN_baseline.sql`, which changes nothing and drops nothing and only 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. 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 that has a snapshot already, a store without `auth_migrations`, 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> <gap>`baseline` cannot fill an organization column from organization data a store keeps elsewhere, such as `session.active_organization_id`, because organizations as a tenancy axis of the app's own tables are not implemented.</gap>
679
681
  - `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, whose snapshot before it only version control has.
680
682
  - `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.
681
683