@protobase/cli 0.117.0 → 0.117.2

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.117.0";
2
+ var version = "0.117.2";
3
3
  //#endregion
4
4
  export { version };
@@ -0,0 +1,37 @@
1
+ import { createsFunction, createsTable, createsTrigger } from "./migration-sql.js";
2
+ import { captureNames, uncapturedMessage } from "@protobase/server/internal";
3
+ //#region src/doctor/capture-files.ts
4
+ /**
5
+ * The change capture the server's startup checks for, judged from the project's migrations (`readMigrationSql`) by the
6
+ * names `checkChanges` looks up in the catalog: `capture()` and the outbox, the history table for history, the notices
7
+ * table for live updates, and each resource's triggers on its table. Only resources whose table a migration creates are
8
+ * judged, each failing with the server's own message; `unjudged` are the others, whose table is the database's to show.
9
+ * A trigger a later migration drops, or one created in dynamic SQL, is judged only with a database.
10
+ */
11
+ const captureFileIssues = (models, events, sql) => {
12
+ const { schema, resources } = captureNames(models, events);
13
+ const judged = resources.filter(({ model }) => createsTable(sql, model.table));
14
+ const setup = createsFunction(sql, schema, "capture") && createsTable(sql, {
15
+ schema,
16
+ name: "outbox"
17
+ });
18
+ const history = createsTable(sql, {
19
+ schema,
20
+ name: "history"
21
+ });
22
+ const notices = createsTable(sql, {
23
+ schema,
24
+ name: "notices"
25
+ });
26
+ const captured = ({ model, triggers }) => setup && triggers.every((trigger) => createsTrigger(sql, trigger, model.table)) && (!model.history || history) && (!model.live || notices);
27
+ return {
28
+ issues: judged.filter((resource) => !captured(resource)).map(({ model }) => ({
29
+ severity: "error",
30
+ resource: model.name,
31
+ message: uncapturedMessage([model.name])
32
+ })),
33
+ unjudged: resources.filter((resource) => !judged.includes(resource)).map(({ model }) => model.name)
34
+ };
35
+ };
36
+ //#endregion
37
+ export { captureFileIssues };
@@ -0,0 +1,32 @@
1
+ import { migrationsDir } from "../migration/migrate-project.js";
2
+ import { existsSync } from "node:fs";
3
+ import path from "node:path";
4
+ import { readFile, readdir } from "node:fs/promises";
5
+ //#region src/doctor/migration-sql.ts
6
+ /**
7
+ * SQL as doctor matches it: without comments, each identifier as Postgres keeps it (a quoted one as written, an unquoted
8
+ * one in lower case), and every run of whitespace one space.
9
+ */
10
+ const normalisedSql = (text) => text.replace(/--[^\n]*/g, " ").replace(/\/\*[\s\S]*?\*\//g, " ").replace(/"((?:[^"]|"")*)"|[A-Za-z_][A-Za-z0-9_$]*/g, (word, quoted) => quoted === void 0 ? word.toLowerCase() : quoted.replaceAll("\"\"", "\"")).replace(/\s+/g, " ");
11
+ /** The project's db/migrations/*.sql in the order they apply, as one normalised text; `undefined` without the folder. */
12
+ const readMigrationSql = async (projectDir) => {
13
+ const dir = path.join(projectDir, migrationsDir);
14
+ if (!existsSync(dir)) return;
15
+ const files = (await readdir(dir)).filter((file) => file.endsWith(".sql")).sort();
16
+ const texts = await Promise.all(files.map((file) => readFile(path.join(dir, file), "utf8")));
17
+ return normalisedSql(texts.join(";\n"));
18
+ };
19
+ const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
20
+ const qualified = ({ schema, name }) => schema && schema !== "public" ? `${escape(schema)}\\.${escape(name)}` : `(?:public\\.)?${escape(name)}`;
21
+ const end = "(?=[\\s(;]|$)";
22
+ /** Whether `sql` creates the table. */
23
+ const createsTable = (sql, table) => new RegExp(`\\bcreate (?:unlogged )?table (?:if not exists )?${qualified(table)}${end}`).test(sql);
24
+ /** Whether `sql` creates a trigger of that name on the table. */
25
+ const createsTrigger = (sql, trigger, table) => new RegExp(`\\bcreate (?:or replace )?(?:constraint )?trigger ${escape(trigger)} [^;]*?\\bon ${qualified(table)}${end}`).test(sql);
26
+ /** Whether `sql` creates the function in the schema. */
27
+ const createsFunction = (sql, schema, name) => new RegExp(`\\bcreate (?:or replace )?function ${qualified({
28
+ schema,
29
+ name
30
+ })} ?\\(`).test(sql);
31
+ //#endregion
32
+ export { createsFunction, createsTable, createsTrigger, normalisedSql, readMigrationSql };
@@ -0,0 +1,28 @@
1
+ import { loadSourceConfig } from "../config/source-config.js";
2
+ import { loadDataConfig } from "../project/load-data-config.js";
3
+ import { builtInModels } from "./built-in-models.js";
4
+ import { unplannedBlocks } from "./page-shapes.js";
5
+ import { checkResourceCount } from "./resource-count.js";
6
+ import { existsSync } from "node:fs";
7
+ import path from "node:path";
8
+ //#region src/doctor/project.ts
9
+ /** The config doctor checks, from `configDir`, the project's protobase.config.ts, and the resources Protobase adds by them. */
10
+ const loadDoctorProject = async (configDir, projectDir) => {
11
+ if (!existsSync(path.join(configDir, "index.ts"))) throw new Error(`No config in ${configDir}: write it with \`protobase scaffold\`, or pass --config <dir>`);
12
+ const config = await loadDataConfig(configDir, projectDir);
13
+ const source = await loadSourceConfig(projectDir, { command: "tool" });
14
+ checkResourceCount(config.models.length, source.resources, `${configDir}/index.ts`);
15
+ return {
16
+ config,
17
+ source,
18
+ builtIn: builtInModels(source, config.models)
19
+ };
20
+ };
21
+ const formatIssue = (issue) => ` ${issue.severity.padEnd(7)} ${issue.resource}: ${issue.message}${issue.suggestion ? `\n fix: ${issue.suggestion}` : ""}\n`;
22
+ /** Each custom component of a page that declares no reads, as a note doctor does not count. */
23
+ const unplannedNotes = ({ config }, models) => {
24
+ const byName = Object.fromEntries(models.map((model) => [model.name, model]));
25
+ return config.pages.flatMap((page) => unplannedBlocks(page, byName)).map((block) => ` note ${block} declares no reads, so it is outside the page's read plan and reads whatever it reads once it draws\n`);
26
+ };
27
+ //#endregion
28
+ export { formatIssue, loadDoctorProject, unplannedNotes };
@@ -0,0 +1,50 @@
1
+ import { projectResources } from "../config/project-parts.js";
2
+ import { userTablesOn } from "../config/user-tables-config.js";
3
+ import { readMigrationSql } from "./migration-sql.js";
4
+ import { captureFileIssues } from "./capture-files.js";
5
+ import { formatIssue, loadDoctorProject, unplannedNotes } from "./project.js";
6
+ import { readShapes } from "./read-shapes.js";
7
+ import { relationIssues } from "./relation-issues.js";
8
+ import { sortIssues } from "./sort-issues.js";
9
+ import { checkServerBuild } from "./startup.js";
10
+ import { configExports } from "@protobase/server";
11
+ //#region src/doctor/run-without-database.ts
12
+ /**
13
+ * The checks `protobase doctor --without-database` makes from the project alone: relations and sorts against the
14
+ * config, the change capture of the app `serve` runs against the project's migrations (`captureFileIssues`), and once
15
+ * those pass, the server's build of the app (`checkServerBuild`), whose refusal ends the run with the server's message.
16
+ * It lists the checks it skipped, which only a database answers.
17
+ */
18
+ const runDoctorWithoutDatabase = async (options, out) => {
19
+ const project = await loadDoctorProject(options.configDir, options.projectDir);
20
+ const { config, source, builtIn } = project;
21
+ const models = [...builtIn.models, ...config.models];
22
+ const shapes = readShapes({
23
+ models,
24
+ views: [...builtIn.views, ...config.views],
25
+ pages: config.pages
26
+ });
27
+ const served = configExports(await projectResources(source)).resources.map((resource) => resource.toModel());
28
+ const capture = captureFileIssues(served, source.events, await readMigrationSql(options.projectDir) ?? "");
29
+ const issues = [...models.flatMap((model) => [...relationIssues(model, models), ...sortIssues(model, shapes)]), ...capture.issues];
30
+ for (const issue of issues) out(formatIssue(issue));
31
+ for (const note of unplannedNotes(project, models)) out(note);
32
+ const errors = issues.filter((i) => i.severity === "error").length;
33
+ if (errors === 0) await checkServerBuild(source);
34
+ const skipped = [
35
+ "the tables, columns, types and keys of the resources, and the indexes their reads need",
36
+ ...userTablesOn(source) ? ["the tables users add"] : [],
37
+ "the server's startup checks of the database's schemas, but for the change capture of the resources whose table a migration creates",
38
+ ...capture.unjudged.length > 0 ? [`the change capture of ${capture.unjudged.join(", ")}, whose table no migration creates`] : []
39
+ ];
40
+ out(`Skipped without a database:\n${skipped.map((check) => ` ${check}\n`).join("")}`);
41
+ out(`Checked ${builtIn.models.length > 0 ? `${config.models.length} resources and ${builtIn.models.length} built-in ones` : `${config.models.length} resources`}${errors === 0 ? ", and the server's build of the app," : ""} without a database: ${errors} errors, ${issues.length - errors} warnings.\n`);
42
+ return {
43
+ errors,
44
+ warnings: issues.length - errors,
45
+ issues,
46
+ skipped
47
+ };
48
+ };
49
+ //#endregion
50
+ export { runDoctorWithoutDatabase };
@@ -1,32 +1,23 @@
1
1
  import { userTablesOn } from "../config/user-tables-config.js";
2
- import { loadSourceConfig } from "../config/source-config.js";
3
2
  import { openAppDatabase } from "../project/pg-db.js";
4
3
  import { connect } from "../db/connect.js";
5
4
  import { introspect } from "../db/introspect.js";
6
- import { loadDataConfig } from "../project/load-data-config.js";
7
- import { readOnlyDb } from "../db/read-only-db.js";
8
- import { builtInIndexIssues, builtInModels } from "./built-in-models.js";
9
- import { checkResource } from "./check.js";
10
- import { fileIndexIssues, indexIssues } from "./index-issues.js";
11
- import { unplannedBlocks } from "./page-shapes.js";
5
+ import { builtInIndexIssues } from "./built-in-models.js";
6
+ import { formatIssue, loadDoctorProject, unplannedNotes } from "./project.js";
12
7
  import { readShapes } from "./read-shapes.js";
13
8
  import { relationIssues } from "./relation-issues.js";
14
- import { checkResourceCount } from "./resource-count.js";
15
9
  import { sortIssues } from "./sort-issues.js";
16
10
  import { checkServerStartup } from "./startup.js";
11
+ import { readOnlyDb } from "../db/read-only-db.js";
12
+ import { checkResource } from "./check.js";
13
+ import { fileIndexIssues, indexIssues } from "./index-issues.js";
17
14
  import { userTableModels } from "./user-table-models.js";
18
- import { existsSync } from "node:fs";
19
- import path from "node:path";
20
15
  import pg from "pg";
21
16
  import { tableIndexes } from "@protobase/query";
22
17
  //#region src/doctor/run.ts
23
- const format = (issue) => ` ${issue.severity.padEnd(7)} ${issue.resource}: ${issue.message}${issue.suggestion ? `\n fix: ${issue.suggestion}` : ""}\n`;
24
18
  const runDoctor = async (options, out) => {
25
- if (!existsSync(path.join(options.configDir, "index.ts"))) throw new Error(`No config in ${options.configDir}: write it with \`protobase scaffold\`, or pass --config <dir>`);
26
- const config = await loadDataConfig(options.configDir, options.projectDir);
27
- const source = await loadSourceConfig(options.projectDir, { command: "tool" });
28
- checkResourceCount(config.models.length, source.resources, `${options.configDir}/index.ts`);
29
- const builtIn = builtInModels(source, config.models);
19
+ const project = await loadDoctorProject(options.configDir, options.projectDir);
20
+ const { config, source, builtIn } = project;
30
21
  const sql = connect(options.url);
31
22
  const tables = await introspect(sql, { views: true }).finally(() => sql.end());
32
23
  const db = readOnlyDb(options.url);
@@ -54,9 +45,8 @@ const runDoctor = async (options, out) => {
54
45
  ...sortIssues(model, shapes),
55
46
  ...indexes[i]
56
47
  ])];
