symmetria-kit 3.4.1 → 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 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` | 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) |
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. The names in parentheses are
98
- the matching config and API options. With `--json`, every command prints one
99
- JSON object: the result, with lists under a key (`findings`, `migrations`,
100
- `steps`, `tables`, `requests`), or `{"error": {"message": …}}` with exit code 1.
101
- Ctrl-C exits with 130 and SIGTERM with 143. Config paths resolve relative to the
102
- config file. SQL lives in `migrations/<id>/`; metadata lives in
103
- `migrations/meta/snapshot.json` and `migrations/meta/migration.json`. Commit SQL
104
- and both JSON files together. `diff` compares snapshots, not live DB drift.
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. Generation updates the same two files; migrate/rollback only change
115
- database history and use `up.sql`/`down.sql`. `generate --json` reports the SQL
116
- and metadata directories, and the findings `lint` would report for the new
117
- migration, which `generate` also prints: a destructive change is refused without
118
- `--allow-destructive`, and cautions (a table rewritten, an index built while
119
- writes wait) are shown with the generated files.
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
@@ -172,9 +188,10 @@ names (`oneOf(...).typeName("Role")`, shared by several columns too), foreign
172
188
  keys as relations (including `ON UPDATE CASCADE`, keys to unique columns and
173
189
  columns not named `*_id`, through `.by()` and `.column()`), junction tables,
174
190
  primary keys, unique columns, indexes (including expression, partial, ordered,
175
- `INCLUDE`, collated, `WITH (…)` and non-btree indexes) and CHECK constraints.
176
- Conditions are predicates where the DSL can write them as PostgreSQL stored them
177
- (`users.score.between(1, 10)`,
191
+ `INCLUDE`, collated, `WITH (…)` and non-btree indexes), CHECK constraints and
192
+ full-text searches (`.search()` with `fullText()`, for the column and index it
193
+ creates). Conditions are predicates where the DSL can write them as PostgreSQL
194
+ stored them (`users.score.between(1, 10)`,
178
195
  `and(users.status.is("active"), users.deletedAt.is(null))`), and `sql` text
179
196
  otherwise. A schema written with the DSL, migrated and pulled back needs no
180
197
  migration: `diff` and `generate` compare conditions in a normalized form, so
@@ -192,18 +209,22 @@ review: constraints with non-conventional names, Prisma's `_AB_pkey` junction
192
209
  keys included (with the `RENAME CONSTRAINT` that fixes them), serial columns
193
210
  (with a fix that makes them `BY DEFAULT` identities continuing after the
194
211
  existing rows and drops the old sequence), types without a builder such as
195
- `money` (declared through `customType()`), multi-column unique constraints
196
- (declared as unique indexes), unique indexes that stand in for constraints (with
197
- the `ADD CONSTRAINT … USING INDEX` that converts them), composite or deferrable
198
- foreign keys, and the views, materialized views and triggers the schema does not
199
- manage. Things that exist only in the database are listed too, so nothing
200
- disappears without a word: table inheritance (`inheritance`), row-level security
201
- and policies (`row-security`), functions and procedures (`function`), sequences
202
- no column owns or several columns share (`sequence`, without the identity fix,
203
- which would drop the shared sequence) and the number of tables in other schemas,
204
- which `pull` does not read (`other-schema`). The same list is in `--json` output
205
- under `warnings`, each with a `code` and, when one exists, a `fix`. The file is
206
- never overwritten without `--force`.
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`.
207
228
 
208
229
  Then point `symmetria.config.ts` at the module, run `drift` until the remaining
209
230
  findings are intended, generate the first migration with `generate initial` and
@@ -223,10 +244,13 @@ can stay until Prisma no longer deploys.
223
244
 
224
245
  - `generate` requires explicit rename hints or `--allow-destructive` for dropped
225
246
  tables/columns and for type changes that narrow existing values (a shorter
226
- `varchar`, fewer decimal places, a smaller integer type, an integer to
227
- `boolean`). A shorter string type is altered without a truncating cast, so
228
- PostgreSQL refuses values that do not fit instead of cutting them. Declared
229
- column order is preserved; snapshot hashes are order-independent.
247
+ `varchar`, fewer decimal places, a smaller integer type or fewer digits before
248
+ the decimal point, an integer to `boolean`). A type change PostgreSQL has no
249
+ cast for in either direction is refused until `using` gives both conversions,
250
+ and conversions that would read the migrating session's time zone convert at
251
+ UTC. A shorter string type is altered without a truncating cast, so PostgreSQL
252
+ refuses values that do not fit instead of cutting them. Declared column order
253
+ is preserved; snapshot hashes are order-independent.
230
254
  - `lint` checks actual `up.sql` even after generation and fails for destructive
231
255
  or blocking findings, reviewing every action of an `ALTER TABLE` and ignoring
232
256
  comments and strings. `CHECK` and foreign keys added without `NOT VALID` are
@@ -246,10 +270,15 @@ can stay until Prisma no longer deploys.
246
270
  `up.sql`) and lists it; `--allow-custom-sql` confirms.
247
271
  - `--online` generates concurrent indexes, phased constraint validation and
248
272
  additive enum changes with commit boundaries. Incomplete nontransactional work
249
- persists in the journal and requires explicit `repair`.
250
- - DDL lock, statement and advisory-lock timeouts are configurable.
251
- SIGINT/SIGTERM cancel CLI work; the API accepts an abort signal and
252
- statement-level events.
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.
253
282
  - `drift` checks defaults, identities, PK/FK/UNIQUE/CHECK definitions, FK
254
283
  actions, enums, indexes and validation state. On a database that is some
255
284
  migrations behind the local chain (after `rollback`, say) it reports that
@@ -308,14 +337,16 @@ requested. Offline SQL inspection works without a database.
308
337
 
309
338
  Exports: `defineMigrationConfig`, `migrationSnapshot`, `parseMigrationSnapshot`,
310
339
  `snapshotHash`, `emptySnapshot`, `createSchemaSQL`, `diffSchemas`,
311
- `generateMigration`, `loadMigrations`, `loadMigrationState`, `squashMigrations`,
312
- `lintMigration`, `lintMigrationSQL`, `detectDrift`, `verifyMigrations`,
313
- `recoverMigrationFiles`, `pullSchema`, their formatting helpers, and `migrator`
314
- with their associated types. `pullSchema({ execute, ignoreTables })` returns the
315
- generated source, the declared tables and the review warnings without touching
316
- the file system. `loadMigrationState` returns `{ migrations, snapshot }`; only
317
- the current schema snapshot is stored. Generated and squashed migrations include
318
- their new snapshot.
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.
319
350
 
320
351
  ```ts
321
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 terminalText, a as wrapExplainLines } from "../query-inspector-C-7K9wtB.js";
1
+ export { t as explainLines, n as inspectQueryScreen, r as inspectValue, i as wrapExplainLines } from "../query-inspector-BolQM66i.js";