ts-grm-migrate 0.1.0-alpha.5 → 0.1.0-alpha.7

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/CHANGELOG.md CHANGED
@@ -2,23 +2,51 @@
2
2
 
3
3
  English | [简体中文](docs/zh-CN/CHANGELOG.md)
4
4
 
5
- ## 0.1.0-alpha.4 (pending publication)
5
+ ## 0.1.0-alpha.7 (pending publication)
6
+
7
+ - Restore the SQLite introspection lost in 0.1.0-alpha.6: CHECK constraints, parent primary-key columns for foreign keys without explicit references, partial index predicates, explicit rejection of unsupported table/column/index structures, and NUMERIC affinity. Users of 0.1.0-alpha.6 with SQLite should upgrade.
8
+ - Failure logs state that a transaction was rolled back only when the executor confirms it, instead of matching error text. SQLite now reports an unconfirmed rollback when `ROLLBACK` itself fails.
9
+ - Document that programmatic `dev()` and `push()` apply destructive changes without asking unless a `confirm` hook is supplied.
10
+ - Enforce Biome's recommended lint rules and formatting in `check`; code comments are now written in Chinese.
11
+
12
+ ## 0.1.0-alpha.6 (2026-10-20)
13
+
14
+ - Add explicit `tgm seed` with executable/argument configuration, literal argument forwarding after `--`, local binary lookup, inherited environment and terminal I/O, exit-code propagation and interruption handling.
15
+ - Keep seeding independent of migration runtime, schema changes and history; add bilingual examples and subprocess/SQLite integration tests.
16
+ - **Known issue:** this release accidentally reverted the SQLite introspection hardening from 0.1.0-alpha.5. SQLite CHECK constraints are regenerated on every `dev`, foreign keys referencing an implicit primary key are misread, and unsupported structures are not rejected. Fixed in 0.1.0-alpha.7.
17
+
18
+ ## 0.1.0-alpha.5 (2026-10-11)
19
+
20
+ - Add `push --dry-run`. `push` is blocked by pending, failed, missing or modified migration files, and returns 1 when differences remain after synchronization or the user cancels. Applied migrations must form a continuous prefix of the ordered files.
21
+ - Round-trip supported CHECK expressions through catalog formatting and compare other expressions conservatively.
22
+ - SQLite keeps NUMERIC affinity separate from REAL, reads CHECK constraints and partial index predicates, drops referencing tables before their parents, and rejects cyclic drops, generated/hidden columns, special indexes that would be rewritten, and unsupported constraint semantics.
23
+ - Use atomic renewable directory leases (`proper-lockfile`) for local locks; crashed leases expire after 10 seconds. PostgreSQL runs the lock and all migration work on one session; SQLite file databases also lock the canonical file path.
24
+ - Document running the CLI in workspaces with non-hoisted dependencies (`npx --workspaces=false tgm`).
25
+
26
+ ## 0.1.0-alpha.4 (2026-10-09)
6
27
 
7
28
  - Localize configuration, history, locking, DDL, transaction and drift explanations throughout the CLI; preserve technical identifiers and expose original external diagnostics with `--detail`.
8
29
  - Explain model naming errors in the selected language and restrict ESM troubleshooting hints to module-format failures.
9
30
 
10
- ## 0.1.0-alpha.1 (pending publication)
31
+ ## 0.1.0-alpha.3 (2026-10-09)
11
32
 
12
33
  - Add `dev --create-only` and read-only `check`, validate history before development generation, preserve unmanaged indexes, order PostgreSQL dependencies, and handle MySQL identity/default changes together.
13
34
  - Compare defaults by dialect and column type without numeric precision loss; abort on patch metadata errors; report all unproven CHECK differences.