57
- for (const issue of issues) out(format(issue));
58
- const byName = Object.fromEntries(models.map((model) => [model.name, model]));
59
- for (const block of config.pages.flatMap((page) => unplannedBlocks(page, byName))) out(` note ${block} declares no reads, so it is outside the page's read plan and reads whatever it reads once it draws\n`);
48
+ for (const issue of issues) out(formatIssue(issue));
49
+ for (const note of unplannedNotes(project, models)) out(note);
60
50
  const errors = issues.filter((i) => i.severity === "error").length;
61
51
  const startup = options.startupChecks === true && errors === 0;
62
52
  if (startup) {
@@ -1,8 +1,11 @@
1
1
  import { buildProject } from "../config/build-project.js";
2
+ import { projectAdmin } from "../project/project-admin.js";
2
3
  import { servedAdmin } from "../project/served-admin.js";
3
4
  import { checkStartup } from "../serve/startup-checks.js";
5
+ import pg from "pg";
4
6
  import { checkJobsSchema } from "@protobase/server";
5
7
  import { readOrigins, readPasskeyDomain } from "@protobase/server/internal";
8
+ import { Kysely, PostgresDialect } from "kysely";
6
9
  import { randomBytes } from "node:crypto";
7
10
  //#region src/doctor/startup.ts
8
11
  /**
@@ -17,6 +20,26 @@ const startupUrl = (config, env) => {
17
20
  const origin = (auth.origins ?? readOrigins(env))[0];
18
21
  return `${origin ? new URL(origin).protocol : passkeyDomain ? "https:" : "http:"}//${passkeyDomain ?? "localhost"}`;
19
22
  };
23
+ const startupConfig = (config) => ({
24
+ ...config,
25
+ url: startupUrl(config, process.env),
26
+ secret: config.secret ?? randomBytes(32).toString("base64")
27
+ });
28
+ const noDatabase = "postgres://nobody@127.0.0.1:1/none";
29
+ /**
30
+ * Builds the app and its admin from its config as `serve` does, over a pool that never connects: the server's startup
31
+ * refusals the config alone decides, such as an owner field that must hold sign-in's user ids, with the server's own
32
+ * message. What `checkServerStartup` checks of the database is left out.
33
+ */
34
+ const checkServerBuild = async (config) => {
35
+ const pool = new pg.Pool({ connectionString: noDatabase });
36
+ const db = new Kysely({ dialect: new PostgresDialect({ pool }) });
37
+ const build = async () => {
38
+ const project = await buildProject(startupConfig(config), { db });
39
+ await projectAdmin(project, db).admin.stopHolding();
40
+ };
41
+ await build().finally(() => db.destroy());
42
+ };
20
43
  /**
21
44
  * Builds the app from its config over `database` as `serve` does and runs the server's startup checks of the database,
22
45
  * its jobs schema included, so doctor refuses what the server would refuse to start on, with the server's own message.
@@ -26,16 +49,11 @@ const startupUrl = (config, env) => {
26
49
  * doctor's own checks read.
27
50
  */
28
51
  const checkServerStartup = async (config, database) => {
29
- const readOnly = {
30
- ...config,
31
- url: startupUrl(config, process.env),
32
- secret: config.secret ?? randomBytes(32).toString("base64")
33
- };
34
- const project = await buildProject(readOnly, database);
52
+ const project = await buildProject(startupConfig(config), database);
35
53
  await checkStartup(project, database.db);
36
54
  const { admin, jobs } = await servedAdmin(project, database.db);
37
55
  await admin.stopHolding();
38
56
  if (jobs.length > 0) await checkJobsSchema(database.db);
39
57
  };
40
58
  //#endregion
41
- export { checkServerStartup, startupUrl };
59
+ export { checkServerBuild, checkServerStartup, startupUrl };
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { registerAuth } from "./auth/register.js";
2
- import { isConnectionString, resolveConnectionUrl } from "./db/connection-url.js";
2
+ import { defaultConnectionEnv, isConnectionString, resolveConnectionUrl } from "./db/connection-url.js";
3
3
  import { parseHosts } from "./dev/hosts.js";
4
4
  import { loadNearestEnvFile } from "./dev/env.js";
5
5
  import { placeholderSecretWarning } from "./project/placeholder-secret.js";
@@ -50,8 +50,19 @@ program.command("scaffold").description("Generate or update config/<resource>/da
50
50
  excludes: opts.exclude
51
51
  }, out);
