@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.
@@ -1,282 +1,151 @@
1
1
  # Getting started
2
2
 
3
- This guide creates a safe local Rehearsal project from synthetic data. It does not
4
- connect to production, request hosted credentials, or require an existing baseline.
3
+ This guide sets up Rehearsal in an existing project. It creates a disposable database on
4
+ your computer and never connects to a hosted database.
5
5
 
6
- ## Prerequisites
6
+ Want to experiment first? Use the [safe hands-on tutorial](tutorial.md).
7
7
 
8
- - Node.js 24
9
- - npm
10
- - Supabase CLI 2.117.0 (the version proved by package CI)
11
- - Docker Desktop, Colima, or another Docker-compatible engine
12
- - a Supabase project with timestamped SQL migrations
8
+ ## 1. Check the required tools
13
9
 
14
- Confirm the tools first:
10
+ You need Node.js 24, npm, and a running Docker-compatible engine:
15
11
 
16
12
  ```bash
17
13
  node --version
18
14
  npm --version
19
- supabase --version
20
15
  docker info
21
16
  ```
22
17
 
23
- If you want to see the complete lifecycle before touching your own project, clone the
24
- Rehearsal repository and run:
18
+ `node --version` must begin with `v24`. If `docker info` fails, start Docker Desktop,
19
+ Colima, or your usual Docker engine.
25
20
 
26
- ```bash
27
- npm ci --ignore-scripts
28
- npm run test:fixture
29
- ```
21
+ Choose the extra requirement for your project:
30
22
 
31
- That proof installs the packed package into a disposable fictional project, restores a
32
- row and Storage object, applies a valid migration, rejects invalid SQL, and removes only
33
- its labeled local runtime. It does not need a hosted Supabase project or credentials.
23
+ - **Supabase:** install Supabase CLI 2.117.0 and run `supabase --version`.
24
+ - **PostgreSQL:** download the local database image once:
34
25
 
35
- ## 1. Install and initialize
26
+ ```bash
27
+ docker pull postgres:17-alpine
28
+ ```
36
29
 
37
- Confirm this shell is running the supported Node.js major before installing:
30
+ Rehearsal will use that image with downloads disabled.
38
31
 
39
- ```bash
40
- node --version # v24.x
41
- ```
32
+ ## 2. Install and open the guide
33
+
34
+ Run these commands from the directory containing your project's `package.json`:
42
35
 
43
36
  ```bash
44
37
  npm install --save-dev @rehearsal-db/core@beta
45
38
  npx rehearsal
46
39
  ```
47
40
 
48
- Choose **Set up Rehearsal** in the guide. It previews a versioned configuration, a
49
- dedicated local-only Supabase configuration using available ports, and protective
50
- `.gitignore` entries before asking permission to write. The guide remains open afterward
51
- and recommends the next incomplete stage.
41
+ Choose **Set the stage**, then choose Supabase or PostgreSQL. Rehearsal previews every file
42
+ before asking to create it. It will not replace an existing file.
52
43
 
53
- The same flow is available noninteractively as an explicit preview and write:
44
+ Review the generated `rehearsal.config.mjs`, especially:
54
45
 
55
- ```bash
56
- npx rehearsal setup
57
- npx rehearsal setup --write
58
- ```
46
+ - the migration directory;
47
+ - the application start and proof commands;
48
+ - the local ports.
59
49
 
60
- Rehearsal never overwrites an existing configuration. For config-only/manual setup, use
61
- `npx rehearsal init` followed by `npx rehearsal init --write`.
50
+ The proof command should check behavior changed by the migration. A test that only checks
51
+ whether the home page loads is usually too weak.
62
52
 
63
- The generated configuration is intentionally incomplete until you review its ports,
64
- project ID, application commands, and project-owned input paths. Do not run `doctor`
65
- until the next section's files exist.
53
+ ## 3. Prepare safe baseline inputs
66
54
 
67
- ## 2. Add the project-owned inputs
55
+ A **baseline** is the locked starting point restored before each rehearsal. Start with a
56
+ small synthetic dataset. Do not use raw production data.
68
57
 
69
- Review or create the project-owned inputs named by `rehearsal.config.mjs`:
58
+ Rehearsal needs:
70
59
 
