symmetria-kit 3.5.0 → 3.7.1

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,88 @@ 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
+ | `--connect-timeout <ms>` | database commands, `pull`, `lint` | How long the database may take to accept a connection (default 30000; 0 disables) |
66
+ | `--json` | all | One JSON object on stdout, `{"error": …}` on failure |
67
+ | `--sql` | `diff` | Print executable SQL |
68
+ | `--diff <file.json>` | `generate`, `diff`, `lint` | Rename hints and `USING` conversions |
69
+ | `--empty` | `generate` | An empty, editable SQL migration |
70
+ | `--allow-destructive` | `generate` | Permit drops and narrowing type changes (`allowDestructive`) |
71
+ | `--transaction <mode>` | `generate` | `batch` (default), `each` or `none` (`transaction`) |
72
+ | `--online` | `generate`, `diff`, `lint` | Concurrent indexes and phased validation (`online`) |
73
+ | `--allow-custom-sql` | `squash` | Drop SQL that generate did not write (`allowCustomSQL`) |
74
+ | `--pending` | `lint` | Only migrations pending in the database |
75
+ | `--strict` | `lint`, `drift` | Exit with code 1 for any finding |
76
+ | `--to <id>` | `migrate`, `adopt` | Apply up to, or adopt through, a migration (`to`) |
77
+ | `--steps <n>` | `rollback` | Number of migrations to revert (`steps`) |
78
+ | `--yes` | `rollback` | Run `down.sql` without asking; required without a terminal |
79
+ | `--plan` | `migrate`, `rollback` | Show SQL and transaction groups without running them |
80
+ | `--action <action>` | `repair` | `retry` or `complete` (`action`) |
81
+ | `--verify-url <url>` | `verify`, `adopt`, `repair`, `drift` | Server for disposable databases (`verificationDatabaseUrl`) |
82
+ | `--snapshot <file>` | `repair` | Snapshot file of the boundary to verify, instead of `--verify-url` |
83
+ | `--ignore-table <name>` | `pull`, `drift`, `adopt`, `repair`, `verify` | Leave an undeclared table out, repeatable (`ignoreTables`) |
84
+ | `--advisory-lock-timeout <ms>` | commands that run migrations | Migration lock wait (`advisoryLockTimeoutMs`, default 10000) |
85
+ | `--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) |
86
+ | `--statement-timeout <ms>` | commands that run migrations | Statement duration (`statementTimeoutMs`, default 600000; no default limit in `transaction: "none"` migrations) |
87
+ | `--force` | `pull`, `graph`, `discard` | Overwrite the written file; `discard`: no database to ask, or an `up.sql` edited after generation |
88
+ | `--compact` | `graph` | Entities and relations without column lists |
89
+ | `--relations` | `inspect` | Start on, or list, the relations |
90
+ | `--profile-url <url>` | `profile` | Profiler endpoint (default `http://127.0.0.1:7331`) |
91
+ | `--profile-token <token>` | `profile` | Profiler token (default `SYMMETRIA_PROFILE_TOKEN`) |
92
+ | `--no-interactive` | all | No dashboard, schema browser or rename questions |
93
+ | `--no-color`, `--no-animation` | all | Plain output; no logo or spinner animation |
94
+ | `--help`, `-h` | all | Show the commands and flags |
95
+ | `--version`, `-v` | all | Print the version of symmetria-kit |
94
96
 
