@protobase/cli 0.128.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.
- package/dist/auth/migration-file.js +3 -1
- package/dist/auth/write-migration.js +15 -5
- package/dist/cli/package.js +1 -1
- package/dist/dev/entry.js +5 -4
- package/dist/migration/apply-migrations.js +96 -25
- package/dist/migration/baseline/read-live-store.js +36 -0
- package/dist/migration/baseline/write-baseline.js +47 -0
- package/dist/migration/plan-migrations.js +26 -24
- package/dist/migration/record/after-file.js +22 -0
- package/dist/migration/record/fill-row.js +25 -0
- package/dist/migration/record/migration-dir.js +34 -0
- package/dist/migration/record/pending.js +36 -0
- package/dist/migration/record/record-block.js +38 -0
- package/dist/migration/record/run-after.js +23 -0
- package/dist/migration/register.js +20 -2
- package/dist/migration/release/apply-release-steps.js +6 -5
- package/dist/migration/release/release-record.js +30 -0
- package/dist/migration/snapshot/auth-difference.js +9 -2
- package/dist/migration/snapshot/check.js +3 -5
- package/dist/migration/snapshot/custom.js +15 -5
- package/dist/migration/snapshot/drop.js +9 -4
- package/dist/migration/snapshot/migration-files.js +3 -2
- package/dist/migration/snapshot/next-snapshot.js +18 -8
- package/dist/migration/snapshot/run-migration.js +4 -3
- package/dist/migration/snapshot/snapshot-file.js +4 -3
- package/dist/migration/snapshot/write-file.js +20 -4
- package/dist/serve/create-admin.js +3 -2
- package/dist/serve/migrate-release.js +14 -7
- package/dist/serve/startup-checks.js +6 -4
- package/dist/users/set-disabled.js +3 -2
- package/package.json +8 -8
- package/skills/protobase/references/features/build-and-run.md +4 -3
- package/skills/protobase/references/guides/deploy.md +15 -1
- package/skills/protobase/references/reference/auth.md +1 -1
- package/skills/protobase/references/reference/cli.md +10 -8
|
@@ -460,7 +460,7 @@ bun --no-install protobase-serve.js migrate-release <bundle> --plan # print wh
|
|
|
460
460
|
bun --no-install protobase-serve.js migrate-release <bundle> # apply it
|
|
461
461
|
```
|
|
462
462
|
|
|
463
|
-
It loads the bundle's config with the app's settings, as `create-admin` does, and compares every feature the config turns on with the database itself, as [`migration`](#migration) does with `DATABASE_URL` set: the sign-in tables by the versions their `auth_migrations` table records, the jobs, change capture, workflows, notifications and the other built-in schemas by what the database has. It applies what differs in one transaction, behind the lock `migrate` takes, prints each part it applies, such as `applying auth`, or that the database is up to date, so a second run applies nothing. A step whose check refuses the rows already there, such as two From addresses one person entered with different case, stops it with the step's message and exit code 1, and nothing is applied. It refuses a database that lacks any of the bundle's own migrations, since the steps are compared with what they made.
|
|
463
|
+
It loads the bundle's config with the app's settings, as `create-admin` does, and compares every feature the config turns on with the database itself, as [`migration`](#migration) does with `DATABASE_URL` set: the sign-in tables by the versions their `auth_migrations` table records, the jobs, change capture, workflows, notifications and the other built-in schemas by what the database has. It applies what differs in one transaction, then the row that records the release in `migrations.history`, which the server reads at startup, behind the lock `migrate` takes, stopping at once while another run holds it, prints each part it applies, such as `applying auth`, or that the database is up to date, so a second run applies nothing. A step whose check refuses the rows already there, such as two From addresses one person entered with different case, stops it with the step's message and exit code 1, and nothing is applied. It refuses a database that lacks any of the bundle's own migrations, since the steps are compared with what they made.
|
|
464
464
|
|
|
465
465
|
`--plan` applies nothing and prints the same statements as one SQL script, each part under a comment, ending with `-- N steps to apply; nothing was applied`. The script records the sign-in versions it applies itself, so a host can run it in a transaction of its own, such as one it rolls back to try it first, or one it commits while nothing else writes.
|
|
466
466
|
|
|
@@ -652,30 +652,32 @@ For a project with [organizations](auth.md#organizations); `<organization>` is a
|
|
|
652
652
|
protobase migrate [connection string | --env VAR] [--plan]
|
|
653
653
|
```
|
|
654
654
|
|
|
655
|
-
Applies the project's `db/migrations/*.sql` that the database has not applied yet, in file name order, as the runtime's [`migrate`](#build-serve) applies a bundle's:
|
|
655
|
+
Applies the project's `db/migrations/*.sql` that the database has not applied yet, in file name order, as the runtime's [`migrate`](#build-serve) applies a bundle's: behind the same lock, which it only tries, stopping at once while another run holds it, recorded in the same `migrations.applied` and, by each file's own last statement, in `migrations.history` (see [The record of migrations](../guides/deploy.md#the-record-of-migrations)), so a database either one migrated is current for the other. The files apply in batches, each in one transaction, cut after a file with an `.after.sql`, whose statements run outside a transaction before the next batch; a file a stopped run left unfinished is finished first. It prints each file it applies and each `.after.sql` it runs, or that the database is up to date; a project without `db/migrations` applies nothing and says so. It runs none of the project's code, so a project with only `protobase.config.ts`, no `package.json` and nothing installed, migrates as well. The URL comes as for [`scaffold`](#scaffold), and is needed only when there are migrations. A project that still has a `db/migrate.ts` recording in `public.schema_migrations` first copies in the presets' current `db/migrate.ts` and `drop.ts`, so the two keep one record. `--plan` is a dry run: it prints each `.after.sql` left unfinished, then each file not applied yet under its name, with its SQL and its `.after.sql`, from a read-only transaction, and applies and records nothing. <gap>`migrate` cannot report where the tables it touched differ from the record's model, nor refuse a Postgres older than the supported one, because comparing them after applying, and `migration check --database`, are not implemented.</gap>
|
|
656
656
|
|
|
657
657
|
## `migration`
|
|
658
658
|
|
|
659
659
|
:::caution[Beta]
|
|
660
|
-
A project with auth migrations written before the snapshot starts it with
|
|
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
|
-
protobase migration --custom <name> [--record-config]
|
|
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
|
-
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. It writes nothing, the snapshot included, when nothing differs. Apply the file with the project's other migrations.
|
|
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
|
|
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
|
-
- `--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. 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.
|
|
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
|
|
|
@@ -710,7 +712,7 @@ Prints the app's entry for the apps file of [Realtime](realtime-relay.md), as JS
|
|
|
710
712
|
protobase auth migration [--dir db/migrations] [--name auth]
|
|
711
713
|
```
|
|
712
714
|
|
|
713
|
-
Run inside a project, against its database with the project's migrations applied. It reads the versions the store applied from its `auth_migrations` table and writes the auth migrations of this Protobase 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 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. For a store made before 0.48, without `auth_migrations`, it writes the step that adopts it once, and refuses one that matches no version, naming what differs. See [migrations](auth.md#migrations).
|
|
715
|
+
Run inside a project, against its database with the project's migrations applied. It reads the versions the store applied from its `auth_migrations` table and writes the auth migrations of this Protobase 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, without `auth_migrations`, it writes the step that adopts it once, and refuses one that matches no version, naming what differs. See [migrations](auth.md#migrations).
|
|
714
716
|
|
|
715
717
|
## `import supabase`
|
|
716
718
|
|