ts-grm-migrate 0.1.0-alpha.4 → 0.1.0-alpha.6
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 +5 -0
- package/README.md +59 -2
- package/THIRD_PARTY_NOTICES.md +6 -0
- package/dist/bin.mjs +1 -1
- package/dist/{cli-vcn3DTDJ.mjs → cli-BlCk2tT8.mjs} +703 -374
- package/dist/cli-BlCk2tT8.mjs.map +1 -0
- package/dist/index.d.mts +88 -10
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/docs/design.md +1 -1
- package/docs/migrations.md +6 -2
- package/docs/zh-CN/CHANGELOG.md +5 -0
- package/docs/zh-CN/README.md +59 -2
- package/docs/zh-CN/THIRD_PARTY_NOTICES.md +6 -0
- package/docs/zh-CN/design.md +1 -1
- package/docs/zh-CN/migrations.md +6 -2
- package/package.json +6 -2
- package/dist/cli-vcn3DTDJ.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
English | [简体中文](docs/zh-CN/CHANGELOG.md)
|
|
4
4
|
|
|
5
|
+
## 0.1.0-alpha.6 (pending publication)
|
|
6
|
+
|
|
7
|
+
- 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
|
+
- Keep seeding independent of migration runtime, schema changes and history; add bilingual examples and subprocess/SQLite integration tests.
|
|
9
|
+
|
|
5
10
|
## 0.1.0-alpha.4 (pending publication)
|
|
6
11
|
|
|
7
12
|
- Localize configuration, history, locking, DDL, transaction and drift explanations throughout the CLI; preserve technical identifiers and expose original external diagnostics with `--detail`.
|
package/README.md
CHANGED
|
@@ -35,6 +35,14 @@ npm install -D ts-grm-migrate@next
|
|
|
35
35
|
- `@next` follows prereleases. Pin an exact version when reproducibility matters, for example `ts-grm-migrate@0.1.0-alpha.0`.
|
|
36
36
|
- Run the installed CLI with `npx tgm`, or use `tgm` / `ts-grm-migrate` through your package manager.
|
|
37
37
|
|
|
38
|
+
In a workspace with non-hoisted dependencies (for example a Bun installation), npm's workspace lookup may miss the child's local CLI or select a different version installed at the root. From the child project, use:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx --workspaces=false tgm dev --create-only -n init
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
This keeps npm's lookup in the current project. If npm reports `No versions available for tgm`, it has failed to locate the local executable and is looking for a package named `tgm`; the package to install is `ts-grm-migrate`. Check that `node_modules/.bin/tgm` resolves to an existing `dist/bin.mjs`, and reinstall dependencies with the project's package manager if the link is broken. The CLI cannot repair npm's command resolution because it has not started yet. [npm exec workspace behavior](https://docs.npmjs.com/cli/npm-exec/).
|
|
45
|
+
|
|
38
46
|
## Quick start
|
|
39
47
|
|
|
40
48
|
> **Your project must use ESM.** Set `"type": "module"` in `package.json`. The ts-grm model registry is a module-level singleton; the migration tool and your models must share the same ESM instance. CommonJS models may register with a separate instance and be invisible to the migration tool.
|
|
@@ -73,9 +81,58 @@ npx tgm status # Inspect applied and pending migrations
|
|
|
73
81
|
- `migrationsDir`: migration file directory; defaults to `./src/ts-grm`.
|
|
74
82
|
- `schema`: target schema; defaults to `public` on PostgreSQL, `dbo` on SQL Server, and the login user's schema on Oracle.
|
|
75
83
|
- `lockPath`: process lock file; defaults to `./.ts-grm-migrate.lock`.
|
|
84
|
+
- `seed`: optional `{ command: string, args?: string[] }` executable for `tgm seed`; see below.
|
|
76
85
|
|
|
77
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"`.
|
|
78
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
|
+
|
|
79
136
|
## Defaults and auto-increment (optional)
|
|
80
137
|
|
|
81
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:
|
|
@@ -213,7 +270,7 @@ You can also run `tests/server-integration.test.ts` against dedicated instances
|
|
|
213
270
|
| `tgm resolve --applied <id>` | Mark SQL already executed manually as applied |
|
|
214
271
|
| `tgm resolve --rolled-back <id>` | Mark an attempt as rolled back so it becomes pending again |
|
|
215
272
|
|
|
216
|
-
Options: `--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.
|
|
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.
|
|
217
274
|
|
|
218
275
|
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.
|
|
219
276
|
|
|
@@ -245,7 +302,7 @@ export const SYS_USER = model("SysUser", "id", class {
|
|
|
245
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.
|
|
246
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.
|
|
247
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.
|
|
248
|
-
- **Post-migration checks:** `dev
|
|
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:
|
|
249
306
|
|
|
250
307
|
```text
|
|
251
308
|
Warning: postgres/app/public differs from the model:
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -13,3 +13,9 @@ The `TableDef`, `ColumnDef`, and constraint type declarations in `src/vendor/ts-
|
|
|
13
13
|
- [Full Apache-2.0 license](LICENSES/Apache-2.0.txt)
|
|
14
14
|
|
|
15
15
|
The published package keeps `@ts-grm/core` and `@ts-grm/sql` as external peer dependencies; it does not bundle upstream implementations. Database drivers are external dependencies with their own licenses.
|
|
16
|
+
|
|
17
|
+
## proper-lockfile
|
|
18
|
+
|
|
19
|
+
Atomic renewable local leases use the external MIT-licensed `proper-lockfile` package. Its dependencies retain their own licenses in their distributed packages.
|
|
20
|
+
|
|
21
|
+
- @see https://github.com/moxystudio/node-proper-lockfile
|
package/dist/bin.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { b as MigrationAbortedError, n as run, q as formatError, r as messages, t as parseArgs } from "./cli-BlCk2tT8.mjs";
|
|
3
3
|
//#region src/bin.ts
|
|
4
4
|
async function main() {
|
|
5
5
|
const argv = process.argv.slice(2);
|