14
- - Repair isolated companion compatibility tests and add bilingual migration review, custom SQL, transaction recovery, and scope documentation.
15
35
  - Support column-level `default` and `autoIncrement` declared through the optional [`ts-grm-patches`](https://www.npmjs.com/package/ts-grm-patches) package, including the matching DDL for PostgreSQL, MySQL, SQLite, SQL Server, and Oracle, and normalize catalog default forms (`::type` casts, parentheses, `N` prefixes, numeric quoting) so migrations are not regenerated.
36
+ - Repair isolated companion compatibility tests and add bilingual migration review, custom SQL, transaction recovery, and scope documentation.
37
+
38
+ ## 0.1.0-alpha.2
39
+
40
+ Removed from the npm registry; not available for installation.
41
+
42
+ ## 0.1.0-alpha.1 (2026-09-26)
43
+
16
44
  - Make CLI output concise and English by default, with `--detail` diagnostics, `--lang zh-CN` Chinese messages, and a configuration setting for the default language.
17
45
  - Reduce default test output while retaining failure reasons and post-migration drift warnings.
18
46
  - Remove the automatic GitHub Actions workflow; maintainers now run pre-release verification and publishing manually.
19
47
  - Make English the primary documentation language and provide corresponding Simplified Chinese documents.
20
48
 
21
- ## 0.1.0-alpha.0
49
+ ## 0.1.0-alpha.0 (2026-09-24)
22
50
 
23
51
  - Add basic PostgreSQL and SQLite migrations and MySQL, SQL Server, and Oracle dialects.
24
52
  - Add durable unfinished-migration state, transactional success recording, exclusive migration-file creation, and stable database locks.
package/CONTRIBUTING.md CHANGED
@@ -19,7 +19,7 @@ corepack yarn test:postgres-mysql
19
19
  corepack yarn test:servers
20
20
  ```
21
21
 
22
- `check` runs lint, type checking, the build, and local tests. Server tests are skipped when their database environment variables are absent, so this is not a complete database verification. The two container scripts use Podman by default; set `CONTAINER_RUNTIME=docker` to use Docker. They create temporary containers on random ports and clean up only their own resources. Allow space for the images and do not test against an application database.
22
+ `check` runs Biome lint and format checks, type checking, the build, and local tests. Server tests are skipped when their database environment variables are absent, so this is not a complete database verification. The two container scripts use Podman by default; set `CONTAINER_RUNTIME=docker` to use Docker. They create temporary containers on random ports and clean up only their own resources. Allow space for the images and do not test against an application database.
23
23
 
24
24
  `TS_GRM_TEST_VERSION=0.0.9 corepack yarn test:servers` installs that historical version in an isolated directory before running real database tests. Compatibility checks do not alter repository dependencies or the lockfile. See [compatibility](docs/compatibility.md) for the supported range and reproduction steps.
25
25
 
@@ -31,7 +31,8 @@ corepack yarn test:servers
31
31
  - Keep access to ts-grm internals in `src/vendor/ts-grm.ts`; verify candidate versions before changing the peer range.
32
32
  - Keep the published package ESM and ts-grm external to the bundle so the host model registry is shared.
33
33
  - Mark external implementation references with `@see` and retain applicable licenses and attribution for adopted code.
34
- - Biome follows upstream formatting preferences. `yarn check` runs correctness lint without wholesale formatting of historical code.
34
+ - Biome follows upstream formatting preferences with the recommended lint rules. `yarn check` runs `biome check` (lint and formatting), so run `yarn format` before committing. Run `yarn check` before every commit; the repository has no CI to catch failures afterwards.
35
+ - Code comments are written in Chinese. Keep technical terms, identifiers, code examples and `@see` links in their original form. User-facing documentation remains English-first with a Simplified Chinese translation.
35
36
 
36
37
  Original contributions use MIT. See [third-party notices](THIRD_PARTY_NOTICES.md) for adapted code.
37
38
 
package/README.md CHANGED
@@ -81,9 +81,58 @@ npx tgm status # Inspect applied and pending migrations
81
81
  - `migrationsDir`: migration file directory; defaults to `./src/ts-grm`.
82
82
  - `schema`: target schema; defaults to `public` on PostgreSQL, `dbo` on SQL Server, and the login user's schema on Oracle.
83
83
  - `lockPath`: process lock file; defaults to `./.ts-grm-migrate.lock`.
84
+ - `seed`: optional `{ command: string, args?: string[] }` executable for `tgm seed`; see below.
84
85
 
85
86
  The CLI searches the project root for a `.ts`, `.mts`, `.mjs`, or `.js` configuration file. Use `--config <path>` to choose one explicitly. A `.ts` file follows the project's module type; in a CommonJS project, use `.mts` or set `"type": "module"`.
86
87
 
88
+ ## Database seeding
89
+
90
+ Add an optional `seed` executable and argument array to your existing configuration:
91
+
92
+ ```ts
93
+ seed: {
94
+ command: "node",
95
+ args: ["./src/ts-grm/seed.ts"],
96
+ },
97
+ ```
98
+
99
+ Run it explicitly after deploying the schema:
100
+
101
+ ```sh
102
+ npx tgm deploy && npx tgm seed
103
+ npx tgm seed -- --environment development
104
+ ```
105
+
106
+ The script can use your application's ts-grm client factory or a database driver. Reuse the same connection settings and target schema as the application. For example, with the PostgreSQL quick-start configuration and an `app_role(code, label)` table created by a migration in `public`:
107
+
108
+ ```ts
109
+ // src/ts-grm/seed.ts
110
+ import { Pool } from "pg";
111
+ import config from "../../ts-grm-migrate.config.ts";
112
+
113
+ const pool = new Pool(config.database);
114
+ try {
115
+ await pool.query(
116
+ `insert into app_role(code, label) values ($1, $2)
117
+ on conflict(code) do update set label = excluded.label`,
118
+ ["reader", "Reader"],
119
+ );
120
+ } finally {
121
+ await pool.end();
122
+ }
123
+ ```
124
+
125
+ - `command` is an executable, not a shell command string. Put each argument in `args`; quotes, spaces and shell characters are passed literally. Local `node_modules/.bin` directories in the project and its ancestors are searched before the inherited PATH. On Windows, use a native executable such as `node` with the runner's JavaScript entry point rather than a `.cmd`/`.bat` wrapper.
126
+ - All relative paths use the CLI working directory, including when `--config` selects a file elsewhere. The script inherits environment variables and terminal input/output. The CLI does not load `.env` automatically; load it in the configuration/script or launch with your environment configured.
127
+ - Node runs TypeScript supported by native type stripping; use a compiled ESM script or your installed TypeScript runner when additional transformations or path aliases are needed.
128
+ - Arguments after `--` are appended verbatim to the configured arguments. The script chooses how to parse them, including environment or dataset selection.
129
+ - Every invocation runs the script. Migration commands do not seed automatically; seed creates no migration history or locks. The script owns connection cleanup, transactions, dependency order and idempotency. Concurrent seed runs and runs overlapping migrations must be coordinated by the application or deployment workflow.
130
+ - A missing seed configuration, startup error or interruption fails the command. Numeric script exit codes are retained; SIGINT/SIGTERM return 130/143. On POSIX, these signals reach the seed process group; a process that does not exit is killed after five seconds. On Windows, interruption terminates the immediate seed process; descendant cleanup depends on the runner.
131
+
132
+ Use migration SQL for one-time data changes tied to a schema version. Use seed for repeatable initialization. This separation follows [Prisma's explicit seeding workflow](https://docs.prisma.io/docs/orm/v7/prisma-migrate/workflows/seeding).
133
+
134
+ Programmatic callers can use `runSeed(seed, cwd, args?)`, which returns the exit code, inherits process I/O and temporarily handles SIGINT/SIGTERM. It does not create a migration runtime.
135
+
87
136
  ## Defaults and auto-increment (optional)
88
137
 
89
138
  Upstream ts-grm column metadata expresses neither column defaults nor auto-increment, so a model cannot declare `serial` / `identity` / `auto_increment` or a `DEFAULT` value on its own. As of this release that capability comes from a companion package, [ts-grm-patches](https://www.npmjs.com/package/ts-grm-patches); install it alongside the CLI:
@@ -252,7 +301,7 @@ export const SYS_USER = model("SysUser", "id", class {
252
301
  - **History validation:** `dev` and `deploy` reject changed or missing applied files. `dev` refuses to generate while pending files exist; apply them with `deploy` first.
253
302
  - **Independent indexes and comments are not managed by models:** custom migration indexes are preserved while their columns remain. Explicit programmatic schemas may manage indexes; removing a unique index is flagged as destructive.
254
303
  - **Migration files are readable SQL:** `<migrationsDir>/<timestamp>_<name>.sql` can be edited before application. **Do not edit an applied migration.** `deploy` rejects a changed checksum; make a new migration instead.
255
- - **Destructive changes require confirmation:** dropping tables or columns, changing column types, and explicit unique-index removal prompt during model synchronization; non-interactive synchronization requires `--force`. `deploy` applies reviewed SQL files without confirmation.
304
+ - **Destructive changes require confirmation:** dropping tables or columns, changing column types, and explicit unique-index removal prompt during model synchronization; non-interactive synchronization requires `--force`. `deploy` applies reviewed SQL files without confirmation. Programmatic `Migrator` calls only ask when a `confirm` hook is supplied: without it, `dev()` and `push()` apply destructive changes immediately. Pass `confirm`, or review SQL first with `push({ dryRun: true })` or `dev({ createOnly: true })`.
256
305
  - **Post-migration checks:** `dev` and `deploy` reread the schema and warn about remaining differences. `push` returns 1 if differences remain after synchronization; cancellation also returns 1. `check` returns 1 for differences, including CHECK constraints whose equivalence cannot be proven. For example:
257
306
 
258
307
  ```text
package/dist/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { K as formatError, n as run, r as messages, t as parseArgs, y as MigrationAbortedError } from "./cli-Cfr6e9vX.mjs";
2
+ import { C as MigrationAbortedError, L as messages, n as run, q as formatError, t as parseArgs } from "./cli-BfbPTbqG.mjs";
3
3
  //#region src/bin.ts
4
4
  async function main() {
5
5
  const argv = process.argv.slice(2);
package/dist/bin.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.mjs","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { parseArgs, run } from \"./cli.js\";\nimport { messages, type CliLanguage } from \"./cli/messages.js\";\nimport { MigrationAbortedError } from \"./migrator.js\";\nimport { formatError } from \"./diagnostics/error.js\";\n\nasync function main(): Promise<void> {\n const argv = process.argv.slice(2);\n let language: CliLanguage = parseArgs(argv).flags.get(\"lang\") === \"zh-CN\" ? \"zh-CN\" : \"en\";\n try {\n process.exitCode = await run(argv, process.cwd(), { onLanguage: (selected) => { language = selected; } });\n } catch (e) {\n const m = messages(language);\n if (e instanceof MigrationAbortedError) {\n console.log(m.cancelled);\n process.exitCode = 0;\n return;\n }\n console.error(`${m.error}: ${formatError(e, language, parseArgs(argv).flags.has(\"detail\"))}`);\n process.exitCode = 1;\n }\n}\n\n// Keep the executable separate from library exports; no config/import cycle.\nvoid main();\n"],"mappings":";;;AAMA,eAAe,OAAsB;CACnC,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;CACjC,IAAI,WAAwB,UAAU,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,MAAM,UAAU,UAAU;CACtF,IAAI;EACF,QAAQ,WAAW,MAAM,IAAI,MAAM,QAAQ,IAAI,GAAG,EAAE,aAAa,aAAa;GAAE,WAAW;EAAU,EAAE,CAAC;CAC1G,SAAS,GAAG;EACV,MAAM,IAAI,SAAS,QAAQ;EAC3B,IAAI,aAAa,uBAAuB;GACtC,QAAQ,IAAI,EAAE,SAAS;GACvB,QAAQ,WAAW;GACnB;EACF;EACA,QAAQ,MAAM,GAAG,EAAE,MAAM,IAAI,YAAY,GAAG,UAAU,UAAU,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,GAAG;EAC5F,QAAQ,WAAW;CACrB;AACF;AAGK,KAAK"}
1
+ {"version":3,"file":"bin.mjs","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { type CliLanguage, messages } from './cli/messages.js';\nimport { parseArgs, run } from './cli.js';\nimport { formatError } from './diagnostics/error.js';\nimport { MigrationAbortedError } from './migrator.js';\n\nasync function main(): Promise<void> {\n const argv = process.argv.slice(2);\n let language: CliLanguage = parseArgs(argv).flags.get('lang') === 'zh-CN' ? 'zh-CN' : 'en';\n try {\n process.exitCode = await run(argv, process.cwd(), {\n onLanguage: (selected) => {\n language = selected;\n },\n });\n } catch (e) {\n const m = messages(language);\n if (e instanceof MigrationAbortedError) {\n console.log(m.cancelled);\n process.exitCode = 0;\n return;\n }\n console.error(`${m.error}: ${formatError(e, language, parseArgs(argv).flags.has('detail'))}`);\n process.exitCode = 1;\n }\n}\n\n// 可执行入口与库导出分离,避免 config 与 import 形成循环。\nvoid main();\n"],"mappings":";;;AAMA,eAAe,OAAsB;CACnC,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;CACjC,IAAI,WAAwB,UAAU,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,MAAM,UAAU,UAAU;CACtF,IAAI;EACF,QAAQ,WAAW,MAAM,IAAI,MAAM,QAAQ,IAAI,GAAG,EAChD,aAAa,aAAa;GACxB,WAAW;EACb,EACF,CAAC;CACH,SAAS,GAAG;EACV,MAAM,IAAI,SAAS,QAAQ;EAC3B,IAAI,aAAa,uBAAuB;GACtC,QAAQ,IAAI,EAAE,SAAS;GACvB,QAAQ,WAAW;GACnB;EACF;EACA,QAAQ,MAAM,GAAG,EAAE,MAAM,IAAI,YAAY,GAAG,UAAU,UAAU,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,GAAG;EAC5F,QAAQ,WAAW;CACrB;AACF;AAGK,KAAK"}