95
97
  `--help` prints the same list. A flag of particular commands (`--sql`, `--plan`,
96
98
  `--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.
99
+ verification-server, profiler, timeout and display flags are accepted everywhere
100
+ and used where they apply; a flag that takes a value refuses an empty one. The
101
+ names in parentheses are the matching config and API options. With `--json`,
102
+ every command prints one JSON object: the result, with lists under a key
103
+ (`findings`, `migrations`, `steps`, `tables`, `requests`), or
104
+ `{"error": {"message": …}}` with exit code 1. Ctrl-C exits with 130 and SIGTERM
105
+ with 143. Ctrl-C at a question (the rollback confirmation, a rename, the
106
+ dashboard menu) exits with 130 too and rolls nothing back; Escape closes the
107
+ question without it. Config paths resolve relative to the config file. SQL lives
108
+ in `migrations/<id>/`; metadata lives in `migrations/meta/snapshot.json` and
109
+ `migrations/meta/migration.json`; dot-files such as `.DS_Store` beside them are
110
+ ignored. Commit SQL and both JSON files together. `diff` compares snapshots, not
111
+ live DB drift.
112
+
113
+ A migrations directory that does not exist is not an empty chain. The commands
114
+ that read it (`migrate`, `status`, `rollback`, `verify`, `adopt`, `repair`,
115
+ `drift`, `lint`, `squash`, `discard`, `recover`) fail when the directory named
116
+ with `--dir` is missing, and when neither a config file nor `./migrations` is
117
+ found where the command runs (the message names the config path it looked for).
118
+ In a project whose config file is found and whose directory does not exist yet,
119
+ `migrate`, `status`, `rollback`, `verify`, `squash` and `recover` still exit
120
+ with 0 and say that `symmetria generate <name>` creates the first migration;
121
+ their `--json` output names the directory under `missingDirectory`. The
122
+ dashboard's header says the same in place of its migration counts.
123
+
124
+ A database URL (`--database-url`, `databaseUrl`, `DATABASE_URL`, `--verify-url`,
125
+ `verificationDatabaseUrl`) starts with `postgres://` or `postgresql://`; a
126
+ socket directory is given in the URL
127
+ (`postgres:///app?host=/var/run/postgresql`) or, for the project's database, as
128
+ its path (`/var/run/postgresql`). Text without the scheme, such as
129
+ `host:5432/app`, is refused: node-postgres would find no host in it and connect
130
+ to localhost. The error names the flag or setting, never the value. White space
131
+ around the URL is dropped. A URL with an `@` after its host is refused too: a
132
+ password that holds `/`, `?` or `#` unencoded ends the host early; write them
133
+ percent-encoded (`%2F`, `%3F`, `%23`, and `%40` for `@`).
134
+
135
+ `init` writes the tables, connection module and config of a new project and
136
+ keeps every file that exists. When `src/database/schema.ts` exists, the
137
+ connection module and config import its schema: its `appSchema` export, or else
138
+ the one `schema(…)` value it exports, by name or as its default. The module is
139
+ read, not run; when it offers no such value, several, or a form init cannot read
140
+ with certainty (`export *`, a re-export, a schema inside an object or a wrapper
141
+ call), init creates nothing, says what to add and exits with 1.
105
142
 
106
143
  <picture>
107
144
  <source media="(prefers-reduced-motion: reduce)" srcset="https://raw.githubusercontent.com/nokturnal3301/symmetria/main/docs/assets/kit-schema.png">
@@ -111,24 +148,36 @@ and both JSON files together. `diff` compares snapshots, not live DB drift.
111
148
  The snapshot holds the latest generated schema. The journal holds IDs, parents
112
149
  and schema hashes for the whole chain, without historical snapshot copies, and
113
150
  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.
151
+ back, and `repair --action retry` of the latest migration can verify its
152
+ starting point without `--verify-url` or `--snapshot`. Generation updates the
153
+ same two files; migrate/rollback only change database history and use
154
+ `up.sql`/`down.sql`. `generate --json` reports the SQL and metadata directories,
155
+ and the findings `lint` would report for the new migration, which `generate`
156
+ also prints: a destructive change is refused without `--allow-destructive`, and
157
+ cautions (a table rewritten, an index built while writes wait) are shown with
158
+ the generated files.
120
159
 
121
160
  `discard` removes the latest migration and puts the snapshot and the journal
122
161
  back as they were before it was generated, so the next `generate` starts from
123
162
  there. It asks the configured database first and refuses a migration that is
124
- applied or incomplete there (roll it back, then discard it); without a database,
163
+ applied or incomplete there (roll it back, then discard it), and refuses while
164
+ another process is applying migrations to that database, which `--force` does
165
+ not override: the migration may be the one being applied. A run that has read
166
+ the directory and holds no lock yet is covered as well: `discard` asks again
167
+ with the directory locked, and a run reads the directory again once it holds the
168
+ migration lock and stops when a migration it read is gone. Without a database,
125
169
  `--force` says that none has applied it. It also refuses an `up.sql` edited
126
170
  after generation, which `--force` would lose. Migrations generated by earlier
127
171
  releases have no `undo` record; `discard` then takes the earlier snapshot from
128
172
  the Git history of `meta/snapshot.json`. When a migration was deleted by hand
129
173
  and `generate`, `status` and `diff` stop with "latest snapshot checksum does not
130
- match the migration journal", `discard` without an ID puts the snapshot back
131
- from the same places.
174
+ match the migration journal" or "migration journal … does not match the SQL
175
+ directories", `discard` without an ID repairs the chain: it takes a latest
176
+ migration whose directory is gone out of the journal, after the same question to
177
+ the database (or `--force` without one), and puts the snapshot back from the
178
+ same places. The database is asked through its journal table alone, so the
179
+ question works while the local chain does not load; putting back only the
180
+ snapshot asks nothing.
132
181
 
133
182
  The database journal defaults to `public._symmetria_migrations`.
134
183
  `metadataSchema` and `metadataTable` configure its location; migrations create a
@@ -143,20 +192,22 @@ latest migration snapshot) with keys, nullable columns and relation
143
192
  cardinalities; `graph docs/schema.md` writes it inside a `mermaid` fence that