52
52
  });
53
- program.command("doctor").description("Check a config folder against the database, and the database against the server's startup checks").argument("[connection]", "connection string (default: DATABASE_URL from the environment or .env)").option("--env <variable>", "read the connection string from this environment variable").option("--config <dir>", "config folder", "config").action(async (connection, opts) => {
53
+ program.command("doctor").description("Check a config folder against the database, and the database against the server's startup checks; with --without-database, what the project alone tells").argument("[connection]", "connection string (default: DATABASE_URL from the environment or .env)").option("--env <variable>", "read the connection string from this environment variable").option("--config <dir>", "config folder", "config").option("--without-database", "check only what the config and the migrations tell, listing the checks skipped").action(async (connection, opts) => {
54
54
  loadNearestEnvFile(process.cwd());
55
+ if (opts.withoutDatabase) {
56
+ if (connection || opts.env) throw new Error("Pass a connection string or --env, or --without-database, not both");
57
+ const { runDoctorWithoutDatabase } = await import("./doctor/run-without-database.js");
58
+ const { errors } = await runDoctorWithoutDatabase({
59
+ configDir: path.resolve(opts.config),
60
+ projectDir: process.cwd()
61
+ }, out);
62
+ if (errors > 0) process.exitCode = 1;
63
+ return;
64
+ }
65
+ if (!connection && !opts.env && !process.env["DATABASE_URL"]) throw new Error(`Pass a connection string or --env <VARIABLE>, or set ${defaultConnectionEnv} in .env; --without-database checks what the project alone tells`);
55
66
  const url = resolveConnectionUrl(connection, opts.env);
56
67
  const { runDoctor } = await import("./doctor/run.js");
57
68
  const { errors } = await runDoctor({
@@ -1,6 +1,6 @@
1
1
  //#region ../mobile/package.json
2
2
  var name = "@protobase/mobile";
3
- var nativeContract = 15;
3
+ var nativeContract = 16;
4
4
  var dependencies = {
5
5
  "@capacitor/android": "8.5.3",
6
6
  "@capacitor/app": "8.1.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.117.0",
3
+ "version": "0.117.2",
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.117.0",
47
- "@protobase/layout": "0.117.0",
48
- "@protobase/query": "0.117.0",
49
- "@protobase/schema": "0.117.0",
50
- "@protobase/server": "0.117.0",
51
- "@protobase/ui": "0.117.0",
52
- "@protobase/workflows": "0.117.0",
46
+ "@protobase/config": "0.117.2",
47
+ "@protobase/layout": "0.117.2",
48
+ "@protobase/query": "0.117.2",
49
+ "@protobase/schema": "0.117.2",
50
+ "@protobase/server": "0.117.2",
51
+ "@protobase/ui": "0.117.2",
52
+ "@protobase/workflows": "0.117.2",
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",
@@ -13,7 +13,7 @@ The sidebar, the user menu, the bottom bar on phones and the global search.
13
13
  - [User menu](../reference/user-menu.md): Account pages, help links, security settings, setting a status, the theme switch and Sign out.
14
14
  - [Bottom bar](../reference/bottom-bar.md): On phones, tabs along the bottom for each role's main screens.
15
15
  - [Phone app layout](../reference/bottom-bar.md#search-and-more): With a bottom bar, More opens the sidebar as a page of its own with search at its top, the top bar takes the app's brand color, and pages that are no tab lead back to More; search can join the bar with `m.search()`.
16
- - [System tab bar](../reference/bottom-bar.md#in-the-ios-app): In the iOS app the bottom bar is the system's own tab bar.
16
+ - [System tab bar](../reference/bottom-bar.md#in-the-phone-apps): In the iOS and Android apps the bottom bar is the system's own tab bar.
17
17
  - [Menus as sheets](../reference/sidebar.md#menus-and-drawers-on-phones): On phones, menus, select lists and the account menu open as a sheet from the bottom, and the sidebar drawer and sheets move under the finger as a native drawer does.
18
18
  - [Global search](../reference/client.md#global-search): A search box, also on Cmd+K or Ctrl+K, finds records in every resource and jumps to pages and New forms.
19
19
  - [Breadcrumbs](../reference/ui-config.md#breadcrumbs): The top bar shows the group and list you are on, each a link back, and on a phone a back button to the one before; a record page's heading names the record.
@@ -20,7 +20,7 @@ Start a new app, or an admin over an existing Postgres database, and keep the co
20
20
  - [Scaffold from a database](../reference/cli.md#scaffold): Reads your Postgres tables and writes the data config for them, with field types, keys, relations, enums, soft delete, tenants and search filled in, and with `--ui` a first view of each.
21
21
  - [Safe re-scaffolding](../reference/cli.md#re-running): Running scaffold again adds only the columns that are not declared yet and leaves your own config code as it is.
22
22
  - [Schema drift report](../reference/cli.md#drift-report): After each scaffold, lists declared fields whose column is gone, whose type changed or whose enum values differ, with a suggested fix.
23
- - [Doctor](../reference/cli.md#doctor): Checks every resource and view against the database, the ones Protobase adds such as webhook subscriptions included, with the reads that lack an index, and prints the fix for each problem. It then runs the server's startup checks, such as the triggers of resources with events, so a project it passes starts.
23
+ - [Doctor](../reference/cli.md#doctor): Checks every resource and view against the database, the ones Protobase adds such as webhook subscriptions included, with the reads that lack an index, and prints the fix for each problem. It then runs the server's startup checks, such as the triggers of resources with events, so a project it passes starts. With `--without-database` it checks what the config and the migrations alone tell, such as relations, sorts and those triggers, and lists the checks it skipped.
24
24
  - [Apps without resources](../reference/config/app.md#resources): An app with no resources on purpose, such as one that only signs people in, says so with `resources: 'none'`, so doctor accepts it while still catching an app that lost its resources by mistake.
25
25
  - [Admin without a view](../guides/table-to-admin.md#1-the-table-as-it-is): A table with an empty view already gives a working admin with every column, sorting, paging, a record page and a New button.
26
26
  - [Agent skills](../reference/cli.md#skill): `protobase skill install` writes agent skills that match the installed version into the project, for the coding agents that work on it.
@@ -202,7 +202,7 @@ An app on Protobase Cloud whose code is on GitHub follows one branch of its repo
202
202
 
203
203
  When a step fails, the previous version keeps serving on the database as it was, except after a failed start, which comes after the migrations committed: they stay applied. Each build reports on GitHub as the check run `Protobase deploy` on the commit it built, with the step that failed and the end of its output. A commit whose build failed is not built again: the fix is a new push.
204
204
 
205
- Since the deploy runs neither the typecheck nor the tests, and refuses what `doctor` refuses, check a change before pushing it: the project's typecheck and tests, `protobase build`, and `protobase doctor --env DATABASE_URL` on a database with the migrations applied, which also runs the server's [startup checks](../reference/cli.md#doctor); on GitHub, [the check action](#check-a-change-before-it-merges) runs them all on every pull request. The migrations run in one transaction, so a statement Postgres refuses in one, such as `create index concurrently`, fails the deploy. Protobase Cloud also pushes to the branch itself, for an update of the app's Protobase packages, so pull before pushing.
205
+ Since the deploy runs neither the typecheck nor the tests, and refuses what `doctor` refuses, check a change before pushing it: the project's typecheck and tests, `protobase build`, and `protobase doctor --env DATABASE_URL` on a database with the migrations applied, which also runs the server's [startup checks](../reference/cli.md#doctor). Without a database, `protobase doctor --without-database` answers what the config and the migrations alone tell, such as a relation to an undeclared resource, a sort by a field that is not sortable or a resource with events whose triggers no migration creates, and lists the checks it skipped, those of the tables, columns, keys and indexes and the rest of the startup checks ([what runs where](../reference/cli.md#doctor)). On GitHub, [the check action](#check-a-change-before-it-merges) runs them all on every pull request. The migrations run in one transaction, so a statement Postgres refuses in one, such as `create index concurrently`, fails the deploy. Protobase Cloud also pushes to the branch itself, for an update of the app's Protobase packages, so pull before pushing.
206
206
 
207
207
  ### Check a change before it merges
208
208
 
@@ -219,11 +219,11 @@ jobs:
219
219
  - uses: PrototeamHQ/protobase/actions/check@main
220
220
  ```
221
221
 
222
- It installs Bun and the app's packages with `bun install --frozen-lockfile`, those of every platform, as the build needs for [native packages](../reference/cli.md#native-packages), then runs the app's `typecheck` and `test` scripts and `protobase build`. It then starts a fresh Postgres 18 of its own in Docker, with a role that is no superuser and may only create in its own database, as a hosted app's is, and runs the app's `db:migrate` (`protobase migrate` without one), the auth schema's migration and `protobase doctor`. Every `protobase` command is the app's own installed CLI, so the checks are those of the version the app deploys with. Each step's output is a group of its own in the log, and the first that fails stops the check with an error naming it, which the action's `failed` output holds too. A script the app does not have is skipped with a notice. The workflow declares no database service and needs no secrets: sign-in gets stand-ins for `PROTOBASE_URL` and `PROTOBASE_SECRET` when the workflow sets none, and doctor does not check the [model key](../reference/ai.md#the-model) of AI fields, which belongs to the deploy's environment.
222
+ It installs Bun and the app's packages with `bun install --frozen-lockfile`, those of every platform, as the build needs for [native packages](../reference/cli.md#native-packages), then runs the app's `typecheck` and `test` scripts and `protobase build`. It then starts a fresh Postgres 18 of its own in Docker, with a role that is no superuser and may only create in its own database, as a hosted app's is, and runs the app's `db:migrate` (`protobase migrate` without one), the auth schema's migration and `protobase doctor`. An app with neither `db/migrations/*.sql` nor a `db:migrate` script brings a database of its own, which a fresh one cannot stand for: for it the action starts no Postgres, skips those migration steps with a notice and runs `protobase doctor --without-database`, which lists the checks only a database answers. Every `protobase` command is the app's own installed CLI, so the checks are those of the version the app deploys with. Each step's output is a group of its own in the log, and the first that fails stops the check with an error naming it, which the action's `failed` output holds too. A script the app does not have is skipped with a notice. The workflow declares no database service and needs no secrets: sign-in gets stand-ins for `PROTOBASE_URL` and `PROTOBASE_SECRET` when the workflow sets none, and doctor does not check the [model key](../reference/ai.md#the-model) of AI fields, which belongs to the deploy's environment.
223
223
 
224
224
  - `working-directory`: the app's folder, for an app that is not at the root of its repository.
225
225
  - `bun-version`: the Bun to install, `latest` by default.
226
226
 
227
- The action needs a Linux runner with Docker, such as `ubuntu-latest`. `@main` follows the action as it changes; a release tag, such as `@v0.99.9`, pins it.
227
+ The action needs a Linux runner with Docker, such as `ubuntu-latest`, for an app with migrations. `@main` follows the action as it changes; a release tag, such as `@v0.99.9`, pins it.
228
228
 
229
229
  [`protobase skill install`](../reference/cli.md#skill) writes the `protobase-cloud` agent skill into the project, with how to check that a change went live and why a deploy failed, step by step.
@@ -33,13 +33,13 @@ Every tab needs its `label`: tabs are narrow, so the bar does not borrow a view'
33
33
 
34
34
  With a bottom bar, a phone works as a phone app does. "More" opens the sidebar as a page of its own, at `/-/menu`, with the bar still there and More the current tab; the app never starts on it, so a restart from More opens the first tab. The top bar takes the app's brand color, the theme's `--primary` with its text in `--primary-foreground`, up behind the status bar: the first tab's page leads with the app's logo and name, More is titled "More", and every page that is no tab leads back to More from its top bar. The top bar has no search button then: with `m.search()` search is part of the bar, and without it the More page has a search field whose results show in place of the sidebar's items.
35
35
 
36
- The bar has five places at most: with search, three tabs, search and More. In the iOS app, where the bar is the system's own tab bar, search is the system's search item after the tabs.
36
+ The bar has five places at most: with search, three tabs, search and More. In the iOS app, where the bar is the system's own tab bar, search is the system's search item after the tabs; in the Android app, whose navigation bar has no search item of its own, search is a tab like the others, in its place.
37
37
 
38
38
  On every phone page, with or without a bottom bar, the account is at the top right of the top bar, the person's avatar or, for a visitor, a guest icon that signs in, rather than at the foot of the sidebar.
39
39
 
40
- ## In the iOS app
40
+ ## In the phone apps
41
41
 
42
- The iOS app draws the bar as the system's tab bar, with the system's own material, through Protobase's `ProtobaseTabBar` plugin: the page sends the tabs it would draw, their icons and the current one each time they change, and the plugin hands a tap back as the tab the page then follows. The page keeps the place of its own bar, unseen, at the height the system bar reports, so nothing ends behind it. The page uses the plugin only where the app's bridge offers it, and draws its own bar otherwise.
42
+ The iOS app draws the bar as the system's tab bar, with the system's own material, and the Android app as the system's navigation bar, in the phone's own colours where it has them, through Protobase's `ProtobaseTabBar` plugin: the page sends the tabs it would draw, their icons and the current one each time they change, and the plugin hands a tap back as the tab the page then follows. The page keeps the place of its own bar, unseen, at the height the system bar reports, the home indicator's or navigation bar's inset included, so nothing ends behind it. The page uses the plugin only where the app's bridge offers it, and draws its own bar otherwise.
43
43
 
44
44
  ## Which bar someone gets
45
45
 
@@ -102,7 +102,7 @@ After each run, declared fields are compared with the database: a column that no
102
102
  ## `doctor`
103
103
 
104
104
  ```sh
105
- protobase doctor [connection string | --env VAR] [--config <dir>]
105
+ protobase doctor [connection string | --env VAR | --without-database] [--config <dir>]
106
106
  ```
107
107
 
108
108
  The URL comes as for [`scaffold`](#scaffold): the connection string, the variable `--env` names, or `DATABASE_URL`, each also read from the nearest `.env`.
@@ -138,7 +138,25 @@ Imports `config/index.ts` and the views of `config/*/ui.ts`, as the config modul
138
138
 
139
139
  Doctor also lists, as a note it does not count, each custom component of a page that declares no [reads](custom-components.md#reads), since it reads outside the page's plan.
140
140
 
141
- When the config has no errors, doctor then builds the app from `protobase.config.ts` and its own `config` folder, whatever `--config` names, as [`serve`](#serve) does and runs the server's startup checks of the database, and stops with the server's own message at the first one that fails: an auth store behind this version, a resource over a table of the auth store, [events](events.md), [history](history.md) or live updates without their triggers, a missing [comments](comments.md#the-table) table, [rollup and formula fields](data-config.md#rollups-and-formulas) without their columns or triggers, and a jobs, webhooks, workflows, notifications, status or user tables schema that is missing or behind. A change that passes doctor so starts. Sign-in is built only to read its store, so doctor needs neither `PROTOBASE_URL` nor `PROTOBASE_SECRET`. The one startup check doctor leaves out is the [model key](ai.md#the-model) of AI fields and actions, which belongs to the environment the app runs in. <gap>Doctor cannot run its checks that need only the config, such as relations and sorts, without a database because a run without a connection is not implemented.</gap>
141
+ When the config has no errors, doctor then builds the app from `protobase.config.ts` and its own `config` folder, whatever `--config` names, as [`serve`](#serve) does and runs the server's startup checks of the database, and stops with the server's own message at the first one that fails: an auth store behind this version, a resource over a table of the auth store, [events](events.md), [history](history.md) or live updates without their triggers, a missing [comments](comments.md#the-table) table, [rollup and formula fields](data-config.md#rollups-and-formulas) without their columns or triggers, and a jobs, webhooks, workflows, notifications, status or user tables schema that is missing or behind. A change that passes doctor so starts. Sign-in is built only to read its store, so doctor needs neither `PROTOBASE_URL` nor `PROTOBASE_SECRET`. The one startup check doctor leaves out is the [model key](ai.md#the-model) of AI fields and actions, which belongs to the environment the app runs in.
142
+
143
+ Without a connection string, `--env` or `DATABASE_URL`, doctor stops and names `--without-database`. With that flag it connects to nothing and checks what the project alone tells:
144
+
145
+ | Check | Without a database | With one |
146
+ | --- | --- | --- |
147
+ | Relations to a resource the config does not declare, sorts by a field that is not `.sortable()`, page components without reads | yes | yes |
148
+ | The triggers, `capture()`, outbox, history and notices tables of resources with events, history or live updates | from `db/migrations/*.sql`, for each resource whose table a migration creates | from the catalog |
149
+ | The server's build of the app, such as an owner field that must hold sign-in's user ids | yes | yes |
150
+ | Tables, columns, types and keys; indexes for the reads; [user tables](user-tables.md); the other startup checks of the database | skipped | yes |
151
+
152
+ From the migrations, a resource passes when they create its table, `capture()` in the changes schema and the outbox, the history table when it keeps history and the notices table when it is live, and a trigger of each name the server looks up on its table; a missing one fails with the server's message, as the startup check does. Statements are matched by name in the files, in any order, so a trigger a later migration drops or one created in dynamic SQL is judged only with a database. A resource whose table no migration creates, as in an app on a database of its own, is left to the database. <gap>Doctor cannot judge the jobs, comments, webhooks, workflows, notifications, status, rollup and other feature schemas without a database because reading their versions from the migration files is not implemented.</gap> Doctor ends with the checks it skipped:
153
+
154
+ ```
155
+ Skipped without a database:
156
+ the tables, columns, types and keys of the resources, and the indexes their reads need
157
+ the server's startup checks of the database's schemas, but for the change capture of the resources whose table a migration creates
158
+ the change capture of notes, whose table no migration creates
159
+ ```
142
160
 
143
161
  Exit code is 1 when there are errors. Run it after the project's migrations and before a new version serves, as a platform's deploy does: a read it fails is one the API would refuse once the version runs. `protobase build` needs no database, so the indexes are doctor's to check.
144
162
 
@@ -59,7 +59,7 @@ Work down the list; the first that matches is the cause.
59
59
  The deploy does not run the project's typecheck or tests, and refuses what doctor refuses, so run them before pushing:
60
60
 
61
61
  1. The project's typecheck and tests.
62
- 2. `protobase doctor --env DATABASE_URL` against a database with the project's migrations applied; exit code 1 means the deploy will be refused, or the new version would not start, since doctor runs the server's startup checks too.
62
+ 2. `protobase doctor --env DATABASE_URL` against a database with the project's migrations applied; exit code 1 means the deploy will be refused, or the new version would not start, since doctor runs the server's startup checks too. With no database at hand, `protobase doctor --without-database` checks what the config and the migrations alone tell, and lists the checks it skipped.
63
63
  3. `protobase build`.
64
64
  4. Migrations that work inside one transaction (no `CONCURRENTLY`), since the deploy runs them all in one.
65
65