@protobase/cli 0.129.1 → 0.130.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.
Files changed (99) hide show
  1. package/dist/auth/config-organizations.js +15 -0
  2. package/dist/auth/register.js +8 -2
  3. package/dist/auth/write-migration.js +34 -12
  4. package/dist/cli/package.js +1 -1
  5. package/dist/config/build-project.js +1 -0
  6. package/dist/config/project-modules.js +64 -0
  7. package/dist/config/read-only-queries.js +9 -0
  8. package/dist/config/user-tables-config.js +1 -1
  9. package/dist/dev/dev-jobs.js +12 -6
  10. package/dist/dev/entry.js +12 -19
  11. package/dist/doctor/capture-files.js +3 -3
  12. package/dist/doctor/startup.js +2 -4
  13. package/dist/migration/apply-migrations.js +9 -6
  14. package/dist/migration/baseline/read-live-modules.js +31 -0
  15. package/dist/migration/baseline/read-live-store.js +18 -4
  16. package/dist/migration/baseline/write-baseline.js +50 -17
  17. package/dist/migration/migrate-project.js +3 -3
  18. package/dist/migration/migration-project.js +29 -15
  19. package/dist/migration/older-code/catalog.js +34 -0
  20. package/dist/migration/older-code/contractions.js +86 -0
  21. package/dist/migration/older-code/lint-files.js +55 -0
  22. package/dist/migration/older-code/refusal.js +9 -0
  23. package/dist/migration/older-code/trial.js +58 -0
  24. package/dist/migration/parts.js +8 -104
  25. package/dist/migration/record/after-file.js +20 -2
  26. package/dist/migration/register.js +67 -19
  27. package/dist/migration/release/release-record.js +9 -7
  28. package/dist/migration/release/release-steps.js +15 -3
  29. package/dist/migration/sign-off/contract.js +65 -0
  30. package/dist/migration/sign-off/delete.js +50 -0
  31. package/dist/migration/sign-off/signed-off-file.js +19 -0
  32. package/dist/migration/snapshot/auth-difference.js +135 -15
  33. package/dist/migration/snapshot/auth-target.js +9 -3
  34. package/dist/migration/snapshot/check.js +24 -5
  35. package/dist/migration/snapshot/custom.js +6 -3
  36. package/dist/migration/snapshot/drop.js +7 -2
  37. package/dist/migration/snapshot/header.js +11 -4
  38. package/dist/migration/snapshot/module-changes.js +22 -0
  39. package/dist/migration/snapshot/module-prompts.js +42 -0
  40. package/dist/migration/snapshot/module-sections.js +38 -0
  41. package/dist/migration/snapshot/next-snapshot.js +13 -7
  42. package/dist/migration/snapshot/off-choice.js +11 -0
  43. package/dist/migration/snapshot/organizations-off-facts.js +49 -0
  44. package/dist/migration/snapshot/revival-rows.js +34 -0
  45. package/dist/migration/snapshot/run-migration.js +82 -15
  46. package/dist/migration/snapshot/snapshot-file.js +7 -0
  47. package/dist/migration/snapshot/terminal-prompts.js +21 -0
  48. package/dist/migration/snapshot/write-file.js +1 -1
  49. package/dist/migration/summary.js +3 -2
  50. package/dist/organizations/api.js +4 -2
  51. package/dist/organizations/commands.js +27 -10
  52. package/dist/organizations/pin-source.js +20 -0
  53. package/dist/organizations/pin.js +40 -0
  54. package/dist/organizations/register.js +20 -12
  55. package/dist/scaffold/protobase-tables.js +2 -2
  56. package/dist/serve/create-admin.js +6 -3
  57. package/dist/serve/lifecycle.js +2 -2
  58. package/dist/serve/migrate-release.js +1 -1
  59. package/dist/serve/relay-check.js +7 -8
  60. package/dist/serve/startup-checks.js +12 -22
  61. package/dist/supabase/load-phase.js +3 -1
  62. package/dist/supabase/project-users.js +4 -1
  63. package/dist/users/commands.js +44 -6
  64. package/dist/users/load-auth.js +9 -3
  65. package/dist/users/manage.js +16 -1
  66. package/dist/users/register.js +28 -25
  67. package/dist/users/set-disabled.js +3 -2
  68. package/dist/users/users-api.js +9 -3
  69. package/dist/worker/start-worker.js +7 -4
  70. package/package.json +8 -8
  71. package/skills/protobase/references/features/api-functions.md +1 -0
  72. package/skills/protobase/references/features/build-and-run.md +4 -2
  73. package/skills/protobase/references/features/sign-in-and-accounts.md +2 -1
  74. package/skills/protobase/references/guides/api-functions.md +27 -2
  75. package/skills/protobase/references/guides/deploy.md +2 -2
  76. package/skills/protobase/references/reference/assistant.md +1 -1
  77. package/skills/protobase/references/reference/auth.md +52 -17
  78. package/skills/protobase/references/reference/calls.md +1 -1
  79. package/skills/protobase/references/reference/cli.md +48 -28
  80. package/skills/protobase/references/reference/comments.md +1 -1
  81. package/skills/protobase/references/reference/config/api.md +1 -1
  82. package/skills/protobase/references/reference/config/jobs-and-events.md +1 -1
  83. package/skills/protobase/references/reference/config/sign-in.md +22 -4
  84. package/skills/protobase/references/reference/config.md +1 -1
  85. package/skills/protobase/references/reference/data-config.md +9 -9
  86. package/skills/protobase/references/reference/derived.md +1 -1
  87. package/skills/protobase/references/reference/email.md +2 -2
  88. package/skills/protobase/references/reference/events.md +2 -2
  89. package/skills/protobase/references/reference/history.md +1 -1
  90. package/skills/protobase/references/reference/jobs.md +5 -5
  91. package/skills/protobase/references/reference/live.md +2 -2
  92. package/skills/protobase/references/reference/notifications.md +4 -4
  93. package/skills/protobase/references/reference/personal-access-tokens.md +2 -2
  94. package/skills/protobase/references/reference/realtime-relay.md +1 -1
  95. package/skills/protobase/references/reference/status.md +2 -2
  96. package/skills/protobase/references/reference/supabase-rest.md +1 -1
  97. package/skills/protobase/references/reference/user-tables.md +1 -1
  98. package/skills/protobase/references/reference/webhooks.md +1 -1
  99. package/dist/migration/snapshot/lint-custom.js +0 -23
