@protobase/cli 0.55.9 → 0.55.11

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.55.9";
2
+ var version = "0.55.11";
3
3
  //#endregion
4
4
  export { version };
@@ -0,0 +1,29 @@
1
+ import { applyMigrations } from "./apply-migrations.js";
2
+ import { existsSync } from "node:fs";
3
+ import path from "node:path";
4
+ import postgres from "postgres";
5
+ //#region src/migration/migrate-project.ts
6
+ const migrationsDir = "db/migrations";
7
+ /**
8
+ * The CLI's `migrate`: applies the project's db/migrations to the database, as the runtime's `migrate` applies a
9
+ * bundle's (see applyMigrations). It runs none of the project's code, so it needs no package.json or install. The
10
+ * connection is asked for only when there is something to apply.
11
+ */
12
+ const migrateProject = async (projectDir, connectionUrl, out) => {
13
+ const dir = path.join(projectDir, migrationsDir);
14
+ if (!existsSync(dir)) {
15
+ out(`the project has no ${migrationsDir}\n`);
16
+ return;
17
+ }
18
+ const sql = postgres(connectionUrl(), {
19
+ max: 1,
20
+ onnotice: () => {}
21
+ });
22
+ try {
23
+ await applyMigrations(sql, dir, out);
24
+ } finally {
25
+ await sql.end();
26
+ }
27
+ };
28
+ //#endregion
29
+ export { migrateProject, migrationsDir };
@@ -1,8 +1,15 @@
1
+ import { resolveConnectionUrl } from "../db/connection-url.js";
2
+ import { loadNearestEnvFile } from "../dev/env.js";
1
3
  import path from "node:path";
2
4
  //#region src/migration/register.ts
3
5
  const out = (text) => process.stdout.write(text);
4
6
  const collect = (value, previous) => [...previous, value];