71
- - the dedicated local Supabase `config.toml` (`setup` creates a conservative one);
72
- - a sanitization policy describing every exported field;
73
- - an active baseline below `.rehearsal/`;
74
- - an application proof command that exits nonzero when the restored app is wrong.
60
+ | Input | What it contains |
61
+ | ------------------- | ---------------------------------------------------- |
62
+ | Records | Safe rows in NDJSON format: one JSON object per line |
63
+ | Migration ledger | The historical migrations represented by those rows |
64
+ | Sanitization policy | A decision for every included table and column |
65
+ | Storage manifest | Optional Supabase Storage files only |
75
66
 
76
- If you used config-only `init`, also create the dedicated Supabase config manually:
67
+ A record looks like this:
77
68
 
78
- ```bash
79
- mkdir -p infrastructure/rehearsal/supabase infrastructure/rehearsal rehearsal
80
- cp supabase/config.toml infrastructure/rehearsal/supabase/config.toml
69
+ ```json
70
+ { "table": "widgets", "row": { "id": 1, "name": "Synthetic Widget" } }
81
71
  ```
82
72
 
83
- Edit the copied Supabase config. Give it the same unique `project_id`, API port, database
84
- port, and Studio port used by `rehearsal.config.mjs`. Disable services your proof does
85
- not need. This must remain an unlinked local config; never run `supabase link` from it.
73
+ Put your safe records and ledger inside the project. Conventional names such as
74
+ `rehearsal/sanitized-data.ndjson` and `rehearsal/migration-ledger.json` are discovered
75
+ automatically. The guide inspects their structure but does not print row values.
86
76
 
87
- Also replace the generated `application.startCommand`, `application.proofCommand`, and
88
- `verification.commands` with real commands from your project. The proof should check a
89
- restored relationship and the candidate schema—not merely that `/` returns 200.
77
+ Follow the guide's recommended actions:
90
78
 
91
- Start with synthetic rows shaped like your schema. Do not start onboarding with
92
- production data. The following SQL, policy, row, and ledger form one matched example;
93
- do not mix them with differently shaped snippets.
79
+ 1. **Prepare the script** creates a draft sanitization policy.
80
+ 2. **Review the script** asks you to classify every table and column.
81
+ 3. **Create the baseline** validates and activates the reviewed inputs.
94
82
 
95
- If you already have the safe NDJSON rows and migration ledger, Rehearsal can enumerate
96
- their table and column shape into a fail-closed policy draft without printing values:
97
-
98
- ```bash
99
- npx rehearsal baseline prepare \
100
- --records=rehearsal/synthetic-data.ndjson \
101
- --ledger=rehearsal/migration-ledger.json
102
- npx rehearsal baseline prepare \
103
- --records=rehearsal/synthetic-data.ndjson \
104
- --ledger=rehearsal/migration-ledger.json \
105
- --write
106
- ```
83
+ Rehearsal will not activate a policy containing undecided fields.
107
84
 
108
- After creating the draft, choose **Review the script** in the guide. Rehearsal walks each
109
- column through sanitization action, generated status, identity status, and optional
110
- foreign-key metadata. Every answer is explicit, the complete policy is validated before
111
- writing, and the original draft is replaced only if it did not change during review.
85
+ The ledger must describe the exact historical SQL included in the baseline. Do not type
86
+ years of migration history by hand for a real project. Generate it through reviewed
87
+ project tooling. The [tutorial](tutorial.md) contains a complete synthetic example, and
88
+ [Baselines](baselines.md) explains the file formats.
112
89
 
113
- For noninteractive workflows, review every `REVIEW REQUIRED` field directly and remove
114
- `"draft": true` only after that review. Rehearsal refuses to activate a draft.
90
+ ## 4. Reach READY
115
91
 
116
- Historical migration `supabase/migrations/20260101000000_create_widgets.sql`:
92
+ The guide displays four setup stages. Continue with its recommended action until all
93
+ checks are complete and the project reports `READY`.
117
94
 
118
- ```sql
119
- create table public.widgets (
120
- id bigint generated by default as identity primary key,
121
- name text not null,
122
- created_at timestamptz not null default now()
123
- );
95
+ You can run the same check directly:
124
96
 
125
- insert into storage.buckets (id, name, public)
126
- values ('fixture-assets', 'fixture-assets', false);
97
+ ```bash
98
+ npx rehearsal doctor
127
99
  ```
128
100
 