144
193
  GitHub renders. `--compact` leaves out column lists; `--json` returns the tables
145
194
  and edges; `schemaGraph()` and `renderMermaid()` expose the same
146
- programmatically.
195
+ programmatically. A column name Mermaid cannot take as it is (a space, a quote,
196
+ a leading digit) is written in a safe form with the real name in its note:
197
+ `First_Name "name: First Name"`.
147
198
 
148
199
  ```mermaid
149
200
  erDiagram
150
- users {
151
- integer id PK "identity"
152
- text email UK
153
- }
154
201
  posts {
155
202
  integer id PK "identity"
156
203
  integer author_id FK
157
204
  integer editor_id FK "nullable"
158
205
  text title
159
206
  }
207
+ users {
208
+ integer id PK "identity"
209
+ text email UK
210
+ }
160
211
 
161
212
  users ||..o{ posts : author
162
213
  users |o..o{ posts : editor
@@ -193,19 +244,26 @@ review: constraints with non-conventional names, Prisma's `_AB_pkey` junction
193
244
  keys included (with the `RENAME CONSTRAINT` that fixes them), serial columns
194
245
  (with a fix that makes them `BY DEFAULT` identities continuing after the
195
246
  existing rows and drops the old sequence), types without a builder such as
196
- `money` (declared through `customType()`), multi-column unique constraints
197
- (declared as unique indexes), unique indexes that stand in for constraints (with
198
- the `ADD CONSTRAINT … USING INDEX` that converts them), composite or deferrable
199
- foreign keys, and the views, materialized views and triggers the schema does not
247
+ `money` (declared through `customType()`), columns of a domain type (declared
248
+ through `customType()` with the domain's base type, so a domain over `bigint`
249
+ reads bigints; migrations do not create the domain), multi-column unique
250
+ constraints (declared as unique indexes; a `DEFERRABLE` one without a fix,
251
+ because an index checks at once), unique indexes that stand in for constraints
252
+ (with the `ADD CONSTRAINT … USING INDEX` that converts them), composite or
253
+ deferrable foreign keys, every further foreign key of a column that has more
254
+ than one (the schema declares one per column), operator class parameters of an
255
+ index key, and the views, materialized views and triggers the schema does not
200
256
  manage. Things that exist only in the database are listed too, so nothing
201
257
  disappears without a word: table inheritance (`inheritance`), row-level security
202
258
  and policies (`row-security`), functions and procedures (`function`), sequences
203
259
  no column owns or several columns share (`sequence`, without the identity fix,
204
260
  which would drop the shared sequence), identity columns whose sequence starts or
205
- steps differently (`sequence`), `UNLOGGED` tables (`unlogged`) and the number of
206
- tables in other schemas, which `pull` does not read (`other-schema`). The same
207
- list is in `--json` output under `warnings`, each with a `code` and, when one
208
- exists, a `fix`. The file is never overwritten without `--force`.
261
+ steps differently (`sequence`), `UNLOGGED` tables (`unlogged`), table storage
262
+ parameters such as `fillfactor` (`storage-parameters`), rules (`rule`), foreign
263
+ tables (`foreign-table`) and the number of tables in other schemas, which `pull`
264
+ does not read (`other-schema`). The same list is in `--json` output under
265
+ `warnings`, each with a `code` and, when one exists, a `fix`. The file is never
266
+ overwritten without `--force`.
209
267
 
210
268
  Then point `symmetria.config.ts` at the module, run `drift` until the remaining
211
269
  findings are intended, generate the first migration with `generate initial` and
@@ -251,10 +309,26 @@ can stay until Prisma no longer deploys.
251
309
  `up.sql`) and lists it; `--allow-custom-sql` confirms.
252
310
  - `--online` generates concurrent indexes, phased constraint validation and
253
311
  additive enum changes with commit boundaries. Incomplete nontransactional work
254
- persists in the journal and requires explicit `repair`.
255
- - DDL lock, statement and advisory-lock timeouts are configurable.
256
- SIGINT/SIGTERM cancel CLI work; the API accepts an abort signal and
257
- statement-level events.
312
+ persists in the journal and requires explicit `repair`; `status` and `drift`
313
+ tell a migration another process is still running (it holds the migration
314
+ lock) from one that stopped part-way, and `drift` names the `repair` it needs.
315
+ - DDL lock, statement and advisory-lock timeouts are configurable. Ctrl-C or
316
+ SIGTERM during a database command cancels the running statement and waits up
317
+ to five seconds for its rollback, so its locks end with it; when the server
318
+ does not answer in that time, the CLI exits anyway and says whether a
319
+ statement may still be running. A second Ctrl-C exits at once, and so does the
320
+ first while no connection to the database (for `verify`, to the verification
321
+ server) has been made. The API accepts an abort signal and statement-level
322
+ events.
323
+ - A database that does not accept a connection within `--connect-timeout` (30
324
+ seconds unless set; 0 waits as long as the operating system does) ends the
325
+ command with an error that names the host and port. The limit covers every
326
+ connection the command opens to the database and to the verification server
327
+ (`--verify-url`), and none of their statements.
328
+ - Ctrl-C or SIGTERM during `generate`, `squash` or `discard` stops before
329
+ anything is published and leaves no lock behind (`signal` in the API). A
330
+ generator that was killed leaves its lock, every command then names
331
+ `symmetria recover`, and `recover` also removes the files it had staged.
258
332
  - `drift` checks defaults, identities, PK/FK/UNIQUE/CHECK definitions, FK
259
333
  actions, enums, indexes and validation state. On a database that is some
260
334
  migrations behind the local chain (after `rollback`, say) it reports that
@@ -313,14 +387,16 @@ requested. Offline SQL inspection works without a database.
313
387
 
314
388
  Exports: `defineMigrationConfig`, `migrationSnapshot`, `parseMigrationSnapshot`,
315
389
  `snapshotHash`, `emptySnapshot`, `createSchemaSQL`, `diffSchemas`,
316
- `generateMigration`, `loadMigrations`, `loadMigrationState`, `squashMigrations`,
317
- `lintMigration`, `lintMigrationSQL`, `detectDrift`, `verifyMigrations`,
318
- `recoverMigrationFiles`, `pullSchema`, their formatting helpers, and `migrator`
319
- with their associated types. `pullSchema({ execute, ignoreTables })` returns the
320
- generated source, the declared tables and the review warnings without touching
321
- the file system. `loadMigrationState` returns `{ migrations, snapshot }`; only
322
- the current schema snapshot is stored. Generated and squashed migrations include
323
- their new snapshot.
390
+ `generateMigration`, `discardMigration`, `loadMigrations`, `loadMigrationState`,
391
+ `squashMigrations`, `lintMigration`, `lintMigrationSQL`, `detectDrift`,
392
+ `normalizeSqlType`, `verifyMigrations`, `recoverMigrationFiles`, `pullSchema`,
393
+ `schemaGraph`, `renderMermaid`, their formatting helpers,
394
+ `MigrationExecutionError` and `migrator`, with their associated types.
395
+ `pullSchema({ execute, ignoreTables })` returns the generated source, the
396
+ declared tables and the review warnings without touching the file system.
397
+ `loadMigrationState` returns `{ migrations, snapshot }`; only the current schema
398
+ snapshot is stored. Generated and squashed migrations include their new
399
+ snapshot.
324
400
 
325
401
  ```ts
326
402
  import { postgres } from "symmetria/driver";
@@ -341,6 +417,11 @@ try {
341
417
  tables and returns a typed database. Closing it drops that schema and its data.
342
418
  Extensions the schema needs, such as pgvector for a search by meaning, are
343
419
  installed when missing and found on the search path without further options.
420
+ Start-up settings in the URL's `options` parameter (`-c TimeZone=…`,
421
+ `-c statement_timeout=…`) apply to the test pool too; the test schema's
422
+ `search_path` is added after them and wins over one they set. The URL starts
423
+ with `postgres://` or `postgresql://`; other text is refused before anything is
424
+ created.
344
425
 
345
426
  ```ts
346
427
  import { testDatabase } from "symmetria-kit/testing";
@@ -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-DGaa-bK6.js";
1
+ export { t as explainLines, n as inspectQueryScreen, r as inspectValue, i as wrapExplainLines } from "../query-inspector-S6bPVzZd.js";