@@ -49,7 +49,7 @@ Connecting again with `?after=<cursor>` catches up on what was missed while disc
49
49
  A view's change names no record, so the [Realtime socket](supabase-realtime.md) does not send it.
50
50
  :::
51
51
 
52
- A resource backed by a database view, such as a chat thread that merges messages and replies, updates live when the tables it reads change. A view takes no trigger, so name the resources it reads with `.live({ reads })`: a change in any of them refreshes the view's open lists, record pages and related lists, and a change in another table does not.
52
+ A resource backed by a database view, such as a chat thread that merges messages and replies, updates live when the tables it reads change. A view takes no trigger, so name the resources it reads with `.live({ reads })`: a change in any of them refreshes the view's open lists, record pages and related lists, and a change in another table does not. <gap>`protobase migration` cannot refuse a trigger on a resource backed by a view before Postgres refuses it as the file applies because reading which tables are views without a database is not implemented.</gap>
53
53
 
54
54
  ```ts title="config/thread.ts"
55
55
  import { f, resource } from '@protobase/schema'
@@ -80,6 +80,6 @@ Who is on a record's page and what they send each other, which no change of a re
80
80
 
81
81
  ## The table
82
82
 
83
- [`protobase migration`](cli.md#migration) adds the table `changes.notices` to the `changes` schema of the event capture (renamed with `events: { schema }`), and the capture triggers of each live resource and of each resource a live view reads; apply it with the project's other migrations. `protobase dev` and `protobase serve` do not start while the table or a trigger is missing.
83
+ [`protobase migration`](cli.md#migration) adds the table `changes.notices` to the `changes` schema of the event capture (renamed with `events: { schema }`), and the capture triggers of each live resource and of each resource a live view reads; apply it with the project's other migrations. `protobase dev` and `protobase serve` do not start while the record of migrations lacks the table or a trigger.
84
84
 
85
85
  A notice is a resource, a record key, the record's tenant and the operation, written by the `changes.dispatch` job in the transaction that removes the change from the outbox; a live resource therefore needs the [`jobs` schema](jobs.md#the-jobs-schema) and the app's workers. Notices are kept for 10 minutes. Each serving process with at least one page open reads the table once a second, however many pages it serves, so live updates work with several serving processes, with `PROTOBASE_JOBS=false` and through a pooler in transaction mode.
@@ -20,7 +20,7 @@ export default defineConfig({
20
20
  })
21
21
  ```
