symmetria-kit 3.5.0 → 3.6.0
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/README.md +104 -78
- package/dist/cli/query-inspect.d.ts +0 -1
- package/dist/cli/query-inspect.js +1 -1
- package/dist/cli.js +545 -91
- package/dist/cli.js.map +1 -1
- package/dist/{diff-f8tZSWq5.js → diff-Bl4o3rmq.js} +1151 -73
- package/dist/diff-Bl4o3rmq.js.map +1 -0
- package/dist/index.d.ts +22 -2
- package/dist/index.js +2 -2
- package/dist/{query-inspector-DGaa-bK6.js → query-inspector-BolQM66i.js} +178 -51
- package/dist/query-inspector-BolQM66i.js.map +1 -0
- package/dist/{src-D9uetYbU.js → src-_9AiCfWh.js} +463 -81
- package/dist/src-_9AiCfWh.js.map +1 -0
- package/dist/testing.js +1 -1
- package/package.json +2 -2
- package/dist/diff-f8tZSWq5.js.map +0 -1
- package/dist/query-inspector-DGaa-bK6.js.map +0 -1
- package/dist/src-D9uetYbU.js.map +0 -1
package/README.md
CHANGED
|
@@ -57,51 +57,63 @@ export default defineMigrationConfig({
|
|
|
57
57
|
| `repair <id>` | Verify and resolve an incomplete migration |
|
|
58
58
|
| `recover` | Recover files after a crashed generator |
|
|
59
59
|
|
|
60
|
-
| Flag | Commands | Purpose
|
|
61
|
-
| ------------------------------ | -------------------------------------------- |
|
|
62
|
-
| `--config <file>` | all | Config module (default `symmetria.config.ts`)
|
|
63
|
-
| `--dir <directory>` | all with a project | Migrations directory, relative to the working directory
|
|
64
|
-
| `--database-url <url>` | database commands, `pull`, `lint` | Connection; overrides `databaseUrl` and `DATABASE_URL`
|
|
65
|
-
| `--json` | all | One JSON object on stdout, `{"error": …}` on failure
|
|
66
|
-
| `--sql` | `diff` | Print executable SQL
|
|
67
|
-
| `--diff <file.json>` | `generate`, `diff`, `lint` | Rename hints and `USING` conversions
|
|
68
|
-
| `--empty` | `generate` | An empty, editable SQL migration
|
|
69
|
-
| `--allow-destructive` | `generate` | Permit drops and narrowing type changes (`allowDestructive`)
|
|
70
|
-
| `--transaction <mode>` | `generate` | `batch` (default), `each` or `none` (`transaction`)
|
|
71
|
-
| `--online` | `generate`, `diff`, `lint` | Concurrent indexes and phased validation (`online`)
|
|
72
|
-
| `--allow-custom-sql` | `squash` | Drop SQL that generate did not write (`allowCustomSQL`)
|
|
73
|
-
| `--pending` | `lint` | Only migrations pending in the database
|
|
74
|
-
| `--strict` | `lint`, `drift` | Exit with code 1 for any finding
|
|
75
|
-
| `--to <id>` | `migrate`, `adopt` | Apply up to, or adopt through, a migration (`to`)
|
|
76
|
-
| `--steps <n>` | `rollback` | Number of migrations to revert (`steps`)
|
|
77
|
-
| `--yes` | `rollback` | Run `down.sql` without asking; required without a terminal
|
|
78
|
-
| `--plan` | `migrate`, `rollback` | Show SQL and transaction groups without running them
|
|
79
|
-
| `--action <action>` | `repair` | `retry` or `complete` (`action`)
|
|
80
|
-
| `--verify-url <url>` | `verify`, `adopt`, `repair`
|
|
81
|
-
| `--snapshot <file>` | `repair` | Snapshot file of the boundary to verify, instead of `--verify-url`
|
|
82
|
-
| `--ignore-table <name>` | `pull`, `drift`, `adopt`, `repair`, `verify` | Leave an undeclared table out, repeatable (`ignoreTables`)
|
|
83
|
-
| `--advisory-lock-timeout <ms>` | commands that run migrations | Migration lock wait (`advisoryLockTimeoutMs`, default 10000)
|
|
84
|
-
| `--lock-timeout <ms>` | commands that run migrations | DDL lock wait (`lockTimeoutMs`, default 5000; 0 disables)
|
|
85
|
-
| `--statement-timeout <ms>` | commands that run migrations | Statement duration (`statementTimeoutMs`, default 600000; no default limit in `transaction: "none"` migrations)
|
|
86
|
-
| `--force` | `pull`, `graph`, `discard` | Overwrite the written file; `discard`: no database to ask, or an `up.sql` edited after generation
|
|
87
|
-
| `--compact` | `graph` | Entities and relations without column lists
|
|
88
|
-
| `--relations` | `inspect` | Start on, or list, the relations
|
|
89
|
-
| `--profile-url <url>` | `profile` | Profiler endpoint (default `http://127.0.0.1:7331`)
|
|
90
|
-
| `--profile-token <token>` | `profile` | Profiler token (default `SYMMETRIA_PROFILE_TOKEN`)
|
|
91
|
-
| `--no-interactive` | all | No dashboard, schema browser or rename questions
|
|
92
|
-
| `--no-color`, `--no-animation` | all | Plain output; no logo or spinner animation
|
|
93
|
-
| `--help`, `-h` | all | Show the commands and flags
|
|
60
|
+
| Flag | Commands | Purpose |
|
|
61
|
+
| ------------------------------ | -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
|
|
62
|
+
| `--config <file>` | all | Config module (default `symmetria.config.ts`) |
|
|
63
|
+
| `--dir <directory>` | all with a project | Migrations directory, relative to the working directory |
|
|
64
|
+
| `--database-url <url>` | database commands, `pull`, `lint` | Connection; overrides `databaseUrl` and `DATABASE_URL` |
|
|
65
|
+
| `--json` | all | One JSON object on stdout, `{"error": …}` on failure |
|
|
66
|
+
| `--sql` | `diff` | Print executable SQL |
|
|
67
|
+
| `--diff <file.json>` | `generate`, `diff`, `lint` | Rename hints and `USING` conversions |
|
|
68
|
+
| `--empty` | `generate` | An empty, editable SQL migration |
|
|
69
|
+
| `--allow-destructive` | `generate` | Permit drops and narrowing type changes (`allowDestructive`) |
|
|
70
|
+
| `--transaction <mode>` | `generate` | `batch` (default), `each` or `none` (`transaction`) |
|
|
71
|
+
| `--online` | `generate`, `diff`, `lint` | Concurrent indexes and phased validation (`online`) |
|
|
72
|
+
| `--allow-custom-sql` | `squash` | Drop SQL that generate did not write (`allowCustomSQL`) |
|
|
73
|
+
| `--pending` | `lint` | Only migrations pending in the database |
|
|
74
|
+
| `--strict` | `lint`, `drift` | Exit with code 1 for any finding |
|
|
75
|
+
| `--to <id>` | `migrate`, `adopt` | Apply up to, or adopt through, a migration (`to`) |
|
|
76
|
+
| `--steps <n>` | `rollback` | Number of migrations to revert (`steps`) |
|
|
77
|
+
| `--yes` | `rollback` | Run `down.sql` without asking; required without a terminal |
|
|
78
|
+
| `--plan` | `migrate`, `rollback` | Show SQL and transaction groups without running them |
|
|
79
|
+
| `--action <action>` | `repair` | `retry` or `complete` (`action`) |
|
|
80
|
+
| `--verify-url <url>` | `verify`, `adopt`, `repair`, `drift` | Server for disposable databases (`verificationDatabaseUrl`) |
|
|
81
|
+
| `--snapshot <file>` | `repair` | Snapshot file of the boundary to verify, instead of `--verify-url` |
|
|
82
|
+
| `--ignore-table <name>` | `pull`, `drift`, `adopt`, `repair`, `verify` | Leave an undeclared table out, repeatable (`ignoreTables`) |
|
|
83
|
+
| `--advisory-lock-timeout <ms>` | commands that run migrations | Migration lock wait (`advisoryLockTimeoutMs`, default 10000) |
|
|
84
|
+
| `--lock-timeout <ms>` | commands that run migrations | DDL lock wait (`lockTimeoutMs`, default 5000; 0 disables; no default for concurrent index DDL and `VALIDATE` in `none` migrations) |
|
|
85
|
+
| `--statement-timeout <ms>` | commands that run migrations | Statement duration (`statementTimeoutMs`, default 600000; no default limit in `transaction: "none"` migrations) |
|
|
86
|
+
| `--force` | `pull`, `graph`, `discard` | Overwrite the written file; `discard`: no database to ask, or an `up.sql` edited after generation |
|
|
87
|
+
| `--compact` | `graph` | Entities and relations without column lists |
|
|
88
|
+
| `--relations` | `inspect` | Start on, or list, the relations |
|
|
89
|
+
| `--profile-url <url>` | `profile` | Profiler endpoint (default `http://127.0.0.1:7331`) |
|
|
90
|
+
| `--profile-token <token>` | `profile` | Profiler token (default `SYMMETRIA_PROFILE_TOKEN`) |
|
|
91
|
+
| `--no-interactive` | all | No dashboard, schema browser or rename questions |
|
|
92
|
+
| `--no-color`, `--no-animation` | all | Plain output; no logo or spinner animation |
|
|
93
|
+
| `--help`, `-h` | all | Show the commands and flags |
|
|
94
94
|
|
|
95
95
|
`--help` prints the same list. A flag of particular commands (`--sql`, `--plan`,
|
|
96
96
|
`--to`, `--ignore-table`, …) is refused by the others; connection, directory,
|
|
97
|
-
timeout and display flags are accepted everywhere
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
verification-server, profiler, timeout and display flags are accepted everywhere
|
|
98
|
+
and used where they apply; a flag that takes a value refuses an empty one. The
|
|
99
|
+
names in parentheses are the matching config and API options. With `--json`,
|
|
100
|
+
every command prints one JSON object: the result, with lists under a key
|
|
101
|
+
(`findings`, `migrations`, `steps`, `tables`, `requests`), or
|
|
102
|
+
`{"error": {"message": …}}` with exit code 1. Ctrl-C exits with 130 and SIGTERM
|
|
103
|
+
with 143. Ctrl-C at a question (the rollback confirmation, a rename, the
|
|
104
|
+
dashboard menu) exits with 130 too and rolls nothing back; Escape closes the
|
|
105
|
+
question without it. Config paths resolve relative to the config file. SQL lives
|
|
106
|
+
in `migrations/<id>/`; metadata lives in `migrations/meta/snapshot.json` and
|
|
107
|
+
`migrations/meta/migration.json`. Commit SQL and both JSON files together.
|
|
108
|
+
`diff` compares snapshots, not live DB drift.
|
|
109
|
+
|
|
110
|
+
`init` writes the tables, connection module and config of a new project and
|
|
111
|
+
keeps every file that exists. When `src/database/schema.ts` exists, the
|
|
112
|
+
connection module and config import its schema: its `appSchema` export, or else
|
|
113
|
+
the one `schema(…)` value it exports, by name or as its default. The module is
|
|
114
|
+
read, not run; when it offers no such value, several, or a form init cannot read
|
|
115
|
+
with certainty (`export *`, a re-export, a schema inside an object or a wrapper
|
|
116
|
+
call), init creates nothing, says what to add and exits with 1.
|
|
105
117
|
|
|
106
118
|
<picture>
|
|
107
119
|
<source media="(prefers-reduced-motion: reduce)" srcset="https://raw.githubusercontent.com/nokturnal3301/symmetria/main/docs/assets/kit-schema.png">
|
|
@@ -111,12 +123,14 @@ and both JSON files together. `diff` compares snapshots, not live DB drift.
|
|
|
111
123
|
The snapshot holds the latest generated schema. The journal holds IDs, parents
|
|
112
124
|
and schema hashes for the whole chain, without historical snapshot copies, and
|
|
113
125
|
the snapshot before the latest migration (`undo`), so that one step can be taken
|
|
114
|
-
back
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
126
|
+
back, and `repair --action retry` of the latest migration can verify its
|
|
127
|
+
starting point without `--verify-url` or `--snapshot`. Generation updates the
|
|
128
|
+
same two files; migrate/rollback only change database history and use
|
|
129
|
+
`up.sql`/`down.sql`. `generate --json` reports the SQL and metadata directories,
|
|
130
|
+
and the findings `lint` would report for the new migration, which `generate`
|
|
131
|
+
also prints: a destructive change is refused without `--allow-destructive`, and
|
|
132
|
+
cautions (a table rewritten, an index built while writes wait) are shown with
|
|
133
|
+
the generated files.
|
|
120
134
|
|
|
121
135
|
`discard` removes the latest migration and puts the snapshot and the journal
|
|
122
136
|
back as they were before it was generated, so the next `generate` starts from
|
|
@@ -143,20 +157,22 @@ latest migration snapshot) with keys, nullable columns and relation
|
|
|
143
157
|
cardinalities; `graph docs/schema.md` writes it inside a `mermaid` fence that
|
|
144
158
|
GitHub renders. `--compact` leaves out column lists; `--json` returns the tables
|
|
145
159
|
and edges; `schemaGraph()` and `renderMermaid()` expose the same
|
|
146
|
-
programmatically.
|
|
160
|
+
programmatically. A column name Mermaid cannot take as it is (a space, a quote,
|
|
161
|
+
a leading digit) is written in a safe form with the real name in its note:
|
|
162
|
+
`First_Name "name: First Name"`.
|
|
147
163
|
|
|
148
164
|
```mermaid
|
|
149
165
|
erDiagram
|
|
150
|
-
users {
|
|
151
|
-
integer id PK "identity"
|
|
152
|
-
text email UK
|
|
153
|
-
}
|
|
154
166
|
posts {
|
|
155
167
|
integer id PK "identity"
|
|
156
168
|
integer author_id FK
|
|
157
169
|
integer editor_id FK "nullable"
|
|
158
170
|
text title
|
|
159
171
|
}
|
|
172
|
+
users {
|
|
173
|
+
integer id PK "identity"
|
|
174
|
+
text email UK
|
|
175
|
+
}
|
|
160
176
|
|
|
161
177
|
users ||..o{ posts : author
|
|
162
178
|
users |o..o{ posts : editor
|
|
@@ -193,19 +209,22 @@ review: constraints with non-conventional names, Prisma's `_AB_pkey` junction
|
|
|
193
209
|
keys included (with the `RENAME CONSTRAINT` that fixes them), serial columns
|
|
194
210
|
(with a fix that makes them `BY DEFAULT` identities continuing after the
|
|
195
211
|
existing rows and drops the old sequence), types without a builder such as
|
|
196
|
-
`money` (declared through `customType()`),
|
|
197
|
-
(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
212
|
+
`money` (declared through `customType()`), columns of a domain type (declared
|
|
213
|
+
through `customType()` with the domain's base type, so a domain over `bigint`
|
|
214
|
+
reads bigints; migrations do not create the domain), multi-column unique
|
|
215
|
+
constraints (declared as unique indexes), unique indexes that stand in for
|
|
216
|
+
constraints (with the `ADD CONSTRAINT … USING INDEX` that converts them),
|
|
217
|
+
composite or deferrable foreign keys, and the views, materialized views and
|
|
218
|
+
triggers the schema does not manage. Things that exist only in the database are
|
|
219
|
+
listed too, so nothing disappears without a word: table inheritance
|
|
220
|
+
(`inheritance`), row-level security and policies (`row-security`), functions and
|
|
221
|
+
procedures (`function`), sequences no column owns or several columns share
|
|
222
|
+
(`sequence`, without the identity fix, which would drop the shared sequence),
|
|
223
|
+
identity columns whose sequence starts or steps differently (`sequence`),
|
|
224
|
+
`UNLOGGED` tables (`unlogged`) and the number of tables in other schemas, which
|
|
225
|
+
`pull` does not read (`other-schema`). The same list is in `--json` output under
|
|
226
|
+
`warnings`, each with a `code` and, when one exists, a `fix`. The file is never
|
|
227
|
+
overwritten without `--force`.
|
|
209
228
|
|
|
210
229
|
Then point `symmetria.config.ts` at the module, run `drift` until the remaining
|
|
211
230
|
findings are intended, generate the first migration with `generate initial` and
|
|
@@ -251,10 +270,15 @@ can stay until Prisma no longer deploys.
|
|
|
251
270
|
`up.sql`) and lists it; `--allow-custom-sql` confirms.
|
|
252
271
|
- `--online` generates concurrent indexes, phased constraint validation and
|
|
253
272
|
additive enum changes with commit boundaries. Incomplete nontransactional work
|
|
254
|
-
persists in the journal and requires explicit `repair
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
273
|
+
persists in the journal and requires explicit `repair`; `status` and `drift`
|
|
274
|
+
tell a migration another process is still running (it holds the migration
|
|
275
|
+
lock) from one that stopped part-way, and `drift` names the `repair` it needs.
|
|
276
|
+
- DDL lock, statement and advisory-lock timeouts are configurable. Ctrl-C or
|
|
277
|
+
SIGTERM during a database command cancels the running statement and waits up
|
|
278
|
+
to five seconds for its rollback, so its locks end with it; when the server
|
|
279
|
+
does not answer in that time, the CLI exits anyway and says whether a
|
|
280
|
+
statement may still be running. A second Ctrl-C exits at once. The API accepts
|
|
281
|
+
an abort signal and statement-level events.
|
|
258
282
|
- `drift` checks defaults, identities, PK/FK/UNIQUE/CHECK definitions, FK
|
|
259
283
|
actions, enums, indexes and validation state. On a database that is some
|
|
260
284
|
migrations behind the local chain (after `rollback`, say) it reports that
|
|
@@ -313,14 +337,16 @@ requested. Offline SQL inspection works without a database.
|
|
|
313
337
|
|
|
314
338
|
Exports: `defineMigrationConfig`, `migrationSnapshot`, `parseMigrationSnapshot`,
|
|
315
339
|
`snapshotHash`, `emptySnapshot`, `createSchemaSQL`, `diffSchemas`,
|
|
316
|
-
`generateMigration`, `
|
|
317
|
-
`lintMigration`, `lintMigrationSQL`, `detectDrift`,
|
|
318
|
-
`
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
340
|
+
`generateMigration`, `discardMigration`, `loadMigrations`, `loadMigrationState`,
|
|
341
|
+
`squashMigrations`, `lintMigration`, `lintMigrationSQL`, `detectDrift`,
|
|
342
|
+
`normalizeSqlType`, `verifyMigrations`, `recoverMigrationFiles`, `pullSchema`,
|
|
343
|
+
`schemaGraph`, `renderMermaid`, their formatting helpers,
|
|
344
|
+
`MigrationExecutionError` and `migrator`, with their associated types.
|
|
345
|
+
`pullSchema({ execute, ignoreTables })` returns the generated source, the
|
|
346
|
+
declared tables and the review warnings without touching the file system.
|
|
347
|
+
`loadMigrationState` returns `{ migrations, snapshot }`; only the current schema
|
|
348
|
+
snapshot is stored. Generated and squashed migrations include their new
|
|
349
|
+
snapshot.
|
|
324
350
|
|
|
325
351
|
```ts
|
|
326
352
|
import { postgres } from "symmetria/driver";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { QueryInspectionController } from "symmetria/internal";
|
|
2
2
|
//#region src/cli/screens/query-inspector.d.ts
|
|
3
|
-
export declare const terminalText: (text: string) => string;
|
|
4
3
|
export declare const inspectValue: (value: unknown, expanded?: boolean) => string;
|
|
5
4
|
/**
|
|
6
5
|
* Plan lines wrapped to `width` under their tree gutter: a long relation or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as explainLines, n as inspectQueryScreen, r as inspectValue, i as
|
|
1
|
+
export { t as explainLines, n as inspectQueryScreen, r as inspectValue, i as wrapExplainLines } from "../query-inspector-BolQM66i.js";
|