@protobase/cli 0.46.11 → 0.46.12
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/register.js +1 -2
- package/dist/auth/write-migration.js +1 -1
- package/dist/build/app-icons.js +1 -1
- package/dist/build/config-bundle.js +1 -1
- package/dist/build/deploy-bundle.js +2 -2
- package/dist/build/entry-code.js +1 -1
- package/dist/build/plugin-build.js +3 -3
- package/dist/build/plugin-fields.js +1 -1
- package/dist/build/service-worker-code.js +1 -1
- package/dist/build/shell.js +2 -2
- package/dist/build/ui-check.js +2 -2
- package/dist/build/vite-bundle.js +1 -1
- package/dist/bundle/manifest.js +1 -1
- package/dist/cli/package.js +1 -1
- package/dist/db/connect.js +8 -5
- package/dist/dev/entry.js +3 -3
- package/dist/dev/project.js +2 -2
- package/dist/dev/run.js +8 -4
- package/dist/dev/startup-logger.js +24 -0
- package/dist/doctor/run.js +4 -1
- package/dist/encryption/register.js +1 -2
- package/dist/error-message.js +15 -0
- package/dist/files/register.js +1 -2
- package/dist/infer/proposal.js +1 -1
- package/dist/main.js +34 -26
- package/dist/migration/load-project.js +1 -1
- package/dist/migration/register.js +7 -4
- package/dist/migration/summary.js +15 -0
- package/dist/mobile/local-spec.js +1 -1
- package/dist/mobile/run.js +1 -1
- package/dist/mobile/web-part.js +2 -2
- package/dist/mobile/workspace.js +1 -1
- package/dist/notifications/register.js +1 -2
- package/dist/organizations/api.js +15 -0
- package/dist/organizations/register.js +5 -15
- package/dist/project/favicon-link.js +1 -1
- package/dist/project/load-bundle-project.js +2 -2
- package/dist/project/load-data-config.js +2 -2
- package/dist/project/placeholder-secret.js +9 -0
- package/dist/scaffold/existing-config.js +4 -1
- package/dist/scaffold/plan.js +11 -7
- package/dist/scaffold/project.js +2 -1
- package/dist/scaffold/prompt.js +12 -5
- package/dist/scaffold/run.js +1 -1
- package/dist/scaffold/ui-fields.js +3 -0
- package/dist/scaffold/ui-file.js +26 -4
- package/dist/serve/app.js +1 -1
- package/dist/serve/bundle-version.js +1 -1
- package/dist/serve/create-admin.js +3 -3
- package/dist/serve/host-modules.js +5 -5
- package/dist/serve/lifecycle.js +3 -3
- package/dist/serve/mobile-release.js +1 -1
- package/dist/serve/serve-bundle-path.js +1 -1
- package/dist/serve/serve-bundle.js +3 -3
- package/dist/serve/serve-dir.js +2 -2
- package/dist/supabase/dump-phase.js +2 -2
- package/dist/supabase/load-phase.js +2 -2
- package/dist/supabase/register.js +1 -1
- package/dist/supabase/storage-phase.js +1 -1
- package/dist/users/commands.js +7 -1
- package/dist/users/register.js +17 -11
- package/dist/users/users-api.js +2 -1
- package/dist/worker/start-worker.js +2 -2
- package/package.json +6 -6
- package/skills/protobase/SKILL.md +1 -0
- package/skills/protobase/references/getting-started.md +4 -0
- package/skills/protobase/references/guides/existing-database.md +112 -0
- package/skills/protobase/references/reference/cli.md +12 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.46.
|
|
3
|
+
"version": "0.46.12",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@better-auth/core": "^1.7.12",
|
|
37
37
|
"@hono/node-server": "^2.1.3",
|
|
38
38
|
"@hono/vite-dev-server": "^0.26.1",
|
|
39
|
-
"@protobase/layout": "0.46.
|
|
40
|
-
"@protobase/query": "0.46.
|
|
41
|
-
"@protobase/schema": "0.46.
|
|
42
|
-
"@protobase/server": "0.46.
|
|
43
|
-
"@protobase/ui": "0.46.
|
|
39
|
+
"@protobase/layout": "0.46.12",
|
|
40
|
+
"@protobase/query": "0.46.12",
|
|
41
|
+
"@protobase/schema": "0.46.12",
|
|
42
|
+
"@protobase/server": "0.46.12",
|
|
43
|
+
"@protobase/ui": "0.46.12",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -43,6 +43,7 @@ Guides:
|
|
|
43
43
|
- When setting up or running a project for the first time → read [Getting started](references/getting-started.md)
|
|
44
44
|
- When you need to know whether Protobase has a feature, what it is called or how stable it is → read [Features](references/features.md), which links a page per area
|
|
45
45
|
- When shipping a project as a bundle and running it with the serve runtime → read [Deploy](references/guides/deploy.md)
|
|
46
|
+
- When putting an admin on a Postgres database that already exists, from install to the first sign-in → read [Admin over an existing database](references/guides/existing-database.md)
|
|
46
47
|
- When turning a table into an admin with fields, views and filters → read [From a table to an admin](references/guides/table-to-admin.md)
|
|
47
48
|
- When building a page from layouts and blocks → read [Your first composed page](references/guides/first-composed-page.md)
|
|
48
49
|
- When giving customers a page for their plan, cards and invoices → read [A billing page](references/guides/billing-page.md)
|
|
@@ -17,6 +17,10 @@ npm create protobase my-app
|
|
|
17
17
|
npm create protobase my-app -- --preset real-estate
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
## Admin over an existing database
|
|
21
|
+
|
|
22
|
+
For a Postgres database you already have, [Admin over an existing database](guides/existing-database.md) goes from an empty folder to signing in: install the packages, scaffold the config from the tables, check it with `doctor`, add sign-in and its tables, create the first admin and run `protobase dev`.
|
|
23
|
+
|
|
20
24
|
## Docs as Markdown
|
|
21
25
|
|
|
22
26
|
Every page of these docs is also Markdown at its address plus `.md`: `https://docs.protobase.net/reference/cli/` is also `https://docs.protobase.net/reference/cli.md`. The code a page shows from example files is written out in it, and its live demos are left out, so a coding agent or a chat assistant reads the page whole. In a project, [`protobase skill install`](reference/cli.md#skill) gives coding agents the docs of the installed version.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/guides/existing-database.md: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# Admin over an existing database
|
|
4
|
+
|
|
5
|
+
Put an admin on a Postgres database you already have, in six steps, from install to signing in, with every file sign-in needs.
|
|
6
|
+
|
|
7
|
+
You have a Postgres database and want an admin over its tables, without moving the data. This guide goes from an empty folder to signing in to that admin. It takes about fifteen minutes and needs Node 22.12 or later.
|
|
8
|
+
|
|
9
|
+
Protobase never changes your tables. Sign-in is the one thing it adds to the database: an `auth` schema with its own tables for users, sessions and signing keys. `protobase migration` writes them as a SQL file you apply yourself, like any other migration, and the app never changes the schema while it runs.
|
|
10
|
+
|
|
11
|
+
## 1. Install
|
|
12
|
+
|
|
13
|
+
In a new folder, next to the database's own code or anywhere else:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @protobase/cli @protobase/schema @protobase/layout @protobase/server @protobase/ui pg kysely
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then a `.env` beside it, which every `protobase` command reads:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
DATABASE_URL=postgres://user:password@localhost:5432/shop
|
|
23
|
+
# Signs session cookies: generate your own with openssl rand -base64 32
|
|
24
|
+
BETTER_AUTH_SECRET=
|
|
25
|
+
BETTER_AUTH_URL=http://localhost:5173
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Keep `.env` out of version control.
|
|
29
|
+
|
|
30
|
+
## 2. Scaffold the config
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
npx protobase scaffold --ui
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
It reads the tables, read-only, and writes `config/<resource>/data.ts` and `ui.ts` for each one, and `config/index.ts`. In a terminal it asks about each column: press Enter to accept one, `l` to accept it and every one after it. `--yes` accepts them all without asking, and `--dry-run` shows the files without writing them. A table without a primary key, or a unique index on columns that are never null, is skipped with a warning, and so is a view. What it infers is in the [CLI reference](../reference/cli.md#scaffold).
|
|
37
|
+
|
|
38
|
+
## 3. Check it
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
npx protobase doctor
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
It checks the config against the database: each table and column exists, each type fits, and an index serves every filter and sort the admin makes. Each error names the index to add, such as `create index on "public"."orders" ("total");`. Add those with your own migrations, or drop the `.filterable()` or `.sortable()` that needs it.
|
|
45
|
+
|
|
46
|
+
## 4. Add sign-in
|
|
47
|
+
|
|
48
|
+
Two files. `protobase.config.ts` is the project:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import * as config from './config'
|
|
52
|
+
import { auth, authenticate } from './auth/auth'
|
|
53
|
+
|
|
54
|
+
export default { config, auth, authenticate }
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`auth/auth.ts` sets up sign-in with [Better Auth](../reference/auth.md), with its tables in the `auth` schema:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { PostgresDialect } from 'kysely'
|
|
61
|
+
import pg from 'pg'
|
|
62
|
+
import { appPool, betterAuthAuthenticator, createAuth } from '@protobase/server'
|
|
63
|
+
|
|
64
|
+
const secret = process.env.BETTER_AUTH_SECRET
|
|
65
|
+
if (!secret) throw new Error('BETTER_AUTH_SECRET is not set: put the output of `openssl rand -base64 32` in .env')
|
|
66
|
+
|
|
67
|
+
// The app's one pool on DATABASE_URL, which `protobase dev` and `serve` share.
|
|
68
|
+
const pool = appPool(pg, process.env.DATABASE_URL!)
|
|
69
|
+
|
|
70
|
+
export const auth = createAuth({
|
|
71
|
+
// Users, sessions and signing keys live in a schema of their own, next to your tables.
|
|
72
|
+
database: { dialect: new PostgresDialect({ pool }), type: 'postgres', schemaName: 'auth', transaction: true },
|
|
73
|
+
baseURL: process.env.BETTER_AUTH_URL ?? 'http://localhost:5173',
|
|
74
|
+
secret,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
export const authenticate = betterAuthAuthenticator({ auth, tenant: 1 })
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The [auth reference](../reference/auth.md) has the rest: emailed codes, passkeys, two-factor, roles, and a users table the database already has.
|
|
81
|
+
|
|
82
|
+
## 5. Write and apply the auth tables
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
npx protobase migration
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
It compares the database with what sign-in needs and writes `db/migrations/001_auth.sql`: the `auth` schema and its tables. It only adds; it never drops or changes your tables. Read it, then apply it with your migration tool, or with `psql`:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
psql "$DATABASE_URL" -1 -f db/migrations/001_auth.sql
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
After a Protobase upgrade, run `npx protobase migration` again: it writes only what the new version adds, as the next file.
|
|
95
|
+
|
|
96
|
+
## 6. Create the first admin and sign in
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
npx protobase users create you@example.com --generate-password
|
|
100
|
+
npx protobase dev
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The first user is always an admin. The password is printed once. `protobase dev` serves the admin and its API at `http://localhost:5173` (`--port` picks another port); sign in there with that email and password.
|
|
104
|
+
|
|
105
|
+
## Running scaffold again
|
|
106
|
+
|
|
107
|
+
When the database gets a new table or column, run `npx protobase scaffold --ui` again. It adds only what is new, and leaves your edits as they are. It leaves out the `auth` schema of step 5 on its own, and says so, as the sign-in tables are no admin pages. It also reports drift: a declared field whose column has gone, or whose type no longer fits.
|
|
108
|
+
|
|
109
|
+
## Next
|
|
110
|
+
|
|
111
|
+
- [From a table to an admin](table-to-admin.md): names, columns, filters and record pages for the resources you scaffolded.
|
|
112
|
+
- [Deploy](deploy.md): build the app and run it on your own server.
|
|
@@ -12,7 +12,7 @@ bun run protobase <command> # from the project, config folde
|
|
|
12
12
|
bun run --cwd examples/erp protobase <command> # in this repository, for an example
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Any package manager installs the packages, and the command runs on Node or on Bun: `npm install` and `npx protobase <command>` work the same. The bin starts with `#!/usr/bin/env node`, so where Node is installed `bun run protobase` starts it on Node, unless the project's `bunfig.toml` sets `[run] bun = true`, as the presets' does.
|
|
15
|
+
Any package manager installs the packages, and the command runs on Node or on Bun: `npm install` and `npx protobase <command>` work the same. The bin starts with `#!/usr/bin/env node`, so where Node is installed `bun run protobase` starts it on Node, unless the project's `bunfig.toml` sets `[run] bun = true`, as the presets' does. `protobase --version` (or `-v`) prints the Protobase version.
|
|
16
16
|
|
|
17
17
|
## How it runs
|
|
18
18
|
|
|
@@ -27,10 +27,10 @@ The CLI reads the database with `default_transaction_read_only = on`, so it can
|
|
|
27
27
|
## `scaffold`
|
|
28
28
|
|
|
29
29
|
```sh
|
|
30
|
-
protobase scaffold
|
|
30
|
+
protobase scaffold [connection string | --env VAR] [target] [options]
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
`target` is `all` (default), `schema`, `schema.table` or `schema.table.column`. Tables are introspected from `pg_catalog`; `config/<resource>/data.ts` is created or extended.
|
|
33
|
+
Without a connection string or `--env`, the URL is `DATABASE_URL`, from the environment or the nearest `.env` at or above the current directory, as `dev` reads it. `target` is `all` (default), `schema`, `schema.table` or `schema.table.column`. Tables are introspected from `pg_catalog`; `config/<resource>/data.ts` is created or extended.
|
|
34
34
|
|
|
35
35
|
Protobase's own tables are left out, since they hold password hashes, OAuth tokens and signing keys: the `auth` schema, another schema holding Better Auth's `user`, `session`, `account` and `verification` tables (in `public`, only the auth store's tables), and pg-boss's `jobs` schema. A line names each one skipped; a target naming the schema scaffolds it anyway. A resource an earlier run made over one of them gets a warning to remove it.
|
|
36
36
|
|
|
@@ -43,7 +43,9 @@ Protobase's own tables are left out, since they hold password hashes, OAuth toke
|
|
|
43
43
|
| `--ui-list`, `--ui-section <names\|list>` | write only those `ui.ts` sections |
|
|
44
44
|
| `--exclude <schema[.table]>` | skip tables, repeatable |
|
|
45
45
|
|
|
46
|
-
Interactively, each new column shows its proposal: accept, edit (name, type) or ignore (writes `field: null`; key columns cannot be ignored).
|
|
46
|
+
Interactively, each new column shows its proposal: accept, accept all (this one and every one after it, without asking), edit (name, type) or ignore (writes `field: null`; key columns cannot be ignored).
|
|
47
|
+
|
|
48
|
+
The list `--ui` writes shows five columns at most: the key unless it is a uuid, up to two relations, then the other fields but long text, json and audit timestamps. It sorts newest first by a sortable `created_at` (or `inserted_at`, `createdAt`, ...), else by another sortable date or timestamp, else not at all.
|
|
47
49
|
|
|
48
50
|
### Inference
|
|
49
51
|
|
|
@@ -58,10 +60,10 @@ Interactively, each new column shows its proposal: accept, edit (name, type) or
|
|
|
58
60
|
| anything else (`ltree`, arrays, ...) | `f.text().readOnly()` |
|
|
59
61
|
|
|
60
62
|
- `NOT NULL` absent: `.optional()`. Literal default: `.default(v)`.
|
|
61
|
-
- Computed defaults (function, sequence, expression, `GENERATED BY DEFAULT` identity): `.dbDefault()`. It also gets `.readOnly()` when the column is an identity column, a primary-key column, or an audit timestamp (`created_at`, `inserted_at`, `updated_at`, `modified_at`); other computed defaults, such as `order_date DEFAULT current_date`, stay editable. `GENERATED ALWAYS` identity and generated columns are only `.readOnly()`.
|
|
63
|
+
- Computed defaults (function, sequence, expression, `GENERATED BY DEFAULT` identity): `.dbDefault()`. It also gets `.readOnly()` when the column is an identity column, a primary-key column, or an audit timestamp (`created_at`, `inserted_at`, `updated_at`, `modified_at`, or the same in camelCase, such as `createdAt`); other computed defaults, such as `order_date DEFAULT current_date`, stay editable. `GENERATED ALWAYS` identity and generated columns are only `.readOnly()`.
|
|
62
64
|
- Leading column of a non-partial index: `.filterable()`; of a btree: also `.sortable()`. Not applied to json.
|
|
63
65
|
- The text field that names a record (`name`, `title`, `number`, `sku`, `email`, `code` or `description`, else the first text field) becomes the resource's `.search(...)` when a non-partial pg_trgm index (`gin_trgm_ops` or `gist_trgm_ops`) serves it, so the [global search](client.md#global-search) finds its records by name. Without one the API would refuse the search, so it is left out; add the index and run `protobase scaffold` on a new resource, or add `.search` by hand.
|
|
64
|
-
- Key: primary key (composite supported), else the first unique index with only `NOT NULL` columns, else the table is skipped with a warning.
|
|
66
|
+
- Key: primary key (composite supported), else the first unique index with only `NOT NULL` columns, else the table is skipped with a warning. A view or materialized view is skipped with a warning too, as Postgres knows no key for it: declare a resource over one by hand.
|
|
65
67
|
- `deleted_at`, `removed_at`, `archived_at` (nullable timestamp/date) become `.softDelete`; `organization_id` and `tenant_id` become `.tenant`.
|
|
66
68
|
- Unique indexes are listed in the doc comment above the resource.
|
|
67
69
|
- Field names are the column names in snake_case; `.column()` is written only when the schema builder's default mapping would not give the column back (always for `hr."EMP_MASTER"`).
|
|
@@ -78,9 +80,11 @@ After each run, declared fields are compared with the database: a column that no
|
|
|
78
80
|
## `doctor`
|
|
79
81
|
|
|
80
82
|
```sh
|
|
81
|
-
protobase doctor
|
|
83
|
+
protobase doctor [connection string | --env VAR] [--config <dir>]
|
|
82
84
|
```
|
|
83
85
|
|
|
86
|
+
The URL comes as for [`scaffold`](#scaffold): the connection string, the variable `--env` names, or `DATABASE_URL`, each also read from the nearest `.env`.
|
|
87
|
+
|
|
84
88
|
Imports `config/index.ts` and the views of `config/*/ui.ts`, as the config module has them by convention, and checks every exported resource against the database:
|
|
85
89
|
|
|
86
90
|
- error: missing table or column, field type that does not fit the column (a file field needs a text column), table without a usable key, configured key not backed by a unique index
|
|
@@ -105,6 +109,7 @@ protobase dev [--port 5173] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-
|
|
|
105
109
|
|
|
106
110
|
One process, one port: Vite serves the admin app from `@protobase/ui`'s `src/app/` (`dist/app/` when installed; `index.html` and `main.tsx`, or `main.js`; the command fails with a clear message when they are missing) and `@hono/vite-dev-server` mounts the Hono app from `createAdmin` under `/api`, supabase-js's `/api/sb` included. Open `http://localhost:<port>`; the API reference is at `/api/docs`.
|
|
107
111
|
|
|
112
|
+
- **Secret:** a `BETTER_AUTH_SECRET` still set to the placeholder of `.env.example` (`change-me-...`) prints a warning once the server is ready, as `serve` does at start: anyone who knows it can sign session cookies.
|
|
108
113
|
- **Database:** the URL comes from the variable named by `--env`, read from the environment or the nearest `.env` at or above the project. The connection is checked before anything starts; if it fails, the command names host, port and reason (and, when nothing listens there, points to its `db:up` script when it has one). The project needs `pg` installed, because the API connects with Kysely over the project's own `pg`.
|
|
109
114
|
- **Port:** the app listens on `--port` at both `127.0.0.1` and `::1`, since `localhost` is either one depending on the runtime and the browser. When another process holds the port on either address the command stops before it starts and names that address; stop the other server or pass another `--port`.
|
|
110
115
|
- **Cache:** Vite's dependency cache is `node_modules/.vite`; two dev servers sharing it can disturb each other's optimisation, so pass `--cache-dir` for a second one (the integration test does).
|