22
22
 
23
- Then run `protobase migration`, which writes the [devices and history tables](#table-names), and the jobs schema that [sending](#sending) runs on, as a migration of the project's own, and apply it with the project's migrations. `protobase dev` and `protobase serve` refuse to start while a table is missing or lacks what notifications need, and name it. Without `notifications` there is none of it: no endpoints, no tables and no migration.
23
+ Then run `protobase migration`, which writes the [devices and history tables](#table-names), and the jobs schema that [sending](#sending) runs on, as a migration of the project's own, and apply it with the project's migrations. `protobase dev` and `protobase serve` refuse to start while the [record of migrations](../guides/deploy.md#the-record-of-migrations) lacks a table, and name it. Without `notifications` there is none of it: no endpoints, no tables and no migration.
24
24
 
25
25
  Every signed-in user gets [the bell](#the-bell), browsers receive push through [Web Push](#web-push), the Android app through [FCM](#android) and iOS devices through [APNs](#ios). `notifications: { ui: false }` keeps only the backend, [without the bell](#without-the-bell).
26
26
 
@@ -431,7 +431,7 @@ The default store keeps devices in the table `devices` of the schema `notificati
431
431
  | Column | |
432
432
  | --- | --- |
433
433
  | `id` | `uuid`, the id the endpoints answer with |
434
- | `user_id` | the user's id, of the same type as auth's users table's `id`; with Protobase's auth a foreign key to that table, so a deleted user's devices go with them |
434
+ | `user_id` | the user's id: `uuid` when auth's users have uuid ids (`generateUserId: 'uuid'`), else `text`; with Protobase's auth a foreign key to its users table, or the one [`users.keyTable`](auth.md#a-view-over-another-systems-users) names, so a deleted user's devices go with them |
435
435
  | `kind` | `web`, `apns` or `fcm` |
436
436
  | `token` | the token, or a browser's endpoint; unique |
437
437
  | `p256dh`, `auth` | a browser's keys |
@@ -441,7 +441,7 @@ The default store keeps devices in the table `devices` of the schema `notificati
441
441
  | `session_id` | the id of the sign-in session it was registered in, never its token; `NULL` when the app's `authenticate` names none |
442
442
  | `created_at`, `last_seen_at` | when the user registered it, and last refreshed it |
443
443
 
444
- `protobase migration` adds `session_id` to a devices table written before devices kept their session.
444
+ [`protobase migration baseline`](cli.md#migration) refuses a devices table written before devices kept their session or could be relay devices: bring it there with `protobase migration` of Protobase 0.14.2 first.
445
445
 
446
446
  You rename the schema, the table and each column, as auth takes `tables`, such as to keep devices in a table you already have:
447
447
 
@@ -472,4 +472,4 @@ notifications: {
472
472
  },
473
473
  ```
474
474
 
475
- A name is lowercase letters, digits and `_`, at most 63 characters. Startup stops, naming what is wrong, while a table lacks a configured column, while the devices table lacks a unique index on the token column alone, which moving a device relies on, or, with Protobase's auth, while either table lacks the foreign key from its user column to the users table with `on delete cascade`.
475
+ A name is lowercase letters, digits and `_`, at most 63 characters. Once the tables are written, changing a name, or turning Protobase's auth on, is refused, since Protobase does not write renames. `protobase migration baseline`, which records a table you already have, refuses one, naming what is wrong, that lacks a configured column, a devices table without a unique index on the token column alone, which moving a device relies on, or, with Protobase's auth, a table without the foreign key from its user column to the users table with `on delete cascade`.
@@ -19,13 +19,13 @@ export default defineConfig({
19
19
 
20
20
  The prefix is lowercase letters, digits and underscores, ending in `_`, and has no default: name it after the app, so a token found in a log or a commit says where it works. With the setting and no prefix, or a prefix of other characters, the server refuses to start and names the problem.
21
21
 
22
- The tokens live in the auth store's `personal_access_token` table, which every store has from [migration](auth.md#migrations) 8 on, whether the app turns the tokens on or not: `protobase auth migration` writes it for an app upgrading from an earlier Protobase.
22
+ The tokens live in the auth store's `personal_access_token` table, the `personal_access_tokens` module's, which the next [migration](auth.md#migrations) makes once the setting is there. Taking the setting out again keeps the table and its tokens (see [turning a module off](auth.md#turning-a-module-off)): they stay valid unless deleted, and once the setting is back, each acts again for its user as the table below says, refused while the user is banned, the token has expired or the user no longer holds its role.
23
23
 
24
24
  ## Making one
25
25
 
26
26
  The account page's Access tokens tab, at `/-/account/tokens`, lists the person's tokens with their name, when each was made, when it expires and when it was last used, and the role and organization it acts with, and revokes any of them after asking. New token asks for a name and an expiry: in 30 days, in 90 days, in a year, or never. The new token is shown once, to copy: the app keeps only its SHA-256 hash, so nobody can show it again. The tab is not offered in an app without the setting.
27
27
 
28
- A token acts with the role, and with [organizations](auth.md#organizations) the organization, the session that made it works in, as its own tokens would. Someone with several roles who wants a token for another one [switches role](auth.md#active-role) first. Someone with no role there cannot make one (`403 NO_ROLE`).
28
+ A token acts with the role, and with [organizations](auth.md#organizations) the organization, the session that made it works in, as its own tokens would. Someone with several roles who wants a token for another one [switches role](auth.md#active-role) first. Someone with no role there cannot make one (`403 NO_ROLE`). With organizations on, every token belongs to one: a session that works in none cannot make one (`403 NO_ORGANIZATION`).
29
29
 
30
30
  - A session that signed in more than a day ago [confirms it's them](auth.md#confirming-an-account-change) first, in place, since a token acts as them long after that session ends.
31
31
  - A [staff session](auth.md#staff-sign-in) cannot make or revoke a token (`STAFF_CANNOT_CHANGE_SIGN_IN`); it may see the list.
@@ -45,7 +45,7 @@ export default defineConfig(({ env }) => ({
45
45
  | `channels.<resource>.events` | The [events](#client-events) the channel's members may send each other, by name, each with its payload's `schema`, its `maxBytes` and the rate one person may send it at, `perSecond` in bursts of `burst`. |
46
46
  | `presence` | Turns on [presence](#presence): the app's own resource it is kept in, its fields of the person's user id (`user`), the status (`status`) and when it began (`at`), and the bearer token of the relay's reports (`key`), at least 32 characters, which defaults to [`PROTOBASE_REALTIME_PRESENCE_KEY`](#from-the-platform). |
47
47
 
48
- The relay needs the app's own [sign-in](auth.md), whose sessions its tickets name, with its store in the app's own database, as the `auth` config puts it: an auth store in another database is refused. A members resource's changes must be captured, so declare [`.live()`](live.md) on it, and so must a channel resource's whose records list their members; the relay hears of the changes of every resource whose changes are captured, such as a live one, that is a channel resource or has a relation field to one. [`protobase migration`](cli.md#migration) writes the trigger that ends a deleted session's sockets, in the `relay` schema, after the auth store's steps when the same file writes them, so a new app's first migration sets up both. For channel records that list their members it also writes `realtime.members`, keyed by channel and indexed by person, the triggers on their tables that keep it as records are written, deleted, soft-deleted or truncated, and a fill from the records already there. It writes these for an app with `realtime.relay`, and for one with sign-in and a live resource whose conversation page has `members`, which the platform can move to the relay; the server checks them at start while it uses the relay. A trigger left disabled stops the server at start, and the next migration writes it again. A partitioned channel table is kept too: Postgres puts the row trigger on each partition, the migration puts a truncate trigger on each, and a truncated partition writes the resource's members again from the table, so its siblings keep theirs; a partition attached later stops the server at start until the next migration gives it its trigger. A partition, or a table in an inheritance tree, is refused as a channel table. Writes made while the triggers do not fire, such as a restore with `session_replication_role = replica`, are not kept in `realtime.members` until the next migration that writes it again.
48
+ The relay needs the app's own [sign-in](auth.md), whose sessions its tickets name, with its store in the app's own database, as the `auth` config puts it: an app without it is refused. A members resource's changes must be captured, so declare [`.live()`](live.md) on it, and so must a channel resource's whose records list their members; the relay hears of the changes of every resource whose changes are captured, such as a live one, that is a channel resource or has a relation field to one. [`protobase migration`](cli.md#migration) writes the trigger that ends a deleted session's sockets, in the `relay` schema, after the auth store's steps when the same file writes them, so a new app's first migration sets up both. For channel records that list their members it also writes `realtime.members`, keyed by channel and indexed by person, the triggers on their tables that keep it as records are written, deleted, soft-deleted or truncated, and a fill from the records already there. It writes these for an app with `realtime.relay`, and for one with sign-in and a live resource whose conversation page has `members`, which the platform can move to the relay, from the project's snapshot as the relay module: `realtime.members` as a numbered step, the trigger and the functions that keep `realtime.members` at their versions, and each listed channel's triggers, written again when its table or fields change and dropped once it lists its members no more, with its rows. The server refuses to start while the [record of migrations](../guides/deploy.md#the-record-of-migrations) lacks them. [`protobase migration baseline`](cli.md#migration) records what an earlier version wrote, and a listed channel whose trigger it finds disabled, or missing on a partition, as one the next migration writes again. A partitioned channel table is kept too: Postgres puts the row trigger on each partition, the migration puts a truncate trigger on each partition it has when it is applied, and a truncated partition writes the resource's members again from the table, so its siblings keep theirs. <gap>A partition attached after its channel's triggers were written cannot keep its siblings' members when it is truncated because writing its truncate trigger again on attach is not implemented.</gap> Applying the migration fails for a partition, or a table in an inheritance tree, as a channel table. Writes made while the triggers do not fire, such as a restore with `session_replication_role = replica`, are not kept in `realtime.members` until its channel's triggers are written again.
49
49
 
50
50
  [`protobase relay app`](cli.md#relay-app) prints the app's entry for the relay's apps file, from this config, these variables and the app's `url`.
51
51
 
@@ -16,12 +16,12 @@ A status says whether someone wants to be reached: an availability, busy or do n
16
16
  import { defineConfig } from '@protobase/config'
17
17
 
18
18
  export default defineConfig({
19
- auth: { organizations: true },
19
+ auth: { organizations: { enabled: true, default: { id: 'main', name: 'Main', slug: 'main' } } },
20
20
  status: {},
21
21
  })
22
22
  ```
23
23
 
24
- Then run `protobase migration`, which writes the statuses table, `status.statuses`, as a migration of the project's own, and apply it with the project's migrations. `status: { schema: 'presence' }` puts the table in another schema. `protobase dev` and `protobase serve` refuse to start while the table is missing. Without `status` there is none of it: no menu item, no endpoints, no table and no migration, and notifications go out as before.
24
+ Then run `protobase migration`, which writes the statuses table, `status.statuses`, as a migration of the project's own, and apply it with the project's migrations. `status: { schema: 'presence' }` puts the table in another schema. Its user column points at the auth store's users table, or the one [`users.keyTable`](auth.md#a-view-over-another-systems-users) names, and is `uuid` when auth's users have uuid ids, else `text`. `protobase dev` and `protobase serve` refuse to start while the [record of migrations](../guides/deploy.md#the-record-of-migrations) lacks the table. Once it is written, changing `schema` is refused, since Protobase does not write renames. Without `status` there is none of it: no menu item, no endpoints, no table and no migration, and notifications go out as before.
25
25
 
26
26
  People see the statuses of those they share an [organization](auth.md#organizations) with, so status needs organizations: an app without them stops at startup, and `protobase migration` says why.
27
27
 
@@ -29,7 +29,7 @@ The keys are `apiKeys` in `protobase.config.ts`, `{ publishable_key, secret_key
29
29
 
30
30
  The transaction sets the role with `SET LOCAL ROLE` and the token's claims in `request.jwt.claims` and `request.jwt.claim.sub`, so Supabase's `auth.uid()`, `auth.role()` and `auth.jwt()` work, and the tables' RLS policies decide what the request may read and write. The resources' access rules (`.access(...)`) do not apply here: a table needs its own grants and policies, and one without a grant to `anon` or `authenticated` refuses them. The `role` claim is the database role, as on Supabase. The database needs the `anon` and `authenticated` roles, and the app's role must be allowed to `SET ROLE` to them.
31
31
 
32
- `/api/sb/rest/v1` serves the tables the app declares as resources, in the `public` schema, under their table names. Any other table is `404`.
32
+ `/api/sb/rest/v1` serves the tables the app declares as resources, in the `public` schema, under their table names. Any other table is `404`, and so is a table of the auth store, such as its sessions, memberships, invitations and personal access tokens, under the names the app gives them, even when a resource is over it.
33
33
 
34
34
  ## What it understands
35
35
 
@@ -33,7 +33,7 @@ The tables users add and their definitions live in two schemas of the app's data
33
33
  | `table_definitions` | `tables`, one row per table users add, with its singular and plural label, its title field, a version, 1 when it is added, its organization with organizations, and its table's name, and `fields`, each table's fields in order with their label, type and whether they are required, indexed by table and position so a table's fields list in their order |
34
34
  | `user_tables` | the tables themselves, each with an `id bigint generated always as identity` primary key and a column per field, and with organizations an `organization_id` column |
35
35
 
36
- With `userTables: true`, [`protobase migration`](cli.md#migration) writes a migration that adds both schemas, the two definition tables and the `pg_trgm` extension when it is missing, and grants the app's database role CREATE on `user_tables` alone, and writes nothing once the database has them. Apply it with the project's other migrations; the server never creates them itself. At start, `dev` and `serve` stop while one is missing; `PROTOBASE_STARTUP_CHECKS=false` skips that check in `serve`, as it skips the others.
36
+ With `userTables: true`, [`protobase migration`](cli.md#migration) writes both schemas, the two definition tables and the `pg_trgm` extension when it is missing, from the project's snapshot as a numbered step, and grants the app's database role CREATE on `user_tables` alone, and writes nothing once the snapshot has them. Apply it with the project's other migrations; the server never creates them itself. The tables inside `user_tables` are the one exception to schema coming from migrations: admins add them while the app serves, as data. At start, `dev` and `serve` stop while the [record of migrations](../guides/deploy.md#the-record-of-migrations) lacks the schemas; `PROTOBASE_STARTUP_CHECKS=false` skips that check in `serve`, as it skips the others. [`protobase migration baseline`](cli.md#migration) records schemas an earlier version made, and refuses a definitions table made before organizations or without the default of a new version, which no step records.
37
37
 
38
38
  A table's name and each field's name are lowercase letters, digits and `_`, starting with a letter, at most 63 bytes. A field is one of these types:
39
39
 
@@ -116,7 +116,7 @@ It adds two pages, over a `webhooks` schema that [`protobase migration`](cli.md#
116
116
  - **Webhook subscriptions** (`webhook_subscriptions`, the table `webhooks.subscriptions`): a name, the events (`orders.created orders.large`, or `orders.*`), the URL, a filter, extra headers, full or thin payload, and whether it is enabled. The server sets the tenant and the owner, the person who made it, and makes the secret, which only a [reveal](api.md#sensitive-fields-and-audit) shows. Saving checks the events and the filter against the resources, and refuses a URL whose host is a private, loopback or link-local address. Each delivery checks the host's addresses again and connects to the very address it checked, so a host that answers differently by then cannot steer it into the app's own network; a redirect is never followed.
117
117
  - **Webhook deliveries** (`webhook_deliveries`, a view over the delivery jobs): the deliveries that wait for their next try or failed for good, with their last error. A delivery leaves the list once it succeeds.
118
118
 
119
- The migration gives the subscriptions table an index for each sort, filter and search of its list, and creates the `pg_trgm` extension the search's indexes need (`create extension if not exists pg_trgm`, a trusted extension since Postgres 13, so any role that may create in the database can). A database that has an earlier version's schema gets the indexes from the next `protobase migration`; until it is applied the server still starts, and refuses only the list's reads that need them.
119
+ The migration gives the subscriptions table an index for each sort, filter and search of its list, and creates the `pg_trgm` extension the search's indexes need (`create extension if not exists pg_trgm`, a trusted extension since Postgres 13, so any role that may create in the database can). The schema is written from the project's snapshot as numbered steps, the delivery log as its own once `deliveryLog` is on, and the server refuses to start while the [record of migrations](../guides/deploy.md#the-record-of-migrations) lacks them. [`protobase migration baseline`](cli.md#migration) records once a schema an earlier version's migration made, and refuses one without the indexes its version 2 added. Changing `schema` once it is written is refused.
120
120
 
121
121
  Both are scoped to the tenant like any resource with `.tenant()`, and their access decides who may do what: `webhook_subscriptions.create`, `webhook_deliveries.update` and so on, as for the app's own resources. A role's wildcard over resources, such as `*.read`, grants none of them: their URLs and secrets let whoever reads them call the receivers, so with roles only admins (`*`) and roles that [name them](access.md#resources-that-need-named-grants) manage webhook subscriptions.
122
122
 
@@ -1,23 +0,0 @@
1
- import { createRequire } from "node:module";
2
- import { lintSteps } from "@protobase/server/internal";
3
- //#region src/migration/snapshot/lint-custom.ts
4
- const createTable = /^\s*create\s+table\s+(?:if\s+not\s+exists\s+)?((?:(?:"[^"]+"|\w+)\.)?(?:"[^"]+"|\w+))/gim;
5
- /**
6
- * What makes each hand-written migration marked additive unsafe to apply unattended, by the same lint as Protobase's
7
- * own steps (Squawk, with the rules `lintSteps` refuses). A hand-written one that is not marked counts as not additive
8
- * and is not linted.
9
- */
10
- const lintCustomFiles = (files) => {
11
- const additive = files.filter(({ header }) => header?.custom && header.additive);
12
- if (additive.length === 0) return [];
13
- const squawk = createRequire(import.meta.url).resolve("squawk-cli/js/bin/squawk");
14
- const steps = additive.map(({ file, text }) => ({
15
- label: file,
16
- sql: text,
17
- made: [...text.matchAll(createTable)].map((match) => match[1]),
18
- checked: false
19
- }));
20
- return lintSteps(steps, squawk).map(({ step, rule, message }) => `${step} is marked additive and breaks ${rule}: ${message}`);
21
- };
22
- //#endregion
23
- export { lintCustomFiles };