ts-grm-migrate 0.1.0-alpha.0 → 0.1.0-alpha.1
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 +19 -0
- package/CONTRIBUTING.md +38 -0
- package/README.md +107 -145
- package/SECURITY.md +9 -0
- package/THIRD_PARTY_NOTICES.md +6 -8
- package/dist/bin.mjs +9 -4
- package/dist/bin.mjs.map +1 -1
- package/dist/{cli-C-KYDbI_.mjs → cli-hSh1xp10.mjs} +399 -199
- package/dist/cli-hSh1xp10.mjs.map +1 -0
- package/dist/index.d.mts +30 -2
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/docs/compatibility.md +9 -7
- package/docs/design.md +19 -17
- package/docs/releasing.md +11 -8
- package/docs/zh-CN/CHANGELOG.md +19 -0
- package/docs/zh-CN/CONTRIBUTING.md +45 -0
- package/docs/zh-CN/README.md +237 -0
- package/docs/zh-CN/SECURITY.md +13 -0
- package/docs/zh-CN/THIRD_PARTY_NOTICES.md +19 -0
- package/docs/zh-CN/compatibility.md +24 -0
- package/docs/zh-CN/design.md +43 -0
- package/docs/zh-CN/releasing.md +14 -0
- package/package.json +4 -1
- package/dist/cli-C-KYDbI_.mjs.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
English | [简体中文](docs/zh-CN/CHANGELOG.md)
|
|
4
|
+
|
|
5
|
+
## 0.1.0-alpha.1 (pending publication)
|
|
6
|
+
|
|
7
|
+
- Make CLI output concise and English by default, with `--detail` diagnostics, `--lang zh-CN` Chinese messages, and a configuration setting for the default language.
|
|
8
|
+
- Reduce default test output while retaining failure reasons and post-migration drift warnings.
|
|
9
|
+
- Remove the automatic GitHub Actions workflow; maintainers now run pre-release verification and publishing manually.
|
|
10
|
+
- Make English the primary documentation language and provide corresponding Simplified Chinese documents.
|
|
11
|
+
|
|
12
|
+
## 0.1.0-alpha.0
|
|
13
|
+
|
|
14
|
+
- Add basic PostgreSQL and SQLite migrations and MySQL, SQL Server, and Oracle dialects.
|
|
15
|
+
- Add durable unfinished-migration state, transactional success recording, exclusive migration-file creation, and stable database locks.
|
|
16
|
+
- Add historical ts-grm compatibility checks, isolated package tests, and container database test scripts.
|
|
17
|
+
- Align the development toolchain with ts-grm, use MIT for original code, and retain third-party adaptation notices.
|
|
18
|
+
|
|
19
|
+
No stable version has been released. See the [README](README.md) for database support boundaries. Future releases will record breaking changes and recovery steps here.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
English | [简体中文](docs/zh-CN/CONTRIBUTING.md)
|
|
4
|
+
|
|
5
|
+
This project is in alpha. When filing an issue, include a minimal model and the database, driver, Node, `@ts-grm/core`, and `@ts-grm/sql` versions. Remove credentials and application data.
|
|
6
|
+
|
|
7
|
+
## Development and verification
|
|
8
|
+
|
|
9
|
+
The development toolchain follows ts-grm: Yarn 4.1.0, TypeScript 7, tsdown, Biome, and Vitest 4. Node `>=24.11.0` is required by the published upstream `using` syntax and the current tsdown runtime. Verify releases on Node 24.11 and the current Node 24 release. The upstream repository's Node >=18 declaration does not satisfy this project's build tools and SQLite driver.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
corepack enable
|
|
13
|
+
corepack yarn install --immutable
|
|
14
|
+
corepack yarn check
|
|
15
|
+
corepack yarn test:package 0.0.9
|
|
16
|
+
corepack yarn test:package 0.0.13
|
|
17
|
+
corepack yarn test:compat 0.0.9 0.0.13
|
|
18
|
+
corepack yarn test:postgres-mysql
|
|
19
|
+
corepack yarn test:servers
|
|
20
|
+
```
|
|
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.
|
|
23
|
+
|
|
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
|
+
|
|
26
|
+
## Changes
|
|
27
|
+
|
|
28
|
+
- A new dialect must cover model adaptation, introspection, DDL, execution, history, locking, and documentation.
|
|
29
|
+
- Verify the schema → SQL → introspection → diff cycle, including data preservation, failure recovery, and concurrency.
|
|
30
|
+
- Reject unsupported database structures explicitly instead of silently dropping them.
|
|
31
|
+
- Keep access to ts-grm internals in `src/vendor/ts-grm.ts`; verify candidate versions before changing the peer range.
|
|
32
|
+
- Keep the published package ESM and ts-grm external to the bundle so the host model registry is shared.
|
|
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.
|
|
35
|
+
|
|
36
|
+
Original contributions use MIT. See [third-party notices](THIRD_PARTY_NOTICES.md) for adapted code.
|
|
37
|
+
|
|
38
|
+
`yarn test:coverage` uses V8 to generate source coverage and LCOV, excluding test fixtures. Coverage from local tests alone does not represent coverage of every dialect; there is currently no global threshold based on a single coverage figure.
|
package/README.md
CHANGED
|
@@ -1,50 +1,40 @@
|
|
|
1
1
|
# ts-grm-migrate
|
|
2
2
|
|
|
3
|
-
[
|
|
4
|
-
但**模型就是你写的 ts-grm 代码**,不需要额外的 schema 文件,也没有代码生成步骤。
|
|
3
|
+
English | [简体中文](docs/zh-CN/README.md)
|
|
5
4
|
|
|
6
|
-
|
|
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.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
- **按序部署**:把所有未应用的迁移依次应用到目标库(部署 / CI 场景)
|
|
10
|
-
- **快速同步**:快速执行迁移SQL,将数据库同步为model定义的形状
|
|
11
|
-
- **迁移后对账**:应用完再核对数据库与模型,不一致就指出「哪个库、哪张表、差在哪」
|
|
12
|
-
- **失败可恢复**:迁移中途失败会记入历史并阻止后续部署,用 `resolve` 修正状态后继续
|
|
7
|
+
## Features
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
- **Incremental migrations:** compare models with the database, generate readable SQL files, and record applied history.
|
|
10
|
+
- **Ordered deployment:** apply pending migration files in order, including in deployment pipelines.
|
|
11
|
+
- **Direct synchronization:** bring a database in line with the models without writing migration history.
|
|
12
|
+
- **Post-migration checks:** report schema differences that remain after applying changes.
|
|
13
|
+
- **Failure recovery:** record failed or interrupted attempts and require an explicit `resolve` before retrying.
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
运行环境与当前 ts-grm 工具链一致:Node `>=24.11.0`、ESM。
|
|
18
|
-
开发使用 Yarn 4.1.0、TypeScript 7、tsdown、Biome 与 Vitest 4。
|
|
15
|
+
## Status and installation
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
**Alpha, published on [npm](https://www.npmjs.com/package/ts-grm-migrate).** The first release was `0.1.0-alpha.0`. Support is limited to the verified combinations and features below; arbitrary existing schemas and historical versions are not guaranteed to work.
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
corepack yarn install --immutable
|
|
24
|
-
corepack yarn check
|
|
25
|
-
corepack yarn pack --out /tmp/ts-grm-migrate.tgz
|
|
26
|
-
```
|
|
19
|
+
Runtime requirements are Node `>=24.11.0` and ESM. Development uses Yarn 4.1.0, TypeScript 7, tsdown, Biome, and Vitest 4.
|
|
27
20
|
|
|
28
|
-
|
|
21
|
+
Install the migration CLI in your application. These commands match the PostgreSQL example below:
|
|
29
22
|
|
|
30
23
|
```sh
|
|
31
|
-
npm install @ts-grm/core@0.0.13 @ts-grm/sql@0.0.13
|
|
32
|
-
npm install -D
|
|
24
|
+
npm install @ts-grm/core@0.0.13 @ts-grm/sql@0.0.13 pg
|
|
25
|
+
npm install -D ts-grm-migrate@next
|
|
33
26
|
```
|
|
34
27
|
|
|
35
|
-
- core/sql
|
|
36
|
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
- npm 发布步骤见 [发布](docs/releasing.md)。
|
|
28
|
+
- `@ts-grm/core` and `@ts-grm/sql` are peer dependencies and must use the **same version**. The verified range is `>=0.0.9 <0.0.14`; see [compatibility](docs/compatibility.md) before changing it.
|
|
29
|
+
- Install only the database driver you need; the supported drivers are listed below.
|
|
30
|
+
- `@next` follows prereleases. Pin an exact version when reproducibility matters, for example `ts-grm-migrate@0.1.0-alpha.0`.
|
|
31
|
+
- Run the installed CLI with `npx tgm`, or use `tgm` / `ts-grm-migrate` through your package manager.
|
|
40
32
|
|
|
41
|
-
##
|
|
33
|
+
## Quick start
|
|
42
34
|
|
|
43
|
-
>
|
|
44
|
-
> ts-grm 的模型注册表是**模块级单例**,migrate 必须与你的模型共用同一份 **ESM** 实例;
|
|
45
|
-
> 若模型是 CommonJS,它会把模型注册到另一份实例上,migrate 看不到任何模型。
|
|
35
|
+
> **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.
|
|
46
36
|
|
|
47
|
-
|
|
37
|
+
Create a configuration file in your project root:
|
|
48
38
|
|
|
49
39
|
```ts
|
|
50
40
|
// ts-grm-migrate.config.ts
|
|
@@ -53,50 +43,49 @@ import { defineConfig } from "ts-grm-migrate";
|
|
|
53
43
|
export default defineConfig({
|
|
54
44
|
dialect: "postgres",
|
|
55
45
|
database: { host: "localhost", database: "app", user: "postgres" },
|
|
56
|
-
models: ["./src/models"], //
|
|
46
|
+
models: ["./src/models"], // ts-grm loads these .ts files or compiled .js files
|
|
47
|
+
// language: "zh-CN", // Optional: use Chinese for this project's CLI output
|
|
57
48
|
});
|
|
58
49
|
```
|
|
59
50
|
|
|
60
|
-
|
|
51
|
+
Then run:
|
|
61
52
|
|
|
62
53
|
```sh
|
|
63
|
-
tgm dev -n init
|
|
64
|
-
tgm dev
|
|
65
|
-
tgm status
|
|
54
|
+
npx tgm dev -n init # Generate and apply the first migration
|
|
55
|
+
npx tgm dev # Omit the name to use only a timestamp
|
|
56
|
+
npx tgm status # Inspect applied and pending migrations
|
|
66
57
|
```
|
|
67
58
|
|
|
68
|
-
###
|
|
59
|
+
### Configuration
|
|
69
60
|
|
|
70
|
-
- **`dialect
|
|
71
|
-
|
|
72
|
-
- **`
|
|
73
|
-
-
|
|
74
|
-
|
|
75
|
-
- `
|
|
76
|
-
- `
|
|
77
|
-
- `lockPath`:进程锁文件,默认 `./.ts-grm-migrate.lock`
|
|
61
|
+
- **`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.
|
|
62
|
+
- **`database` (required):** connection settings; fields depend on the dialect.
|
|
63
|
+
- **`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.
|
|
64
|
+
- `language`: project default for CLI output, `en` or `zh-CN`; defaults to `en`. `--lang` overrides it for one command.
|
|
65
|
+
- `migrationsDir`: migration file directory; defaults to `./src/ts-grm`.
|
|
66
|
+
- `schema`: target schema; defaults to `public` on PostgreSQL, `dbo` on SQL Server, and the login user's schema on Oracle.
|
|
67
|
+
- `lockPath`: process lock file; defaults to `./.ts-grm-migrate.lock`.
|
|
78
68
|
|
|
79
|
-
|
|
80
|
-
`.ts` 的模块类型跟随项目:CommonJS 项目请用 `.mts`,或给 `package.json` 加 `"type": "module"`。
|
|
69
|
+
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"`.
|
|
81
70
|
|
|
82
|
-
##
|
|
71
|
+
## Databases and configuration
|
|
83
72
|
|
|
84
|
-
| `dialect` |
|
|
73
|
+
| `dialect` | Driver dependency | Supported scope |
|
|
85
74
|
| --- | --- | --- |
|
|
86
|
-
| `postgres
|
|
87
|
-
| `sqlite` | `better-sqlite3` |
|
|
88
|
-
| `mysql` | `mysql2` | MySQL 8.0.16
|
|
89
|
-
| `mssql` | `mssql` | SQL Server 2016
|
|
90
|
-
| `oracle` | `oracledb` | Oracle 19c
|
|
75
|
+
| `postgres` (default) | `pg` | PostgreSQL; default schema `public` |
|
|
76
|
+
| `sqlite` | `better-sqlite3` | Basic migrations; table rebuilds are not implemented |
|
|
77
|
+
| `mysql` | `mysql2` | MySQL 8.0.16+, InnoDB, `lower_case_table_names=0` |
|
|
78
|
+
| `mssql` | `mssql` | SQL Server 2016+; default schema `dbo`; tested on SQL Server 2022 |
|
|
79
|
+
| `oracle` | `oracledb` | Oracle 19c+; default schema is the login user; tested on Oracle Free 23 |
|
|
91
80
|
|
|
92
|
-
SQL Server
|
|
81
|
+
SQL Server example:
|
|
93
82
|
|
|
94
83
|
```ts
|
|
95
84
|
export default defineConfig({
|
|
96
85
|
dialect: "mssql",
|
|
97
86
|
database: {
|
|
98
87
|
host: "localhost", port: 1433, database: "app", user: "app", password: process.env.DB_PASSWORD,
|
|
99
|
-
//
|
|
88
|
+
// Use only for local tests with self-signed certificates; production validates certificates by default.
|
|
100
89
|
trustServerCertificate: true,
|
|
101
90
|
},
|
|
102
91
|
schema: "dbo",
|
|
@@ -104,7 +93,7 @@ export default defineConfig({
|
|
|
104
93
|
});
|
|
105
94
|
```
|
|
106
95
|
|
|
107
|
-
Oracle
|
|
96
|
+
Oracle example (Thin mode; no Oracle Client installation needed):
|
|
108
97
|
|
|
109
98
|
```ts
|
|
110
99
|
export default defineConfig({
|
|
@@ -117,121 +106,94 @@ export default defineConfig({
|
|
|
117
106
|
});
|
|
118
107
|
```
|
|
119
108
|
|
|
120
|
-
Oracle `database.database`
|
|
121
|
-
`connectionString`。Oracle schema 必须已存在;SQL Server 会创建尚不存在的目标 schema。
|
|
122
|
-
SQL Server 和 Oracle 的自动生成 DDL 与历史表均限定目标 schema,避免读写落在不同命名空间。
|
|
109
|
+
For Oracle, `database.database` is the service name. You can provide `host`, `port`, and `database` instead of `connectionString`. The Oracle schema must already exist; SQL Server creates a missing target schema. Generated DDL and migration history on both dialects are scoped to that schema.
|
|
123
110
|
|
|
124
|
-
Oracle
|
|
125
|
-
`CREATE SEQUENCE`。数据库锁使用 `DBMS_LOCK`,需由 DBA 授权:
|
|
111
|
+
The Oracle user needs `CREATE SESSION`, `CREATE TABLE`, and a tablespace quota. Identity columns also require `CREATE SEQUENCE`. A DBA must grant access to `DBMS_LOCK` for database locking:
|
|
126
112
|
|
|
127
113
|
```sql
|
|
128
114
|
GRANT EXECUTE ON SYS.DBMS_LOCK TO APP;
|
|
129
115
|
```
|
|
130
116
|
|
|
131
|
-
MySQL
|
|
132
|
-
|
|
133
|
-
PostgreSQL
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
- SQL Server 的计算/隐藏/稀疏列、temporal/memory-optimized 表、自定义聚集约束布局、
|
|
148
|
-
降序/INCLUDE/特殊索引会明确拒绝。
|
|
149
|
-
- Oracle 的虚拟/隐藏列、IOT/嵌套/临时表、特殊/表达式/降序索引、延迟约束会明确拒绝。
|
|
150
|
-
- 两者目前不支持跨 schema 外键及未启用/未验证的约束。CHECK 只做保守的格式归一化,
|
|
151
|
-
不承诺任意两种等价表达式都能匹配。
|
|
152
|
-
- Oracle 迁移文件支持以分号分隔的 SQL,正确保留字符串、标识符、注释中的分号;
|
|
153
|
-
PL/SQL、SQL*Plus 指令暂不支持,会在执行文件前拒绝。SQL Server 文件使用 SQL 批次,
|
|
154
|
-
不支持客户端的 `GO` 分隔符。
|
|
155
|
-
- MySQL 暂不支持 MariaDB、生成列、隐藏列及特殊索引。
|
|
156
|
-
|
|
157
|
-
### 容器集成测试
|
|
117
|
+
MySQL and Oracle DDL commits implicitly and may leave partial changes after failure. `resolve --rolled-back` changes **history only**; it does not undo SQL. Restore the database manually before retrying, or complete the SQL and use `resolve --applied`.
|
|
118
|
+
|
|
119
|
+
PostgreSQL, SQLite, and SQL Server execute migration SQL and record success in one transaction, so a failure to record success rolls back the SQL. Every dialect persists an unfinished attempt before execution. A crash, lost connection, or history-write failure blocks automatic replay until you inspect the database and use `resolve`. `status` shows unfinished attempts as failed. It treats only a confirmed missing history table as empty history; connection and permission errors propagate. Oracle's ORA-00942 cannot reliably distinguish a missing table from lack of access across schemas, so that error is preserved.
|
|
120
|
+
|
|
121
|
+
New migration IDs use millisecond timestamps and advance past existing IDs while holding the local lock. Files are created exclusively; an existing filename causes an error instead of overwriting historical SQL. PostgreSQL uses a fixed database lock resource scoped to the database and current schema, independent of the checkout path.
|
|
122
|
+
|
|
123
|
+
Current limits:
|
|
124
|
+
|
|
125
|
+
- SQL Server and Oracle support ordinary tables, columns, primary keys, unique constraints, foreign keys, CHECK constraints, and ordinary indexes. Identity strategy changes, automatic renames, and complex table rebuilds are unsupported.
|
|
126
|
+
- SQL Server explicitly rejects computed, hidden, and sparse columns; temporal and memory-optimized tables; custom clustered constraint layouts; and descending, INCLUDE, or special indexes.
|
|
127
|
+
- Oracle explicitly rejects virtual and hidden columns; index-organized, nested, and temporary tables; special, expression, and descending indexes; and deferred constraints.
|
|
128
|
+
- Both reject cross-schema foreign keys and disabled or unvalidated constraints. CHECK expressions receive conservative normalization; equivalent expressions are not guaranteed to compare as equal.
|
|
129
|
+
- Oracle migration files may contain semicolon-separated SQL, including semicolons inside strings, identifiers, and comments. PL/SQL and SQL*Plus directives are rejected before execution. SQL Server files use SQL batches; the client-side `GO` separator is unsupported.
|
|
130
|
+
- MySQL support does not include MariaDB, generated or hidden columns, or special indexes.
|
|
131
|
+
|
|
132
|
+
### Container integration tests
|
|
158
133
|
|
|
159
134
|
```sh
|
|
160
135
|
corepack yarn install
|
|
161
136
|
corepack yarn test:servers
|
|
162
137
|
```
|
|
163
138
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
可通过 `MSSQL_TEST_IMAGE` / `ORACLE_TEST_IMAGE` 指定镜像。首次拉取镜像需要网络及足够磁盘空间。
|
|
168
|
-
SQL Server Developer 的测试用途受其许可条款约束,脚本用 `ACCEPT_EULA=Y` 启动。
|
|
139
|
+
By default, the script starts SQL Server Developer and Oracle Free with Podman (`CONTAINER_RUNTIME=docker` selects Docker). It binds random ports to `127.0.0.1`, tests migrations, data preservation, locks, recovery, and the CLI in isolated schemas or users, then removes its containers and volumes. MySQL integration tests create and remove their own randomly named database rather than using `MYSQL_DATABASE`; the test account needs database-creation permission.
|
|
140
|
+
|
|
141
|
+
Set `MSSQL_TEST_IMAGE` or `ORACLE_TEST_IMAGE` to select images. The first run needs network access and enough disk space. SQL Server Developer testing is subject to its license terms; the script starts it with `ACCEPT_EULA=Y`.
|
|
169
142
|
|
|
170
|
-
|
|
171
|
-
`ORACLE_HOST/PORT/PASSWORD/DATABASE`,运行 `tests/server-integration.test.ts`。
|
|
172
|
-
Oracle 测试使用 SYSTEM 创建临时用户,需要该账户拥有 `DBMS_LOCK` 的转授权权限;
|
|
173
|
-
这些权限仅供测试环境使用。未设置对应 `*_HOST` 时,集成测试会跳过。
|
|
143
|
+
You can also run `tests/server-integration.test.ts` against dedicated instances by setting `MSSQL_HOST/PORT/USER/PASSWORD/DATABASE` or `ORACLE_HOST/PORT/PASSWORD/DATABASE`. Oracle tests use SYSTEM to create temporary users, so SYSTEM needs permission to grant `DBMS_LOCK` to them. Those privileges are for test environments only. Integration tests skip when the corresponding `*_HOST` is unset.
|
|
174
144
|
|
|
175
|
-
##
|
|
145
|
+
## Commands
|
|
176
146
|
|
|
177
|
-
|
|
|
147
|
+
| Command | Purpose |
|
|
178
148
|
| --- | --- |
|
|
179
|
-
| `tgm dev [-n
|
|
180
|
-
| `tgm deploy` |
|
|
181
|
-
| `tgm push [--force]` |
|
|
182
|
-
| `tgm status` |
|
|
183
|
-
| `tgm resolve --applied <id>` |
|
|
184
|
-
| `tgm resolve --rolled-back <id>` |
|
|
149
|
+
| `tgm dev [-n <name>]` | Compare models with the database, then generate and apply a migration (the name is optional) |
|
|
150
|
+
| `tgm deploy` | Apply pending migrations in order without interaction |
|
|
151
|
+
| `tgm push [--force]` | Sync the database to the models without a file or history record |
|
|
152
|
+
| `tgm status` | Show applied and pending migrations |
|
|
153
|
+
| `tgm resolve --applied <id>` | Mark SQL already executed manually as applied |
|
|
154
|
+
| `tgm resolve --rolled-back <id>` | Mark an attempt as rolled back so it becomes pending again |
|
|
185
155
|
|
|
186
|
-
|
|
156
|
+
Options: `--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.
|
|
187
157
|
|
|
188
|
-
|
|
158
|
+
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.
|
|
189
159
|
|
|
190
|
-
|
|
191
|
-
但**已应用的迁移不能再改** —— 内容一旦变动,后续 `deploy` 会因 checksum 不匹配而拒绝继续
|
|
192
|
-
- **破坏性变更会先问**:删表 / 删列 / 改列类型默认交互确认;非交互环境(CI)需显式加 `--force`
|
|
193
|
-
- **迁移后自动对账**:`dev` / `deploy` / `push` 完成后会再读一次数据库与模型比对,
|
|
194
|
-
仍有差异就报出具体位置,例如:
|
|
160
|
+
### Output language
|
|
195
161
|
|
|
196
|
-
|
|
197
|
-
⚠ 对账发现数据库与模型不一致(库 app,schema public):
|
|
198
|
-
- 表 AUTHOR:多出列 LEGACY
|
|
199
|
-
这通常意味着迁移未完整生效,或数据库被手工改动过。
|
|
200
|
-
```
|
|
162
|
+
The CLI defaults to English and does not switch based on the system's `LANG`. Set `language: "zh-CN"` in `defineConfig({...})` to make Chinese the project default. To use Chinese for a single command:
|
|
201
163
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
164
|
+
```sh
|
|
165
|
+
npx tgm --help --lang zh-CN
|
|
166
|
+
npx tgm deploy --lang zh-CN
|
|
167
|
+
npx tgm status --lang zh-CN --detail
|
|
168
|
+
```
|
|
206
169
|
|
|
207
|
-
|
|
170
|
+
The precedence is **`--lang` > configuration `language` > `en`**. For example, `tgm deploy --lang en` uses English once in a project configured for Chinese. `--help` and unknown commands do not load the project configuration, so add `--lang zh-CN` explicitly for Chinese help or errors in those paths. `--detail` works with either language. Low-level diagnostics and database-driver errors remain in English or their original language.
|
|
208
171
|
|
|
209
|
-
|
|
210
|
-
模块级单例,若 migrate 自带一份 `@ts-grm/core`,它看到的是空注册表,拿不到你定义的任何模型。
|
|
172
|
+
## Behavior
|
|
211
173
|
|
|
212
|
-
|
|
174
|
+
- **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.
|
|
175
|
+
- **Destructive changes require confirmation:** dropping tables or columns and changing column types prompts by default. Non-interactive environments require `--force`.
|
|
176
|
+
- **Post-migration checks:** `dev`, `deploy`, and `push` reread the schema and report remaining differences, for example:
|
|
213
177
|
|
|
214
|
-
|
|
178
|
+
```text
|
|
179
|
+
Warning: postgres/app/public differs from the model:
|
|
180
|
+
- Table AUTHOR: Extra column LEGACY
|
|
181
|
+
Check for a partial migration or manual database changes.
|
|
182
|
+
```
|
|
215
183
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
corepack yarn test:compat 0.0.9 0.0.13
|
|
219
|
-
corepack yarn test:package 0.0.9
|
|
220
|
-
corepack yarn test:postgres-mysql
|
|
221
|
-
corepack yarn test:servers
|
|
222
|
-
```
|
|
184
|
+
- **Concurrency protection:** a process lock prevents parallel migrations in one project; a database lock protects deployments across machines.
|
|
185
|
+
- **Target schema applies to reads and writes:** PostgreSQL uses `search_path`, while SQL Server and Oracle qualify target tables. This prevents introspection and DDL from targeting different schemas.
|
|
223
186
|
|
|
224
|
-
|
|
225
|
-
相关测试会跳过,因此不能仅凭 `yarn test` 绿色判断全部数据库通过。
|
|
187
|
+
## License
|
|
226
188
|
|
|
227
|
-
- [
|
|
228
|
-
- [安全报告](SECURITY.md)
|
|
229
|
-
- [变更记录](CHANGELOG.md)
|
|
230
|
-
- [设计](docs/design.md):代码分层、差分规则与失败恢复
|
|
231
|
-
- [兼容性](docs/compatibility.md):ts-grm 版本范围及复现命令
|
|
232
|
-
- [发布](docs/releasing.md):npm 发布前检查
|
|
189
|
+
Original code uses [MIT](LICENSE). ts-grm uses Apache-2.0; adapted upstream structure types retain their license and attribution. See [third-party notices](THIRD_PARTY_NOTICES.md).
|
|
233
190
|
|
|
234
|
-
##
|
|
191
|
+
## More documentation
|
|
235
192
|
|
|
236
|
-
|
|
237
|
-
|
|
193
|
+
- [Compatibility and supported ts-grm versions](docs/compatibility.md)
|
|
194
|
+
- [Design and migration internals](docs/design.md)
|
|
195
|
+
- [Contributing](CONTRIBUTING.md)
|
|
196
|
+
- [Security and support](SECURITY.md)
|
|
197
|
+
- [Release process](docs/releasing.md)
|
|
198
|
+
- [Changelog](CHANGELOG.md)
|
|
199
|
+
- [Third-party notices](THIRD_PARTY_NOTICES.md)
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Security and support
|
|
2
|
+
|
|
3
|
+
English | [简体中文](docs/zh-CN/SECURITY.md)
|
|
4
|
+
|
|
5
|
+
This project is in alpha. Only the current development branch is maintained, and no production support lifecycle is promised. Database migrations change schema and data; review generated SQL and verify it in a recoverable environment before release.
|
|
6
|
+
|
|
7
|
+
To report a vulnerability, use the repository's private GitHub Security reporting option once it is enabled. Do not post credentials, application data, or directly exploitable details in a public issue. Until a private channel is available, file only a non-sensitive request to contact the maintainers so they can establish one.
|
|
8
|
+
|
|
9
|
+
Maintainers should enable Private vulnerability reporting on GitHub and configure branch protection according to their collaboration model. Repository files cannot replace GitHub account settings. No response time is currently promised.
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
# Third-party notices
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English | [简体中文](docs/zh-CN/THIRD_PARTY_NOTICES.md)
|
|
4
|
+
|
|
5
|
+
Original code in this project is under the [MIT license](LICENSE). Dependencies and adapted portions retain their respective licenses.
|
|
4
6
|
|
|
5
7
|
## ts-grm
|
|
6
8
|
|
|
7
|
-
`src/vendor/ts-grm.ts`
|
|
8
|
-
`schema_def.ts`:保留迁移器需要的字段,调整类型名称和引用,并添加本项目的适配接口及实现。
|
|
9
|
-
上游文件署名为陈涛 (Chen Tao),上游包标记为 Apache-2.0。改写部分保留其许可与署名;
|
|
10
|
-
本项目其余原创代码使用 MIT。
|
|
9
|
+
The `TableDef`, `ColumnDef`, and constraint type declarations in `src/vendor/ts-grm.ts` were adapted from ts-grm's `schema_def.ts`. They retain the fields needed by the migrator, change type names and references, and add this project's adapter interfaces and implementation. The upstream file credits Chen Tao, and the upstream package is licensed under Apache-2.0. The adapted portion retains that license and attribution; the project's other original code uses MIT.
|
|
11
10
|
|
|
12
11
|
- @see https://github.com/babyfish-ct/ts-grm/blob/fe78eb6c323bf335ff23650a414856eb36bfbce7/packages/sql/src/impl/schema_def.ts
|
|
13
12
|
- @see https://github.com/babyfish-ct/ts-grm/blob/fe78eb6c323bf335ff23650a414856eb36bfbce7/packages/sql/package.json
|
|
14
|
-
- [Apache-2.0
|
|
13
|
+
- [Full Apache-2.0 license](LICENSES/Apache-2.0.txt)
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
其他数据库驱动也为外部依赖,其许可证由各自包提供。
|
|
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.
|
package/dist/bin.mjs
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { n as run,
|
|
2
|
+
import { n as run, r as messages, t as parseArgs, y as MigrationAbortedError } from "./cli-hSh1xp10.mjs";
|
|
3
3
|
//#region src/bin.ts
|
|
4
4
|
async function main() {
|
|
5
|
+
const argv = process.argv.slice(2);
|
|
6
|
+
let language = parseArgs(argv).flags.get("lang") === "zh-CN" ? "zh-CN" : "en";
|
|
5
7
|
try {
|
|
6
|
-
process.exitCode = await run(
|
|
8
|
+
process.exitCode = await run(argv, process.cwd(), { onLanguage: (selected) => {
|
|
9
|
+
language = selected;
|
|
10
|
+
} });
|
|
7
11
|
} catch (e) {
|
|
12
|
+
const m = messages(language);
|
|
8
13
|
if (e instanceof MigrationAbortedError) {
|
|
9
|
-
console.log(
|
|
14
|
+
console.log(m.cancelled);
|
|
10
15
|
process.exitCode = 0;
|
|
11
16
|
return;
|
|
12
17
|
}
|
|
13
|
-
console.error(
|
|
18
|
+
console.error(`${m.error}: ${e.message}`);
|
|
14
19
|
process.exitCode = 1;
|
|
15
20
|
}
|
|
16
21
|
}
|
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 { run } from \"./cli.js\";\nimport { MigrationAbortedError } from \"./migrator.js\";\n\nasync function main(): Promise<void> {\n try {\n process.exitCode = await run(
|
|
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\";\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}: ${(e as Error).message}`);\n process.exitCode = 1;\n }\n}\n\n// Keep the executable separate from library exports; no config/import cycle.\nvoid main();\n"],"mappings":";;;AAKA,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,IAAK,EAAY,SAAS;EACnD,QAAQ,WAAW;CACrB;AACF;AAGK,KAAK"}
|