129
- Sanitization policy `infrastructure/rehearsal/sanitization-policy.json`:
130
-
131
- ```json
132
- {
133
- "policyVersion": 1,
134
- "migrationCutoff": "20260101000000",
135
- "tables": [
136
- {
137
- "name": "widgets",
138
- "group": "synthetic",
139
- "sourceRows": "STREAM AND SANITIZE",
140
- "columns": [
141
- {
142
- "name": "id",
143
- "action": "KEEP EXACTLY",
144
- "generated": "NEVER",
145
- "identity": "YES",
146
- "foreignKey": null
147
- },
148
- {
149
- "name": "name",
150
- "action": "REPLACE WITH SYNTHETIC",
151
- "generated": "NEVER",
152
- "identity": "NO",
153
- "foreignKey": null
154
- },
155
- {
156
- "name": "created_at",
157
- "action": "DERIVE",
158
- "generated": "NEVER",
159
- "identity": "NO",
160
- "foreignKey": null
161
- }
162
- ]
163
- }
164
- ]
165
- }
166
- ```
101
+ If it reports `NOT READY`, fix the listed item and run it again. Do not bypass a check or
102
+ add a hosted connection string.
167
103
 
168
- Safe row `rehearsal/synthetic-data.ndjson` (one JSON object per physical line):
104
+ ## 5. Run the rehearsal
169
105
 
170
- ```json
171
- {
172
- "table": "widgets",
173
- "row": {
174
- "id": 1,
175
- "name": "Synthetic Widget",
176
- "created_at": "2026-01-01T00:00:00.000Z"
177
- }
178
- }
179
- ```
106
+ Choose **Run a rehearsal**. Rehearsal shows the exact candidate migrations and asks for
107
+ confirmation before it changes the disposable runtime.
180
108
 
181
- Migration ledger `rehearsal/migration-ledger.json`:
109
+ A successful run:
182
110
 
183
- ```json
184
- [
185
- {
186
- "version": "20260101000000",
187
- "name": "create_widgets",
188
- "statements": [
189
- "create table public.widgets (\n\tid bigint generated by default as identity primary key,\n\tname text not null,\n\tcreated_at timestamptz not null default now()\n)",
190
- "insert into storage.buckets (id, name, public)\nvalues ('fixture-assets', 'fixture-assets', false)"
191
- ]
192
- }
193
- ]
194
- ```
111
+ 1. restores the baseline;
112
+ 2. applies only the migrations you approved;
113
+ 3. verifies the local database;
114
+ 4. runs your application proof.
195
115
 
196
- The ledger is evidence, not a second migration language. Its version, name, order, and
197
- statements must exactly represent the historical migration bytes in the baseline. SQL
198
- that is merely equivalent is rejected. For a production-shaped baseline, generate this
199
- ledger through the project's reviewed source/export tooling; do not reconstruct years of
200
- history by hand.
116
+ Your original baseline remains unchanged.
201
117
 
202
- Then activate the safe input:
118
+ ## 6. Test and clean up
203
119
 
204
- ```bash
205
- npx rehearsal baseline create \
206
- --records=rehearsal/synthetic-data.ndjson \
207
- --ledger=rehearsal/migration-ledger.json
208
- ```
120
+ Use the guide for normal runtime tasks:
209
121
 
210
- The independent fixture in this repository is the executable reference example.
122
+ - **Verify** checks the current runtime.
123
+ - **Reset** discards runtime edits and restores the baseline.
124
+ - **Stop** stops the runtime but keeps its local state.
125
+ - **Discard** removes this project's disposable runtime and volume.
211
126
 
212
- Expected result:
127
+ Press `Ctrl+Z` at any prompt to exit the entire guide. It will not leave a suspended
128
+ process behind.
213
129
 
214
- ```text
215
- Activated synthetic baseline ...: 1 rows across 1 tables; 1 migrations through 20260101000000.
216
- ```
130
+ ## Command-line setup
217
131
 
218
- ## 3. Check readiness
132
+ The guide is recommended for people. Scripts and CI can use explicit commands:
219
133
 
220
134
  ```bash
135
+ npx rehearsal setup --target=postgresql --write
221
136
  npx rehearsal doctor
222
- ```
223
-
224
- Do not continue until it ends with `READY`. Doctor checks the local-only boundary,
225
- dependencies, artifact integrity, migration lineage, ports, and project commands.
226
-
227
- If it reports `NOT READY`, fix each named prerequisite and rerun it. Do not bypass a
228
- check or copy a hosted connection string into the generated runtime environment.
229
-
230
- ## 4. Review pending work
231
-
232
- ```bash
233
- npx rehearsal explain
234
137
  npx rehearsal candidates
235
- npx rehearsal inspect baseline
236
- npx rehearsal inspect migrations
237
- ```
238
-
239
- The plan prints an exact candidate digest. It does not start services or change data.
240
-
241
- ## 5. Run the rehearsal
242
-
243
- ```bash
244
- npx rehearsal run --confirm-candidates=<sha256>
138
+ npx rehearsal run --confirm-candidates=PASTE_DIGEST_HERE
245
139
  ```
