@rehearsal-db/core 0.1.0-beta.4 → 0.1.0-beta.6
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/CHANGELOG.md +55 -1
- package/COMPATIBILITY.md +5 -0
- package/README.md +105 -368
- package/SECURITY.md +2 -1
- package/SUPPORT.md +5 -0
- package/docs/adapters.md +5 -0
- package/docs/baselines.md +81 -22
- package/docs/commands.md +76 -64
- package/docs/configuration.md +47 -4
- package/docs/getting-started.md +87 -218
- package/docs/glossary.md +7 -8
- package/docs/sanitization.md +8 -5
- package/docs/security-model.md +5 -1
- package/docs/troubleshooting.md +46 -1
- package/docs/tutorial.md +70 -59
- package/package.json +5 -3
- package/scripts/lib/rehearsal/baseline_preparation.mjs +138 -23
- package/scripts/lib/rehearsal/configuration.d.mts +18 -3
- package/scripts/lib/rehearsal/configuration.mjs +227 -56
- package/scripts/lib/rehearsal/diagnostics.mjs +4 -2
- package/scripts/lib/rehearsal/input_discovery.mjs +155 -0
- package/scripts/lib/rehearsal/plan.mjs +85 -10
- package/scripts/lib/rehearsal/policy_review.mjs +45 -5
- package/scripts/lib/rehearsal/runtime_restore.mjs +6 -2
- package/scripts/lib/rehearsal/setup.mjs +60 -28
- package/scripts/lib/rehearsal/support_report.mjs +102 -0
- package/scripts/lib/runtime/postgresql_runtime.mjs +772 -0
- package/scripts/lib/runtime/runtime_target.mjs +41 -0
- package/scripts/lib/runtime/supabase_runtime.mjs +790 -0
- package/scripts/operations/database/manage_rehearsal_database.mjs +6 -785
- package/scripts/operations/rehearsal/rehearsal_cli.mjs +522 -149
package/docs/baselines.md
CHANGED
|
@@ -1,33 +1,92 @@
|
|
|
1
1
|
# Baselines
|
|
2
2
|
|
|
3
|
-
A baseline is
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
A baseline is the locked starting point for every rehearsal. It combines safe rows with
|
|
4
|
+
the exact historical migrations that created their schema. Resetting the runtime always
|
|
5
|
+
returns to this point.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Required inputs
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
and made read-only. A complete manifest is verified before an atomic `current` symlink
|
|
11
|
-
selects the generation. An interrupted build cannot replace the active baseline.
|
|
9
|
+
### Records
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
Records use NDJSON: one complete JSON object per line. Each object names a table and one
|
|
12
|
+
safe row.
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
```json
|
|
15
|
+
{ "table": "widgets", "row": { "id": 1, "name": "Synthetic Widget" } }
|
|
16
|
+
```
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
Use synthetic or reviewed sanitized values. A `.json` array is not NDJSON and will be
|
|
19
|
+
rejected.
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
schema, streams sanitized rows, restores checksummed local Storage assets, reapplies
|
|
23
|
-
normal enforcement, and verifies counts and foreign keys. A failure removes trust and
|
|
24
|
-
cannot leave a successful receipt.
|
|
21
|
+
### Migration ledger
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
The ledger is a JSON array in migration order:
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
```json
|
|
26
|
+
[
|
|
27
|
+
{
|
|
28
|
+
"version": "20260101000000",
|
|
29
|
+
"name": "create_widgets",
|
|
30
|
+
"statements": [
|
|
31
|
+
"create table public.widgets (id bigint primary key, name text not null)"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
```
|
|
31
36
|
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
Each entry must match the version, name, order, and SQL represented by the historical
|
|
38
|
+
migration. Equivalent-looking SQL is not enough. Generate this evidence with reviewed
|
|
39
|
+
project tooling for a real migration history; do not reconstruct a large ledger by hand.
|
|
40
|
+
|
|
41
|
+
### Sanitization policy
|
|
42
|
+
|
|
43
|
+
The policy records the approved treatment of every included table and column. The guide
|
|
44
|
+
can create a shape-only draft from the records and walk you through its review. A draft
|
|
45
|
+
with undecided fields cannot become a baseline. See [Sanitization](sanitization.md).
|
|
46
|
+
|
|
47
|
+
### Storage manifest (optional)
|
|
48
|
+
|
|
49
|
+
Supabase projects may include a bounded set of approved local Storage files. Plain
|
|
50
|
+
PostgreSQL projects do not support Supabase Storage. Every file is checksum-verified and
|
|
51
|
+
must remain inside the project.
|
|
52
|
+
|
|
53
|
+
## Create a baseline
|
|
54
|
+
|
|
55
|
+
The guided action is recommended:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx rehearsal
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
For automation, use explicit safe local paths:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npx rehearsal baseline create \
|
|
65
|
+
--records=rehearsal/sanitized-data.ndjson \
|
|
66
|
+
--ledger=rehearsal/migration-ledger.json
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Add `--assets=rehearsal/assets.json` only when using approved Supabase Storage files.
|
|
70
|
+
Rehearsal validates everything and shows counts before activation. It never extracts data.
|
|
71
|
+
|
|
72
|
+
## Why historical migrations are locked
|
|
73
|
+
|
|
74
|
+
The baseline records the exact ordered historical migration files. If a file keeps the
|
|
75
|
+
same timestamp but its bytes change, Rehearsal reports modified history instead of
|
|
76
|
+
treating it as a new candidate. New migrations must form an ordered suffix after the
|
|
77
|
+
baseline cutoff.
|
|
78
|
+
|
|
79
|
+
## What reset does
|
|
80
|
+
|
|
81
|
+
`reset` removes only the exactly labeled local runtime, rebuilds the represented schema,
|
|
82
|
+
loads the safe rows, restores approved Storage files when present, and verifies counts and
|
|
83
|
+
relationships. A failed restore cannot produce a successful receipt.
|
|
84
|
+
|
|
85
|
+
The baseline itself never changes during normal use. Runtime edits persist until you
|
|
86
|
+
reset or discard that runtime.
|
|
87
|
+
|
|
88
|
+
## Storage and privacy
|
|
89
|
+
|
|
90
|
+
Baseline files can still be sensitive after sanitization. Rehearsal stores them under the
|
|
91
|
+
ignored `.rehearsal/` directory with checksums and read-only files. Keep them off shared
|
|
92
|
+
drives, use encrypted disks, retain them only as long as needed, and never commit them.
|
package/docs/commands.md
CHANGED
|
@@ -1,66 +1,78 @@
|
|
|
1
1
|
# CLI commands
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
| `rehearsal
|
|
24
|
-
| `rehearsal
|
|
25
|
-
| `
|
|
26
|
-
| `rehearsal
|
|
27
|
-
| `rehearsal
|
|
28
|
-
| `rehearsal
|
|
29
|
-
| `
|
|
30
|
-
| `rehearsal
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
`
|
|
60
|
-
the
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
3
|
+
Run commands from the project directory containing `rehearsal.config.mjs`. The examples
|
|
4
|
+
use `npx`, so a global install is not required.
|
|
5
|
+
|
|
6
|
+
## Guided mode
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npx rehearsal
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The guide reads the current project state and recommends the next useful action. It stays
|
|
13
|
+
open after each action. Press `Ctrl+Z` at a prompt to exit the entire session.
|
|
14
|
+
|
|
15
|
+
Use `npx rehearsal guide` for the same screen or add `--plain` to use numbered menus
|
|
16
|
+
without decorative terminal styling. When input or output is not an interactive terminal,
|
|
17
|
+
bare `npx rehearsal` prints help instead of waiting for input.
|
|
18
|
+
|
|
19
|
+
## Setup and baseline
|
|
20
|
+
|
|
21
|
+
| Command | What it does |
|
|
22
|
+
| ----------------------------------------------------------------- | ------------------------------------------------------ |
|
|
23
|
+
| `npx rehearsal setup --target=supabase` | Preview Supabase setup files. |
|
|
24
|
+
| `npx rehearsal setup --target=postgresql` | Preview PostgreSQL setup files. |
|
|
25
|
+
| Add `--write` to either setup command | Create the previewed files without overwriting. |
|
|
26
|
+
| `npx rehearsal init` | Preview only `rehearsal.config.mjs`. |
|
|
27
|
+
| `npx rehearsal init --write` | Create only `rehearsal.config.mjs`. |
|
|
28
|
+
| `npx rehearsal baseline prepare --records=<path> --ledger=<path>` | Preview a sanitization-policy draft. |
|
|
29
|
+
| Add `--write` to `baseline prepare` | Write the draft for human review. |
|
|
30
|
+
| `npx rehearsal baseline create --records=<path> --ledger=<path>` | Create and activate a baseline from safe local inputs. |
|
|
31
|
+
|
|
32
|
+
Add `--assets=<manifest.json>` to `baseline create` only for approved local Supabase
|
|
33
|
+
Storage files. Baseline commands never extract data or connect to another database.
|
|
34
|
+
|
|
35
|
+
## Check and inspect
|
|
36
|
+
|
|
37
|
+
| Command | What it does |
|
|
38
|
+
| ---------------------------------- | ----------------------------------------------------- |
|
|
39
|
+
| `npx rehearsal doctor` | Check dependencies, inputs, and safety rules. |
|
|
40
|
+
| `npx rehearsal support` | Print a privacy-safe report for a support request. |
|
|
41
|
+
| `npx rehearsal explain` | Show the exact plan without changing anything. |
|
|
42
|
+
| `npx rehearsal run --dry-run` | Show the same non-mutating plan. |
|
|
43
|
+
| `npx rehearsal candidates` | List pending migrations and their approval digest. |
|
|
44
|
+
| `npx rehearsal inspect baseline` | Show baseline metadata without row values. |
|
|
45
|
+
| `npx rehearsal inspect migrations` | Classify every historical and candidate migration. |
|
|
46
|
+
| `npx rehearsal status` | Report baseline, candidates, and local runtime state. |
|
|
47
|
+
|
|
48
|
+
State-reporting commands accept `--json` for scripts. Scripts should use the JSON fields
|
|
49
|
+
and process exit code, not parse human-facing text.
|
|
50
|
+
|
|
51
|
+
## Run and manage the local database
|
|
52
|
+
|
|
53
|
+
| Command | What it does |
|
|
54
|
+
| ----------------------------------------------------- | ------------------------------------------------------------------- |
|
|
55
|
+
| `npx rehearsal run --confirm-candidates=<sha256>` | Reset, apply the exact candidates, verify, and run the app proof. |
|
|
56
|
+
| `npx rehearsal migrate --confirm-candidates=<sha256>` | Apply the exact candidates without resetting existing runtime data. |
|
|
57
|
+
| `npx rehearsal start` | Start an existing verified runtime. |
|
|
58
|
+
| `npx rehearsal verify` | Verify the current runtime and receipt. |
|
|
59
|
+
| `npx rehearsal reset` | Discard runtime edits and restore the baseline. |
|
|
60
|
+
| `npx rehearsal stop` | Stop the runtime but keep its local state. |
|
|
61
|
+
| `npx rehearsal discard` | Remove this project's disposable runtime and volume. |
|
|
62
|
+
|
|
63
|
+
In a terminal, the guide displays candidate filenames and asks for confirmation. In a
|
|
64
|
+
script, copy the digest from `candidates` into `--confirm-candidates`. Adding, removing,
|
|
65
|
+
reordering, or editing a migration changes that digest.
|
|
66
|
+
|
|
67
|
+
## Common options
|
|
68
|
+
|
|
69
|
+
| Option | Meaning |
|
|
70
|
+
| ------------------------------- | ---------------------------------------------------------------- |
|
|
71
|
+
| `--json` | Return the versioned machine-readable result. |
|
|
72
|
+
| `--verbose` | Show more safe detail. |
|
|
73
|
+
| `--debug` | Show the most diagnostic detail; still review it before sharing. |
|
|
74
|
+
| `--plain` | Disable decorative interactive prompts. |
|
|
75
|
+
| `--config=<path>` | Use a specific config file inside the project. |
|
|
76
|
+
| `--target=supabase\|postgresql` | Choose the setup target. |
|
|
77
|
+
|
|
78
|
+
Run `npx rehearsal --help` to print the command list available in your installed version.
|
package/docs/configuration.md
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
# Configuration reference
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Most users should let the guide create this file:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx rehearsal
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Use this page when reviewing or changing the generated `rehearsal.config.mjs`. The schema
|
|
10
|
+
is strict: misspelled fields, unknown fields, and unsupported versions are errors. The
|
|
11
|
+
`.mjs` extension works in both CommonJS and ESM projects.
|
|
7
12
|
|
|
8
13
|
```ts
|
|
9
14
|
import { defineRehearsalConfig } from "@rehearsal-db/core";
|
|
@@ -26,6 +31,7 @@ export default defineRehearsalConfig({
|
|
|
26
31
|
proofCommand: "npm run test:rehearsal",
|
|
27
32
|
},
|
|
28
33
|
runtime: {
|
|
34
|
+
target: "supabase",
|
|
29
35
|
applicationUrl: "http://localhost:5175",
|
|
30
36
|
projectId: "example-app-rehearsal",
|
|
31
37
|
apiPort: 58321,
|
|
@@ -42,6 +48,9 @@ All paths resolve inside the consuming project. The artifact directory must be n
|
|
|
42
48
|
`.rehearsal`; this is an intentional deletion guard. `runtimeWorkdir` must be its
|
|
43
49
|
`runtime` child, and the generated application environment file must remain inside it.
|
|
44
50
|
|
|
51
|
+
Rehearsal never overwrites this config. To start over, move the existing file somewhere
|
|
52
|
+
safe, run setup again, and compare the two files before deleting either one.
|
|
53
|
+
|
|
45
54
|
## Supabase service environment
|
|
46
55
|
|
|
47
56
|
Some local identity providers need a client ID and secret. Configure both fields or
|
|
@@ -68,6 +77,40 @@ Use unique, non-privileged ports that do not overlap. `projectId` accepts lowerc
|
|
|
68
77
|
letters, numbers, and hyphens. It labels the local Docker resources so cleanup targets
|
|
69
78
|
only this project.
|
|
70
79
|
|
|
80
|
+
## Database runtime
|
|
81
|
+
|
|
82
|
+
`runtime.target` selects the isolated database driver. It is optional in existing
|
|
83
|
+
configurations and currently defaults to `"supabase"`, so upgrading does not change an
|
|
84
|
+
existing project's behavior. Unknown targets are rejected before any runtime action.
|
|
85
|
+
|
|
86
|
+
For ordinary PostgreSQL, use `postgresql` instead of `supabase`:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
postgresql: {
|
|
90
|
+
migrationDirectory: "database/migrations",
|
|
91
|
+
runtimeWorkdir: ".rehearsal/runtime",
|
|
92
|
+
image: "postgres:17-alpine",
|
|
93
|
+
database: "postgres",
|
|
94
|
+
user: "postgres",
|
|
95
|
+
},
|
|
96
|
+
runtime: {
|
|
97
|
+
target: "postgresql",
|
|
98
|
+
applicationUrl: "http://localhost:5175",
|
|
99
|
+
projectId: "example-app-rehearsal",
|
|
100
|
+
databasePort: 58322,
|
|
101
|
+
},
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The image must be an official versioned Alpine PostgreSQL image and must already exist
|
|
105
|
+
locally. Rehearsal runs it with `--pull=never`, publishes it only on `127.0.0.1`, and
|
|
106
|
+
creates a fresh random runtime password in owner-readable ignored files. It manages only
|
|
107
|
+
the exactly named container and volume carrying the matching project label.
|
|
108
|
+
Plain PostgreSQL does not restore Supabase Storage assets or synthesize Supabase Auth
|
|
109
|
+
users.
|
|
110
|
+
|
|
111
|
+
Project-owned runtime adapters remain the place for application-specific setup and
|
|
112
|
+
checks; they do not replace the database driver.
|
|
113
|
+
|
|
71
114
|
## Application proof
|
|
72
115
|
|
|
73
116
|
`proofCommand` is mandatory and project-owned. It should test restored relationships,
|