@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/docs/baselines.md CHANGED
@@ -1,33 +1,92 @@
1
1
  # Baselines
2
2
 
3
- A baseline is an immutable, digest-addressed starting point for a disposable runtime.
4
- It binds sanitized rows, represented migration bytes, optional Storage assets, schema
5
- evidence, policy identity, and verification metadata.
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
- ## Generation lifecycle
7
+ ## Required inputs
8
8
 
9
- New content is written to a private building directory. Individual files are checksummed
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
- ## Migration lineage
11
+ Records use NDJSON: one complete JSON object per line. Each object names a table and one
12
+ safe row.
14
13
 
15
- The manifest records the exact ordered historical prefix. A migration with the same
16
- timestamp but different bytes is modified history, not a candidate. New migrations must
17
- form an ordered suffix. Candidate confirmation binds the exact filenames and checksums.
14
+ ```json
15
+ { "table": "widgets", "row": { "id": 1, "name": "Synthetic Widget" } }
16
+ ```
18
17
 
19
- ## Restore lifecycle
18
+ Use synthetic or reviewed sanitized values. A `.json` array is not NDJSON and will be
19
+ rejected.
20
20
 
21
- `reset` destroys only the explicitly labelled local runtime, replays the represented
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
- ## Persistence model
23
+ The ledger is a JSON array in migration order:
27
24
 
28
- The baseline never changes during normal use. The restored runtime is writable and its
29
- changes persist across application restarts while the local containers remain. Run
30
- `reset` to discard sandbox changes and return to the exact baseline.
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
- Treat baseline files as sensitive even after sanitization: owner-only permissions,
33
- ignored paths, encrypted disks, bounded retention, and explicit deletion are prudent.
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
- All commands run from the consuming project root. State-reporting commands accept
4
- `--json`; `--verbose` and `--debug` increase safe diagnostics without revealing row
5
- values or credentials.
6
-
7
- | Command | Mutates local state | Purpose |
8
- | ------------------------------------------------------------ | ------------------- | --------------------------------------------------------- |
9
- | `rehearsal` or `rehearsal guide` | No by default | Open the guided, state-aware interactive home screen. |
10
- | `rehearsal setup` | No | Preview safe config, local runtime, and ignore files. |
11
- | `rehearsal setup --write` | Project files | Create the previewed first-run scaffolding. |
12
- | `rehearsal init` | No | Preview safe starter configuration. |
13
- | `rehearsal init --write` | Config only | Create config without overwriting. |
14
- | `rehearsal baseline prepare --records= --ledger=` | No | Preview a fail-closed policy draft from local shape. |
15
- | `rehearsal baseline prepare --records= --ledger= --write` | Policy only | Write the draft without exposing row values. |
16
- | `rehearsal baseline create --records=<path> --ledger=<path>` | Artifact only | Activate a baseline from explicit safe local inputs. |
17
- | `rehearsal doctor` | No | Check dependencies, inputs, and safety barriers. |
18
- | `rehearsal explain` | No | Print the immutable execution plan. |
19
- | `rehearsal run --dry-run` | No | Alias the same plan used by `explain`. |
20
- | `rehearsal candidates` | No | Print pending migrations and their exact digest. |
21
- | `rehearsal inspect baseline` | No | Print data-free artifact provenance. |
22
- | `rehearsal inspect migrations` | No | Classify each migration. |
23
- | `rehearsal run --confirm-candidates=<sha256>` | Yes, local only | Reset, apply exact candidates, verify, and run app proof. |
24
- | `rehearsal start` | Runtime only | Start a verified runtime without resetting its data. |
25
- | `rehearsal migrate --confirm-candidates=<sha256>` | Yes, local only | Apply the exact suffix without resetting current data. |
26
- | `rehearsal verify` | No data mutation | Verify the current local runtime and receipt. |
27
- | `rehearsal status` | No | Report runtime, baseline, and candidate state. |
28
- | `rehearsal reset` | Yes, local only | Replace runtime data with the immutable baseline. |
29
- | `rehearsal stop` | Runtime only | Stop this project's local services. |
30
- | `rehearsal discard` | Yes, local only | Remove only this project's disposable runtime and volume. |
31
-
32
- In an interactive terminal, `run` and `migrate` display the candidate files and ask for
33
- confirmation before touching the runtime. In automation, they require the digest from
34
- the current candidate set. Any added, removed, reordered, or edited migration changes
35
- the digest and invalidates either form of confirmation.
36
-
37
- `baseline create` never extracts data. The NDJSON and migration-ledger files must already
38
- exist inside the project and be safe to retain. Add `--assets=<manifest.json>` to include
39
- bounded local Storage bytes; every manifest `file` must also remain inside the project.
40
- The guided home screen can ask for these paths so they do not need to be supplied as
41
- flags.
42
-
43
- The guide is a persistent session: after setup, policy review, baseline creation, or a
44
- runtime action it re-reads project state and offers the next relevant action. Generated
45
- policy drafts can be completed interactively without editing JSON. Each column still
46
- requires explicit action, generated, identity, and foreign-key decisions; the guide does
47
- not silently infer them.
48
-
49
- `baseline prepare` reads only table and column names from the NDJSON records; row values
50
- are never included in its result. Its generated policy deliberately marks every column
51
- decision `REVIEW REQUIRED` and cannot be activated until a human completes the metadata
52
- and removes the `draft` marker. Rehearsal binds the reviewed policy checksum to the
53
- baseline and rejects later policy changes during planning and restore.
54
-
55
- Automation should use `--json` and inspect both exit status and the versioned envelope.
56
- Exit-code meanings are documented in the root README. Scripts must not parse human text.
57
- When standard input or output is not an interactive terminal, bare `rehearsal` prints
58
- help instead of prompting. Use `--plain` to disable decorative terminal styling.
59
- `NO_COLOR` also selects the plain numbered interface. Both interactive modes preserve
60
- the same safety decisions and cancellation behavior.
61
-
62
- `setup` chooses an available local port block and generates a conservative Supabase
63
- configuration with hosted access and optional networked services disabled. It does not
64
- overwrite an existing Rehearsal config, dedicated Supabase config, or concurrently
65
- changed `.gitignore`. After writing, it includes a Doctor readiness summary. `init`
66
- remains available for config-only/manual onboarding.
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.
@@ -1,9 +1,14 @@
1
1
  # Configuration reference
2
2
 
3
- `rehearsal.config.mjs` is executable configuration with a strict versioned schema. The
4
- initializer uses an explicit ESM extension so the same generated file works in CommonJS
5
- and ESM projects.
6
- Unknown fields and unknown schema versions are errors, not warnings.
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,