246
140
 
247
- Rehearsal restores the immutable baseline, applies only the confirmed migration suffix,
248
- verifies the runtime, and runs the project-owned application proof. The resulting local
249
- database is writable, so you can test real application changes without mutating the
250
- baseline.
251
-
252
- ## 6. Work, verify, and reset
253
-
254
- ```bash
255
- npx rehearsal status
256
- npx rehearsal start
257
- npx rehearsal verify
258
- npx rehearsal reset
259
- npx rehearsal stop
260
- ```
261
-
262
- Changes persist in the disposable runtime until `reset` or runtime removal. `start`
263
- resumes that runtime without resetting it. `reset` restores the exact baseline. `stop`
264
- stops only this project's runtime.
265
-
266
- ## Next steps
267
-
268
- - Follow [the full tutorial](tutorial.md).
269
- - Read [the security model](security-model.md) before designing a production export.
270
- - Define an exhaustive [sanitization policy](sanitization.md).
271
- - Learn the [baseline lifecycle](baselines.md).
141
+ Replace `postgresql` with `supabase` when needed. See [CLI commands](commands.md) for the
142
+ complete reference and [Troubleshooting](troubleshooting.md) when a check fails.
272
143
 
273
- ## Generated files
144
+ ## Files Rehearsal creates
274
145
 
275
- - `rehearsal.config.mjs` is written only by `init --write`. Its explicit ESM extension
276
- works whether the consuming project's `package.json` uses CommonJS or ESM.
277
- - `.rehearsal/generations/<id>/` contains one immutable baseline generation.
278
- - `.rehearsal/current` selects the active generation atomically.
279
- - `.rehearsal/runtime/` contains the disposable local Supabase project and receipts.
280
- - `.rehearsal/runtime.env` contains generated loopback-only application credentials.
146
+ - `rehearsal.config.mjs` — reviewed project configuration
147
+ - `.rehearsal/` — ignored baselines, runtime files, and receipts
148
+ - `.rehearsal/runtime.env` — generated local-only application variables
149
+ - `infrastructure/rehearsal/supabase/config.toml` — Supabase-only local configuration
281
150
 
282
- Ignore all of `.rehearsal/`. Do not commit it even when its inputs were synthetic.
151
+ Keep `.rehearsal/` out of source control, even when its data is synthetic.
package/docs/glossary.md CHANGED
@@ -1,4 +1,4 @@
1
- # Glossary and architecture
1
+ # Glossary
2
2
 
3
3
  **Baseline** — immutable sanitized starting artifact.
4
4
 
@@ -19,13 +19,12 @@ baseline.
19
19
 
20
20
  ```mermaid
21
21
  flowchart LR
22
- A[Project-owned approved source] --> B[Project-owned sanitization]
23
- B --> C[Immutable baseline]
24
- D[Project migrations] --> E[Digest planner]
25
- C --> F[Disposable local Supabase]
26
- E --> F
27
- F --> G[Project application proof]
28
- G --> H[Verified local receipt]
22
+ A[Safe rows] --> B[Locked baseline]
23
+ C[Migration files] --> D[Reviewed plan]
24
+ B --> E[Disposable local database]
25
+ D --> E
26
+ E --> F[Application proof]
27
+ F --> G[Verified result]
29
28
  ```
30
29
 
31
30
  The reusable package owns the path from a completed baseline plus migration directory to
@@ -19,11 +19,14 @@ whether it is an identity column, and its foreign-key target or explicit absence
19
19
  draft uses `REVIEW REQUIRED` placeholders and cannot be activated until they are
20
20
  replaced and the `draft` marker is removed.
21
21
 
22
- In an interactive terminal, the guided **Review the script** action completes these
23
- decisions one column at a time. Replacement-oriented actions are shown first, retaining
24
- a value is explicitly labeled as sensitive, and no choice is silently inferred. The
25
- reviewer validates the completed policy and refuses to overwrite a draft changed during
26
- the session.
22
+ In an interactive terminal, the guided **Review the script** action works table by table.
23
+ For larger tables, a human can explicitly apply safe defaults (`REPLACE`, `NEVER`
24
+ generated, `NO` identity, and no foreign key), then review only exceptions. Likely
25
+ structural columns such as `id`, `*_id`, and timestamps start selected as exceptions.
26
+ Users can instead review every column individually. Retaining a value is explicitly
27
+ labeled as sensitive, every saved field remains classified, and no preset is silently
28
+ applied. The reviewer validates the completed policy and refuses to overwrite a draft
29
+ changed during the session.
27
30
 
