symmetria-kit 3.6.0 → 4.0.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
@@ -62,6 +62,7 @@ export default defineMigrationConfig({
62
62
  | `--config <file>` | all | Config module (default `symmetria.config.ts`) |
63
63
  | `--dir <directory>` | all with a project | Migrations directory, relative to the working directory |
64
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) |
65
66
  | `--json` | all | One JSON object on stdout, `{"error": …}` on failure |
66
67
  | `--sql` | `diff` | Print executable SQL |
67
68
  | `--diff <file.json>` | `generate`, `diff`, `lint` | Rename hints and `USING` conversions |
@@ -91,6 +92,7 @@ export default defineMigrationConfig({
91
92
  | `--no-interactive` | all | No dashboard, schema browser or rename questions |
92
93
  | `--no-color`, `--no-animation` | all | Plain output; no logo or spinner animation |
93
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,
@@ -104,8 +106,31 @@ with 143. Ctrl-C at a question (the rollback confirmation, a rename, the
104
106
  dashboard menu) exits with 130 too and rolls nothing back; Escape closes the
105
107
  question without it. Config paths resolve relative to the config file. SQL lives
106
108
  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
+ `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 `@`).
109
134
 
110
135
  `init` writes the tables, connection module and config of a new project and
111
136
  keeps every file that exists. When `src/database/schema.ts` exists, the
@@ -135,14 +160,24 @@ the generated files.
135
160
  `discard` removes the latest migration and puts the snapshot and the journal
136
161
  back as they were before it was generated, so the next `generate` starts from
137
162
  there. It asks the configured database first and refuses a migration that is
138
- 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,
139
169
  `--force` says that none has applied it. It also refuses an `up.sql` edited
140
170
  after generation, which `--force` would lose. Migrations generated by earlier
141
171
  releases have no `undo` record; `discard` then takes the earlier snapshot from
142
172
  the Git history of `meta/snapshot.json`. When a migration was deleted by hand
143
173
  and `generate`, `status` and `diff` stop with "latest snapshot checksum does not
144
- match the migration journal", `discard` without an ID puts the snapshot back
145
- 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.
146
181
 
147
182
  The database journal defaults to `public._symmetria_migrations`.
148
183
  `metadataSchema` and `metadataTable` configure its location; migrations create a
@@ -212,17 +247,21 @@ existing rows and drops the old sequence), types without a builder such as
212
247
  `money` (declared through `customType()`), columns of a domain type (declared
213
248
  through `customType()` with the domain's base type, so a domain over `bigint`
214
249
  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
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
256
+ manage. Things that exist only in the database are listed too, so nothing
257
+ disappears without a word: table inheritance (`inheritance`), row-level security
258
+ and policies (`row-security`), functions and procedures (`function`), sequences
259
+ no column owns or several columns share (`sequence`, without the identity fix,
260
+ which would drop the shared sequence), identity columns whose sequence starts or
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
226
265
  `warnings`, each with a `code` and, when one exists, a `fix`. The file is never
227
266
  overwritten without `--force`.
228
267
 
@@ -277,8 +316,19 @@ can stay until Prisma no longer deploys.
277
316
  SIGTERM during a database command cancels the running statement and waits up
278
317
  to five seconds for its rollback, so its locks end with it; when the server
279
318
  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.
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.
282
332
  - `drift` checks defaults, identities, PK/FK/UNIQUE/CHECK definitions, FK
283
333
  actions, enums, indexes and validation state. On a database that is some
284
334
  migrations behind the local chain (after `rollback`, say) it reports that
@@ -344,9 +394,12 @@ Exports: `defineMigrationConfig`, `migrationSnapshot`, `parseMigrationSnapshot`,
344
394
  `MigrationExecutionError` and `migrator`, with their associated types.
345
395
  `pullSchema({ execute, ignoreTables })` returns the generated source, the
346
396
  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.
397
+ `loadMigrationState` returns `{ migrations, snapshot, undo? }`: the SQL chain,
398
+ the current schema snapshot and `undo: { migration, snapshot }`, the snapshot
399
+ from before the latest migration, which `generate` keeps in the journal so that
400
+ `discard` can take that migration back (absent after a squash or a discard). No
401
+ other earlier snapshot is stored. Generated and squashed migrations include
402
+ their new snapshot.
350
403
 
351
404
  ```ts
352
405
  import { postgres } from "symmetria/driver";
@@ -367,6 +420,11 @@ try {
367
420
  tables and returns a typed database. Closing it drops that schema and its data.
368
421
  Extensions the schema needs, such as pgvector for a search by meaning, are
369
422
  installed when missing and found on the search path without further options.
423
+ Start-up settings in the URL's `options` parameter (`-c TimeZone=…`,
424
+ `-c statement_timeout=…`) apply to the test pool too; the test schema's
425
+ `search_path` is added after them and wins over one they set. The URL starts
426
+ with `postgres://` or `postgresql://`; other text is refused before anything is
427
+ created.
370
428
 
371
429
  ```ts
372
430
  import { testDatabase } from "symmetria-kit/testing";
@@ -1 +1 @@
1
- export { t as explainLines, n as inspectQueryScreen, r as inspectValue, i as wrapExplainLines } from "../query-inspector-BolQM66i.js";
1
+ export { t as explainLines, n as inspectQueryScreen, r as inspectValue, i as wrapExplainLines } from "../query-inspector-C5e2s4hC.js";