ts-grm-migrate 0.1.0-alpha.7 → 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 +6 -2
- package/README.md +26 -3
- package/THIRD_PARTY_NOTICES.md +6 -0
- package/dist/bin.mjs +1 -1
- package/dist/{cli-BfbPTbqG.mjs → cli-DbmCX5wz.mjs} +415 -216
- package/dist/cli-DbmCX5wz.mjs.map +1 -0
- package/dist/index.d.mts +28 -8
- package/dist/index.mjs +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 +6 -2
- package/docs/zh-CN/README.md +25 -2
- 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 +4 -2
- package/dist/cli-BfbPTbqG.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
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.
|
|
6
10
|
|
|
7
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.
|
|
8
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,7 +17,7 @@ English | [简体中文](docs/zh-CN/CHANGELOG.md)
|
|
|
13
17
|
|
|
14
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.
|
|
15
19
|
- 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.
|
|
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.
|
|
17
21
|
|
|
18
22
|
## 0.1.0-alpha.5 (2026-10-11)
|
|
19
23
|
|
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
|
|
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);
|