28
31
  The package exports `validateSanitizationCoverage` and
29
32
  `applySanitizationAction` as generic primitives:
@@ -13,12 +13,16 @@ changed migration history, incomplete artifacts, or an unverified runtime.
13
13
  ## Independent barriers
14
14
 
15
15
  - loopback-only application and service URLs;
16
- - a dedicated unlinked Supabase workdir and project ID;
16
+ - a dedicated unlinked Supabase workdir, or an exactly named and labeled PostgreSQL
17
+ container and volume;
17
18
  - exact non-overlapping local ports;
18
19
  - a clean child-process environment that omits hosted credentials;
19
20
  - immutable baseline files and checksums;
20
21
  - exact migration-prefix and candidate digests;
21
22
  - local runtime labels used for bounded stop/removal;
23
+ - PostgreSQL images must already exist locally and are never pulled implicitly;
24
+ - plain PostgreSQL receives a fresh random password per disposable runtime, retained
25
+ only in owner-readable ignored runtime files;
22
26
  - successful receipts written only after verification.
23
27
 
24
28
  No single environment variable or config edit should redirect the tool to production.
@@ -1,5 +1,25 @@
1
1
  # Troubleshooting
2
2
 
3
+ Start with:
4
+
5
+ ```bash
6
+ npx rehearsal doctor
7
+ ```
8
+
9
+ Doctor names each missing or unsafe item. If you still need help, run
10
+ `npx rehearsal support`, review the report, and attach it to a GitHub issue.
11
+
12
+ ## `npx rehearsal` cannot find the command
13
+
14
+ Confirm you are in the project directory and install the beta locally:
15
+
16
+ ```bash
17
+ npm install --save-dev @rehearsal-db/core@beta
18
+ npx rehearsal --help
19
+ ```
20
+
21
+ Do not use `sudo` or require a global install.
22
+
3
23
  ## Setup says Node.js 24 is required
4
24
 
5
25
  Rehearsal intentionally supports one maintained Node.js major in its first beta. Switch
@@ -19,12 +39,32 @@ writes setup files.
19
39
  Start Docker Desktop or Colima, confirm `docker info`, then rerun `rehearsal doctor`.
20
40
  Restarting the computer is rarely necessary.
21
41
 
42
+ ## The guide does not show styled menus
43
+
44
+ Rehearsal uses numbered menus when terminal styling is unavailable, `NO_COLOR` is set, or
45
+ `--plain` is used. Enter the number beside your choice. This is the same workflow and has
46
+ the same safety checks.
47
+
48
+ If bare `npx rehearsal` prints help, the command is not connected to an interactive
49
+ terminal. Run it directly in a terminal rather than through a pipe or background task.
50
+
51
+ ## Doctor says the PostgreSQL image is unavailable
52
+
53
+ Rehearsal will not download an image during a rehearsal. Pull and review the exact image
54
+ declared in `rehearsal.config.mjs`, then rerun Doctor:
55
+
56
+ ```bash
57
+ docker pull postgres:17-alpine
58
+ npx rehearsal doctor
59
+ ```
60
+
22
61
  ## A port is already in use
23
62
 
24
63
  Rerun `rehearsal setup` to select a different available block. Setup checks both active
25
64
  listeners and whether every selected port can be bound, then checks again before writing.
26
65
  For an existing configuration, choose unique non-privileged ports and mirror them in the
27
- dedicated Supabase config. Do not stop an unrelated database to make defaults fit.
66
+ dedicated Supabase config when using Supabase. Do not stop an unrelated database to make
67
+ defaults fit.
28
68
 
29
69
  ## Baseline checksum mismatch
30
70
 
@@ -62,5 +102,10 @@ is the local Auth callback. Do not paste provider secrets into config or termina
62
102
  `reset` deliberately restores the immutable baseline. `stop` should preserve Docker
63
103
  state, but runtime removal or a failed migration discards untrusted state.
64
104
 
105
+ ## `Ctrl+Z` exits instead of suspending
106
+
107
+ This is intentional inside the guided interface. It exits the entire Rehearsal session
108
+ and restores the terminal. Choose **Exit** for the same result.
109
+
65
110
  Use `--debug` only after ordinary output is insufficient. Diagnostics are redacted, but
66
111
  you should still review output before sharing it publicly.