ts-grm-migrate 0.1.0-alpha.6 → 0.1.0-alpha.8
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 +32 -5
- package/CONTRIBUTING.md +3 -2
- package/README.md +27 -4
- package/THIRD_PARTY_NOTICES.md +6 -0
- package/dist/bin.mjs +1 -1
- package/dist/bin.mjs.map +1 -1
- package/dist/{cli-BlCk2tT8.mjs → cli-DbmCX5wz.mjs} +3720 -3432
- package/dist/cli-DbmCX5wz.mjs.map +1 -0
- package/dist/index.d.mts +619 -590
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/docs/design.md +10 -2
- package/docs/migrations.md +40 -2
- package/docs/releasing.md +2 -2
- package/docs/zh-CN/CHANGELOG.md +32 -5
- package/docs/zh-CN/CONTRIBUTING.md +3 -2
- package/docs/zh-CN/README.md +26 -3
- package/docs/zh-CN/THIRD_PARTY_NOTICES.md +6 -0
- package/docs/zh-CN/design.md +10 -2
- package/docs/zh-CN/migrations.md +40 -2
- package/docs/zh-CN/releasing.md +2 -2
- package/package.json +5 -3
- package/dist/cli-BlCk2tT8.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,28 +2,55 @@
|
|
|
2
2
|
|
|
3
3
|
English | [简体中文](docs/zh-CN/CHANGELOG.md)
|
|
4
4
|
|
|
5
|
-
## 0.1.0-alpha.
|
|
5
|
+
## 0.1.0-alpha.8 (pending publication)
|
|
6
|
+
|
|
7
|
+
- Add exact, glob and RegExp physical-table exclusions across all five introspectors and migration/drift workflows, while allowing excluded tables to remain in query models, with conservative cross-boundary foreign-key guards.
|
|
8
|
+
- Add `tgm baseline [-n name]` and `Migrator.baseline()` to verify supported existing tables, generate replayable initial SQL, and record it without modifying business data.
|
|
9
|
+
- Document partial adoption, recovery, scope changes and SQL replay limits in English and Chinese; add SQLite end-to-end and catalog regression tests.
|
|
10
|
+
|
|
11
|
+
- 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.
|
|
12
|
+
- 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.
|
|
13
|
+
- Document that programmatic `dev()` and `push()` apply destructive changes without asking unless a `confirm` hook is supplied.
|
|
14
|
+
- Enforce Biome's recommended lint rules and formatting in `check`; code comments are now written in Chinese.
|
|
15
|
+
|
|
16
|
+
## 0.1.0-alpha.6 (2026-10-20)
|
|
6
17
|
|
|
7
18
|
- 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.
|
|
8
19
|
- Keep seeding independent of migration runtime, schema changes and history; add bilingual examples and subprocess/SQLite integration tests.
|
|
20
|
+
- **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.8.
|
|
9
21
|
|
|
10
|
-
## 0.1.0-alpha.
|
|
22
|
+
## 0.1.0-alpha.5 (2026-10-11)
|
|
23
|
+
|
|
24
|
+
- 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.
|
|
25
|
+
- Round-trip supported CHECK expressions through catalog formatting and compare other expressions conservatively.
|
|
26
|
+
- 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.
|
|
27
|
+
- 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.
|
|
28
|
+
- Document running the CLI in workspaces with non-hoisted dependencies (`npx --workspaces=false tgm`).
|
|
29
|
+
|
|
30
|
+
## 0.1.0-alpha.4 (2026-10-09)
|
|
11
31
|
|
|
12
32
|
- Localize configuration, history, locking, DDL, transaction and drift explanations throughout the CLI; preserve technical identifiers and expose original external diagnostics with `--detail`.
|
|
13
33
|
- Explain model naming errors in the selected language and restrict ESM troubleshooting hints to module-format failures.
|
|
14
34
|
|
|
15
|
-
## 0.1.0-alpha.
|
|
35
|
+
## 0.1.0-alpha.3 (2026-10-09)
|
|
16
36
|
|
|
17
37
|
- 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.
|
|
18
38
|
- Compare defaults by dialect and column type without numeric precision loss; abort on patch metadata errors; report all unproven CHECK differences.
|
|
19
|
-
- Repair isolated companion compatibility tests and add bilingual migration review, custom SQL, transaction recovery, and scope documentation.
|
|
20
39
|
- 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.
|
|
40
|
+
- Repair isolated companion compatibility tests and add bilingual migration review, custom SQL, transaction recovery, and scope documentation.
|
|
41
|
+
|
|
42
|
+
## 0.1.0-alpha.2
|
|
43
|
+
|
|
44
|
+
Removed from the npm registry; not available for installation.
|
|
45
|
+
|
|
46
|
+
## 0.1.0-alpha.1 (2026-09-26)
|
|
47
|
+
|
|
21
48
|
- Make CLI output concise and English by default, with `--detail` diagnostics, `--lang zh-CN` Chinese messages, and a configuration setting for the default language.
|
|
22
49
|
- Reduce default test output while retaining failure reasons and post-migration drift warnings.
|
|
23
50
|
- Remove the automatic GitHub Actions workflow; maintainers now run pre-release verification and publishing manually.
|
|
24
51
|
- Make English the primary documentation language and provide corresponding Simplified Chinese documents.
|
|
25
52
|
|
|
26
|
-
## 0.1.0-alpha.0
|
|
53
|
+
## 0.1.0-alpha.0 (2026-09-24)
|
|
27
54
|
|
|
28
55
|
- Add basic PostgreSQL and SQLite migrations and MySQL, SQL Server, and Oracle dialects.
|
|
29
56
|
- 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
|
|
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
|
@@ -4,11 +4,12 @@ English | [简体中文](docs/zh-CN/README.md)
|
|
|
4
4
|
|
|
5
5
|
Database schema migrations for [ts-grm](https://github.com/babyfish-ct/ts-grm). Manage database versions with SQL migration files while keeping your ts-grm models as the source of truth. No separate schema file or code generation is required.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Start from an empty database, or adopt supported existing tables with `tgm baseline`. Use `excludeTables` with exact names, globs or RegExp to leave selected physical tables unmanaged. Models must be supplied by the application; reverse model generation is not supported. A shadow database is deliberately omitted; see [migration workflows and design tradeoffs](docs/migrations.md).
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
- **Incremental migrations:** compare models with the database, generate readable SQL files, and record applied history.
|
|
12
|
+
- **Partial database adoption:** baseline supported existing tables and exclude exact names, globs or RegExp while retaining their query models.
|
|
12
13
|
- **SQL review:** `dev --create-only` generates a pending file for review and editing before deployment.
|
|
13
14
|
- **Strict checks:** `check` reports model/database drift with a nonzero exit code.
|
|
14
15
|
- **Ordered deployment:** apply pending migration files in order, including in deployment pipelines.
|
|
@@ -61,7 +62,7 @@ export default defineConfig({
|
|
|
61
62
|
});
|
|
62
63
|
```
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
For a new, empty database, run:
|
|
65
66
|
|
|
66
67
|
```sh
|
|
67
68
|
npx tgm dev --create-only -n init # Generate SQL for review
|
|
@@ -72,11 +73,32 @@ npx tgm dev # Omit the name to use only a timestamp
|
|
|
72
73
|
npx tgm status # Inspect applied and pending migrations
|
|
73
74
|
```
|
|
74
75
|
|
|
76
|
+
### Adopt an existing database
|
|
77
|
+
|
|
78
|
+
Keep all application query models and exclude tables whose structure is maintained elsewhere:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
export default defineConfig({
|
|
82
|
+
dialect: "postgres",
|
|
83
|
+
database: { connectionString: process.env.DATABASE_URL },
|
|
84
|
+
models: ["./src/models"],
|
|
85
|
+
excludeTables: ["sys_*", /^archive_\d{6}$/, "external_users"],
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
npx tgm check # Align managed tables with their models first
|
|
91
|
+
npx tgm baseline -n initial # Generate initial SQL and record it as already applied
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`baseline` requires empty migration files/history and matching managed structures. It does not modify business tables or data. Excluded models remain available to the application, but tgm does not create their tables, synchronize their structure or report their drift. Exclusions do not prevent existing migration SQL from executing. Cross-boundary foreign keys remain restricted; see [adoption, matching rules and recovery](docs/migrations.md#adopt-existing-databases-and-exclude-tables).
|
|
95
|
+
|
|
75
96
|
### Configuration
|
|
76
97
|
|
|
77
98
|
- **`dialect`:** `postgres`, `sqlite`, `mysql`, `mssql`, or `oracle`; defaults to `postgres`. It selects the driver, schema introspection, SQL generation, and execution. See the support table below.
|
|
78
99
|
- **`database` (required):** connection settings; fields depend on the dialect.
|
|
79
100
|
- **`models` (required):** model files or directories relative to the project root, starting with `./` or `../`. They must be ESM: declare `"type": "module"` or point to compiled ESM `.js` files.
|
|
101
|
+
- `excludeTables`: optional `(string | RegExp)[]` matched against physical table names; strings use glob, RegExp uses JavaScript semantics without `g`/`y` flags. Excluded tables can remain in query models.
|
|
80
102
|
- `language`: project default for CLI output, `en` or `zh-CN`; defaults to `en`. `--lang` overrides it for one command.
|
|
81
103
|
- `migrationsDir`: migration file directory; defaults to `./src/ts-grm`.
|
|
82
104
|
- `schema`: target schema; defaults to `public` on PostgreSQL, `dbo` on SQL Server, and the login user's schema on Oracle.
|
|
@@ -263,6 +285,7 @@ You can also run `tests/server-integration.test.ts` against dedicated instances
|
|
|
263
285
|
| --- | --- |
|
|
264
286
|
| `tgm dev [-n <name>]` | Compare models with the database, then generate and apply a migration (the name is optional) |
|
|
265
287
|
| `tgm dev --create-only [-n <name>]` | Generate a pending SQL file for review without applying it |
|
|
288
|
+
| `tgm baseline [-n <name>]` | Verify existing managed tables, generate initial SQL and record it as applied without executing business DDL |
|
|
266
289
|
| `tgm check` | Read-only model/database comparison; exit 1 for drift or an error |
|
|
267
290
|
| `tgm deploy` | Apply pending migrations in order without interaction |
|
|
268
291
|
| `tgm push [--force]` | Sync the database to the models without a file or history record |
|
|
@@ -270,7 +293,7 @@ You can also run `tests/server-integration.test.ts` against dedicated instances
|
|
|
270
293
|
| `tgm resolve --applied <id>` | Mark SQL already executed manually as applied |
|
|
271
294
|
| `tgm resolve --rolled-back <id>` | Mark an attempt as rolled back so it becomes pending again |
|
|
272
295
|
|
|
273
|
-
Options: `--dry-run` previews SQL without applying it (`push` only); `--create-only` generates without applying (`dev` only); `--config <path>` selects a configuration file; `-n` / `--name <name>` names a migration; `--force` skips destructive-change confirmation; `--detail` shows execution steps, SQL, and locks; `--lang <en|zh-CN>` selects the language for this command; `-h` shows help.
|
|
296
|
+
Options: `--dry-run` previews SQL without applying it (`push` only); `--create-only` generates without applying (`dev` only); `--config <path>` selects a configuration file; `-n` / `--name <name>` names a migration (`dev` / `baseline`); `--force` skips destructive-change confirmation; `--detail` shows execution steps, SQL, and locks; `--lang <en|zh-CN>` selects the language for this command; `-h` shows help.
|
|
274
297
|
|
|
275
298
|
Normal commands report the target, migration count or ID, and result. `status` intentionally lists migrations because it is an inspection command. For example, `tgm deploy` may print `Applied 2 migrations to postgres/app/public.` The SQL shown with `--detail` may contain business data: take care when saving or sharing logs. Diagnostic events do not print connection passwords.
|
|
276
299
|
|
|
@@ -301,7 +324,7 @@ export const SYS_USER = model("SysUser", "id", class {
|
|
|
301
324
|
- **History validation:** `dev` and `deploy` reject changed or missing applied files. `dev` refuses to generate while pending files exist; apply them with `deploy` first.
|
|
302
325
|
- **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.
|
|
303
326
|
- **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.
|
|
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.
|
|
327
|
+
- **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 })`.
|
|
305
328
|
- **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:
|
|
306
329
|
|
|
307
330
|
```text
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -19,3 +19,9 @@ The published package keeps `@ts-grm/core` and `@ts-grm/sql` as external peer de
|
|
|
19
19
|
Atomic renewable local leases use the external MIT-licensed `proper-lockfile` package. Its dependencies retain their own licenses in their distributed packages.
|
|
20
20
|
|
|
21
21
|
- @see https://github.com/moxystudio/node-proper-lockfile
|
|
22
|
+
|
|
23
|
+
## picomatch
|
|
24
|
+
|
|
25
|
+
Table-name glob patterns are compiled using the external MIT-licensed `picomatch` package.
|
|
26
|
+
|
|
27
|
+
- @see https://github.com/micromatch/picomatch
|
package/dist/bin.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { L as messages, S as MigrationAbortedError, n as run, q as formatError, t as parseArgs } from "./cli-DbmCX5wz.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 {
|
|
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"}
|