5
7
  const registerMigration = (program) => {
8
+ program.command("migrate").description("Apply the project's db/migrations/*.sql not applied yet, in one transaction, as the runtime's migrate applies a bundle's").argument("[connection]", "connection string (default: DATABASE_URL from the environment or .env)").option("--env <variable>", "read the connection string from this environment variable").action(async (connection, opts) => {
9
+ loadNearestEnvFile(process.cwd());
10
+ const { migrateProject } = await import("./migrate-project.js");
11
+ await migrateProject(process.cwd(), () => resolveConnectionUrl(connection, opts.env), out);
12
+ });
6
13
  program.command("migration").description("Write what the database still needs for every feature the config enables (auth, events, jobs) as the project's next SQL migrations").option("--dir <dir>", "migrations folder", "db/migrations").option("--extend <dir>", "merge the protobase.config.ts in this folder before the project's, as dev and build do, repeatable", collect, []).action(async (opts) => {
7
14
  const [{ loadMigrationProject }, { migrationParts }, { writeMigrations }, { migrationSummary }, { resolveExtensions }] = await Promise.all([
8
15
  import("./load-project.js"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.55.9",
3
+ "version": "0.55.11",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -42,12 +42,12 @@
42
42
  "dependencies": {
43
43
  "@better-auth/core": "^1.7.12",
44
44
  "@hono/node-server": "^2.1.3",
45
- "@protobase/config": "0.55.9",
46
- "@protobase/layout": "0.55.9",
47
- "@protobase/query": "0.55.9",
48
- "@protobase/schema": "0.55.9",
49
- "@protobase/server": "0.55.9",
50
- "@protobase/ui": "0.55.9",
45
+ "@protobase/config": "0.55.11",
46
+ "@protobase/layout": "0.55.11",
47
+ "@protobase/query": "0.55.11",
48
+ "@protobase/schema": "0.55.11",
49
+ "@protobase/server": "0.55.11",
50
+ "@protobase/ui": "0.55.11",
51
51
  "@react-email/render": "^2.1.0",
52
52
  "@scalar/hono-api-reference": "^0.12.10",
53
53
  "@tailwindcss/vite": "^4.3.3",
@@ -8,6 +8,7 @@ Develop, build and run an app, on servers, in containers and on phones.
8
8
  - [Dev server](../reference/cli.md#dev): The admin app and the API on one port, with changes shown without a restart.
9
9
  - [Editor types](../reference/cli.md#types): `protobase types` gives the editor and `tsc` the types of the CLI that builds the app, with nothing installed.
10
10
  - [Project scripts](../reference/cli.md#run): `protobase run` runs a seed or a migration script on the CLI's packages.
11
+ - [Migrate command](../reference/cli.md#migrate): `protobase migrate` applies the project's SQL migrations in one transaction, with nothing installed.
11
12
  - [Migrations from config](../reference/cli.md#migration): Writes the SQL migrations for what the config turns on, as files of the project.
12
13
  - [User and organization commands](../reference/cli.md#users): Create users, set roles and manage organizations from the terminal.
13
14
  - [Encryption commands](../reference/cli.md#encryption-status): Report and fix plaintext or old-key values of encrypted fields.
@@ -507,6 +507,14 @@ protobase organizations add-app-role <role> --to owners
507
507
 
508
508
  For a project with [organizations](auth.md#organizations); `<organization>` is a slug or an id. The host acts as a superuser, so it may give any role. `create` makes `--owner` the owner with every app role; `--id` keeps an existing tenant value, and `--members all` adds every other user, superusers as owners and everyone else as a member with their global roles moved onto the membership, for an app that ran as one organization. `remove-member` and `set-roles` refuse to leave an organization without an owner. `add-app-role` gives a role the project added later to every owner.
509
509
 
510
+ ## `migrate`
511
+
512
+ ```sh
513
+ protobase migrate [connection string | --env VAR]
514
+ ```
515
+
516
+ 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: in one transaction behind the same lock, recorded in the same `migrations.applied` (see [Deploy](../guides/deploy.md#migrations)), so a database either one migrated is current for the other. It prints each file it applies, 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.
517
+
510
518
  ## `migration`
511
519
 
512
520
  ```sh
@@ -24,7 +24,7 @@ The server serves the socket when the host gives `createAdmin` its WebSocket upg
24
24
 
25
25
  ## Which tables
26
26
 
27
- A channel may listen to the tables of the resources with [`.live()`](live.md), by `schema` (`*` for any), `table` (every live table of the schema when left out), `event` (`INSERT`, `UPDATE`, `DELETE` or `*`) and `filter`. A table that is not live is refused when the channel joins, with Supabase's message; [`import supabase`](cli.md#import-supabase) makes the tables of the project's `supabase_realtime` publication live. A filter is Supabase's: `column=operator.value`, with `eq`, `neq`, `lt`, `lte`, `gt`, `gte`, `in.(a,b)`, `like`, `ilike`, `match`, `imatch`, `is` and `isdistinct`, `not.` before the operator, and several conditions joined by commas, all of which must hold. Postgres compares each value as the column's type. <gap>A channel cannot `select` columns because that is not supported yet.</gap>
27
+ A channel may listen to the tables of the resources with [`.live()`](live.md), by `schema` (`*` for any), `table` (every live table of the schema when left out), `event` (`INSERT`, `UPDATE`, `DELETE` or `*`) and `filter`. A table that is not live is refused when the channel joins, with Supabase's message; [`import supabase`](cli.md#import-supabase) makes the tables of the project's `supabase_realtime` publication live. A filter is Supabase's: `column=operator.value`, with `eq`, `neq`, `lt`, `lte`, `gt`, `gte`, `in.(a,b)`, `like`, `ilike`, `match`, `imatch`, `is` and `isdistinct`, `not.` before the operator, and several conditions joined by commas, all of which must hold. Postgres compares each value as the column's type. A filter Postgres would refuse under the subscriber's role, such as `id=eq.abc` on an integer column, a column the role may not select or a pattern that does not compile, refuses the join with an error, as on Supabase; one that fails later, such as on a column dropped since, ends only its own channel with an error. <gap>A subscriber's slow `match` or `imatch` pattern cannot be kept from costing the other subscribers of its role a batch of changes because evaluating each pattern once per check is not implemented.</gap> <gap>A channel cannot `select` columns because that is not supported yet.</gap>
28
28
 
29
29
  ## Broadcast and presence
30
30