@pristine-ts/mysql-cli 2.0.16
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/LICENSE +201 -0
- package/dist/lib/cjs/commands/commands.js +25 -0
- package/dist/lib/cjs/commands/commands.js.map +1 -0
- package/dist/lib/cjs/commands/mysql-migrate-create.command-options.js +37 -0
- package/dist/lib/cjs/commands/mysql-migrate-create.command-options.js.map +1 -0
- package/dist/lib/cjs/commands/mysql-migrate-create.command.js +120 -0
- package/dist/lib/cjs/commands/mysql-migrate-create.command.js.map +1 -0
- package/dist/lib/cjs/commands/mysql-migrate-status.command-options.js +27 -0
- package/dist/lib/cjs/commands/mysql-migrate-status.command-options.js.map +1 -0
- package/dist/lib/cjs/commands/mysql-migrate-status.command.js +104 -0
- package/dist/lib/cjs/commands/mysql-migrate-status.command.js.map +1 -0
- package/dist/lib/cjs/commands/mysql-migrate-verify.command-options.js +27 -0
- package/dist/lib/cjs/commands/mysql-migrate-verify.command-options.js.map +1 -0
- package/dist/lib/cjs/commands/mysql-migrate-verify.command.js +74 -0
- package/dist/lib/cjs/commands/mysql-migrate-verify.command.js.map +1 -0
- package/dist/lib/cjs/commands/mysql-migrate.command-options.js +41 -0
- package/dist/lib/cjs/commands/mysql-migrate.command-options.js.map +1 -0
- package/dist/lib/cjs/commands/mysql-migrate.command.js +86 -0
- package/dist/lib/cjs/commands/mysql-migrate.command.js.map +1 -0
- package/dist/lib/cjs/enums/enums.js +18 -0
- package/dist/lib/cjs/enums/enums.js.map +1 -0
- package/dist/lib/cjs/enums/migration-state.enum.js +28 -0
- package/dist/lib/cjs/enums/migration-state.enum.js.map +1 -0
- package/dist/lib/cjs/errors/errors.js +22 -0
- package/dist/lib/cjs/errors/errors.js.map +1 -0
- package/dist/lib/cjs/errors/migration-checksum-mismatch.error.js +24 -0
- package/dist/lib/cjs/errors/migration-checksum-mismatch.error.js.map +1 -0
- package/dist/lib/cjs/errors/migration-duplicate-name.error.js +21 -0
- package/dist/lib/cjs/errors/migration-duplicate-name.error.js.map +1 -0
- package/dist/lib/cjs/errors/migration-execution.error.js +21 -0
- package/dist/lib/cjs/errors/migration-execution.error.js.map +1 -0
- package/dist/lib/cjs/errors/migration-invalid-name.error.js +20 -0
- package/dist/lib/cjs/errors/migration-invalid-name.error.js.map +1 -0
- package/dist/lib/cjs/errors/migration-orphaned-record.error.js +22 -0
- package/dist/lib/cjs/errors/migration-orphaned-record.error.js.map +1 -0
- package/dist/lib/cjs/interfaces/interfaces.js +18 -0
- package/dist/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/dist/lib/cjs/interfaces/mysql-migration.interface.js +3 -0
- package/dist/lib/cjs/interfaces/mysql-migration.interface.js.map +1 -0
- package/dist/lib/cjs/managers/managers.js +22 -0
- package/dist/lib/cjs/managers/managers.js.map +1 -0
- package/dist/lib/cjs/managers/mysql-migration-checksum.manager.js +35 -0
- package/dist/lib/cjs/managers/mysql-migration-checksum.manager.js.map +1 -0
- package/dist/lib/cjs/managers/mysql-migration-record.manager.js +96 -0
- package/dist/lib/cjs/managers/mysql-migration-record.manager.js.map +1 -0
- package/dist/lib/cjs/managers/mysql-migration-runner.manager.js +96 -0
- package/dist/lib/cjs/managers/mysql-migration-runner.manager.js.map +1 -0
- package/dist/lib/cjs/managers/mysql-migration-scaffold.manager.js +217 -0
- package/dist/lib/cjs/managers/mysql-migration-scaffold.manager.js.map +1 -0
- package/dist/lib/cjs/managers/mysql-migration.manager.js +261 -0
- package/dist/lib/cjs/managers/mysql-migration.manager.js.map +1 -0
- package/dist/lib/cjs/models/migration-apply-entry.model.js +11 -0
- package/dist/lib/cjs/models/migration-apply-entry.model.js.map +1 -0
- package/dist/lib/cjs/models/migration-apply-result.model.js +18 -0
- package/dist/lib/cjs/models/migration-apply-result.model.js.map +1 -0
- package/dist/lib/cjs/models/migration-plan-entry.model.js +11 -0
- package/dist/lib/cjs/models/migration-plan-entry.model.js.map +1 -0
- package/dist/lib/cjs/models/migration-plan.model.js +24 -0
- package/dist/lib/cjs/models/migration-plan.model.js.map +1 -0
- package/dist/lib/cjs/models/migration-record.model.js +12 -0
- package/dist/lib/cjs/models/migration-record.model.js.map +1 -0
- package/dist/lib/cjs/models/models.js +22 -0
- package/dist/lib/cjs/models/models.js.map +1 -0
- package/dist/lib/cjs/mysql-cli.configuration-keys.js +20 -0
- package/dist/lib/cjs/mysql-cli.configuration-keys.js.map +1 -0
- package/dist/lib/cjs/mysql-cli.module.js +63 -0
- package/dist/lib/cjs/mysql-cli.module.js.map +1 -0
- package/dist/lib/cjs/mysql-cli.module.keyname.js +5 -0
- package/dist/lib/cjs/mysql-cli.module.keyname.js.map +1 -0
- package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/lib/esm/commands/commands.js +9 -0
- package/dist/lib/esm/commands/commands.js.map +1 -0
- package/dist/lib/esm/commands/mysql-migrate-create.command-options.js +33 -0
- package/dist/lib/esm/commands/mysql-migrate-create.command-options.js.map +1 -0
- package/dist/lib/esm/commands/mysql-migrate-create.command.js +114 -0
- package/dist/lib/esm/commands/mysql-migrate-create.command.js.map +1 -0
- package/dist/lib/esm/commands/mysql-migrate-status.command-options.js +23 -0
- package/dist/lib/esm/commands/mysql-migrate-status.command-options.js.map +1 -0
- package/dist/lib/esm/commands/mysql-migrate-status.command.js +101 -0
- package/dist/lib/esm/commands/mysql-migrate-status.command.js.map +1 -0
- package/dist/lib/esm/commands/mysql-migrate-verify.command-options.js +23 -0
- package/dist/lib/esm/commands/mysql-migrate-verify.command-options.js.map +1 -0
- package/dist/lib/esm/commands/mysql-migrate-verify.command.js +71 -0
- package/dist/lib/esm/commands/mysql-migrate-verify.command.js.map +1 -0
- package/dist/lib/esm/commands/mysql-migrate.command-options.js +37 -0
- package/dist/lib/esm/commands/mysql-migrate.command-options.js.map +1 -0
- package/dist/lib/esm/commands/mysql-migrate.command.js +83 -0
- package/dist/lib/esm/commands/mysql-migrate.command.js.map +1 -0
- package/dist/lib/esm/enums/enums.js +2 -0
- package/dist/lib/esm/enums/enums.js.map +1 -0
- package/dist/lib/esm/enums/migration-state.enum.js +25 -0
- package/dist/lib/esm/enums/migration-state.enum.js.map +1 -0
- package/dist/lib/esm/errors/errors.js +6 -0
- package/dist/lib/esm/errors/errors.js.map +1 -0
- package/dist/lib/esm/errors/migration-checksum-mismatch.error.js +20 -0
- package/dist/lib/esm/errors/migration-checksum-mismatch.error.js.map +1 -0
- package/dist/lib/esm/errors/migration-duplicate-name.error.js +17 -0
- package/dist/lib/esm/errors/migration-duplicate-name.error.js.map +1 -0
- package/dist/lib/esm/errors/migration-execution.error.js +17 -0
- package/dist/lib/esm/errors/migration-execution.error.js.map +1 -0
- package/dist/lib/esm/errors/migration-invalid-name.error.js +16 -0
- package/dist/lib/esm/errors/migration-invalid-name.error.js.map +1 -0
- package/dist/lib/esm/errors/migration-orphaned-record.error.js +18 -0
- package/dist/lib/esm/errors/migration-orphaned-record.error.js.map +1 -0
- package/dist/lib/esm/interfaces/interfaces.js +2 -0
- package/dist/lib/esm/interfaces/interfaces.js.map +1 -0
- package/dist/lib/esm/interfaces/mysql-migration.interface.js +2 -0
- package/dist/lib/esm/interfaces/mysql-migration.interface.js.map +1 -0
- package/dist/lib/esm/managers/managers.js +6 -0
- package/dist/lib/esm/managers/managers.js.map +1 -0
- package/dist/lib/esm/managers/mysql-migration-checksum.manager.js +32 -0
- package/dist/lib/esm/managers/mysql-migration-checksum.manager.js.map +1 -0
- package/dist/lib/esm/managers/mysql-migration-record.manager.js +93 -0
- package/dist/lib/esm/managers/mysql-migration-record.manager.js.map +1 -0
- package/dist/lib/esm/managers/mysql-migration-runner.manager.js +93 -0
- package/dist/lib/esm/managers/mysql-migration-runner.manager.js.map +1 -0
- package/dist/lib/esm/managers/mysql-migration-scaffold.manager.js +211 -0
- package/dist/lib/esm/managers/mysql-migration-scaffold.manager.js.map +1 -0
- package/dist/lib/esm/managers/mysql-migration.manager.js +258 -0
- package/dist/lib/esm/managers/mysql-migration.manager.js.map +1 -0
- package/dist/lib/esm/models/migration-apply-entry.model.js +7 -0
- package/dist/lib/esm/models/migration-apply-entry.model.js.map +1 -0
- package/dist/lib/esm/models/migration-apply-result.model.js +14 -0
- package/dist/lib/esm/models/migration-apply-result.model.js.map +1 -0
- package/dist/lib/esm/models/migration-plan-entry.model.js +7 -0
- package/dist/lib/esm/models/migration-plan-entry.model.js.map +1 -0
- package/dist/lib/esm/models/migration-plan.model.js +20 -0
- package/dist/lib/esm/models/migration-plan.model.js.map +1 -0
- package/dist/lib/esm/models/migration-record.model.js +8 -0
- package/dist/lib/esm/models/migration-record.model.js.map +1 -0
- package/dist/lib/esm/models/models.js +6 -0
- package/dist/lib/esm/models/models.js.map +1 -0
- package/dist/lib/esm/mysql-cli.configuration-keys.js +17 -0
- package/dist/lib/esm/mysql-cli.configuration-keys.js.map +1 -0
- package/dist/lib/esm/mysql-cli.module.js +46 -0
- package/dist/lib/esm/mysql-cli.module.js.map +1 -0
- package/dist/lib/esm/mysql-cli.module.keyname.js +2 -0
- package/dist/lib/esm/mysql-cli.module.keyname.js.map +1 -0
- package/dist/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/dist/types/commands/commands.d.ts +8 -0
- package/dist/types/commands/mysql-migrate-create.command-options.d.ts +12 -0
- package/dist/types/commands/mysql-migrate-create.command.d.ts +32 -0
- package/dist/types/commands/mysql-migrate-status.command-options.d.ts +8 -0
- package/dist/types/commands/mysql-migrate-status.command.d.ts +25 -0
- package/dist/types/commands/mysql-migrate-verify.command-options.d.ts +8 -0
- package/dist/types/commands/mysql-migrate-verify.command.d.ts +23 -0
- package/dist/types/commands/mysql-migrate.command-options.d.ts +14 -0
- package/dist/types/commands/mysql-migrate.command.d.ts +23 -0
- package/dist/types/enums/enums.d.ts +1 -0
- package/dist/types/enums/migration-state.enum.d.ts +23 -0
- package/dist/types/errors/errors.d.ts +5 -0
- package/dist/types/errors/migration-checksum-mismatch.error.d.ts +14 -0
- package/dist/types/errors/migration-duplicate-name.error.d.ts +11 -0
- package/dist/types/errors/migration-execution.error.d.ts +12 -0
- package/dist/types/errors/migration-invalid-name.error.d.ts +10 -0
- package/dist/types/errors/migration-orphaned-record.error.d.ts +12 -0
- package/dist/types/interfaces/interfaces.d.ts +1 -0
- package/dist/types/interfaces/mysql-migration.interface.d.ts +40 -0
- package/dist/types/managers/managers.d.ts +5 -0
- package/dist/types/managers/mysql-migration-checksum.manager.d.ts +15 -0
- package/dist/types/managers/mysql-migration-record.manager.d.ts +22 -0
- package/dist/types/managers/mysql-migration-runner.manager.d.ts +16 -0
- package/dist/types/managers/mysql-migration-scaffold.manager.d.ts +40 -0
- package/dist/types/managers/mysql-migration.manager.d.ts +41 -0
- package/dist/types/models/migration-apply-entry.model.d.ts +9 -0
- package/dist/types/models/migration-apply-result.model.d.ts +14 -0
- package/dist/types/models/migration-plan-entry.model.d.ts +15 -0
- package/dist/types/models/migration-plan.model.d.ts +14 -0
- package/dist/types/models/migration-record.model.d.ts +12 -0
- package/dist/types/models/models.d.ts +5 -0
- package/dist/types/mysql-cli.configuration-keys.d.ts +29 -0
- package/dist/types/mysql-cli.module.d.ts +10 -0
- package/dist/types/mysql-cli.module.keyname.d.ts +1 -0
- package/package.json +75 -0
- package/readme.md +195 -0
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pristine-ts/mysql-cli",
|
|
3
|
+
"version": "2.0.16",
|
|
4
|
+
"description": "Pristine CLI commands and TypeScript-defined SQL migrations for @pristine-ts/mysql.",
|
|
5
|
+
"module": "dist/lib/esm/mysql-cli.module.js",
|
|
6
|
+
"main": "dist/lib/cjs/mysql-cli.module.js",
|
|
7
|
+
"types": "dist/types/mysql-cli.module.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
|
|
10
|
+
"prepublish": "npm run build",
|
|
11
|
+
"test": "jest",
|
|
12
|
+
"test:cov": "jest --coverage"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@pristine-ts/class-validator": "^2.0.4",
|
|
24
|
+
"@pristine-ts/cli": "^2.0.16",
|
|
25
|
+
"@pristine-ts/common": "^2.0.16",
|
|
26
|
+
"@pristine-ts/configuration": "^2.0.16",
|
|
27
|
+
"@pristine-ts/core": "^2.0.16",
|
|
28
|
+
"@pristine-ts/file": "^2.0.16",
|
|
29
|
+
"@pristine-ts/logging": "^2.0.16",
|
|
30
|
+
"@pristine-ts/mysql": "^2.0.16",
|
|
31
|
+
"@pristine-ts/telemetry": "^2.0.16",
|
|
32
|
+
"mysql2": "^3.10.0",
|
|
33
|
+
"tsyringe": "^4.8.0"
|
|
34
|
+
},
|
|
35
|
+
"jest": {
|
|
36
|
+
"transform": {
|
|
37
|
+
".(ts|tsx)": "ts-jest"
|
|
38
|
+
},
|
|
39
|
+
"globals": {
|
|
40
|
+
"ts-jest": {
|
|
41
|
+
"tsconfig": {
|
|
42
|
+
"strictNullChecks": false
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"testEnvironment": "node",
|
|
47
|
+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
|
|
48
|
+
"moduleFileExtensions": [
|
|
49
|
+
"ts",
|
|
50
|
+
"tsx",
|
|
51
|
+
"js"
|
|
52
|
+
],
|
|
53
|
+
"coveragePathIgnorePatterns": [
|
|
54
|
+
"/node_modules/",
|
|
55
|
+
"/test/"
|
|
56
|
+
],
|
|
57
|
+
"coverageThreshold": {
|
|
58
|
+
"global": {
|
|
59
|
+
"branches": 90,
|
|
60
|
+
"functions": 95,
|
|
61
|
+
"lines": 95,
|
|
62
|
+
"statements": 95
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"collectCoverageFrom": [
|
|
66
|
+
"src/*.{js,ts}"
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
"repository": {
|
|
70
|
+
"type": "git",
|
|
71
|
+
"url": "https://github.com/magieno/pristine-ts.git",
|
|
72
|
+
"directory": "packages/mysql-cli"
|
|
73
|
+
},
|
|
74
|
+
"gitHead": "a55d7d59862672a8cbbca4088fed090779b37705"
|
|
75
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# @pristine-ts/mysql-cli
|
|
2
|
+
|
|
3
|
+
CLI commands and a TypeScript-defined migration system for `@pristine-ts/mysql`.
|
|
4
|
+
|
|
5
|
+
- Migrations are TypeScript classes implementing `MysqlMigrationInterface` — they
|
|
6
|
+
bundle with your deployment artifact, so the same code runs locally and in
|
|
7
|
+
production.
|
|
8
|
+
- Forward-only by design. There is no `down()`. Roll forward by writing a new
|
|
9
|
+
migration.
|
|
10
|
+
- Drift detection: every applied migration is checksummed; status/verify catch
|
|
11
|
+
edits made after apply.
|
|
12
|
+
|
|
13
|
+
## Install + import
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// app.module.ts
|
|
17
|
+
import {AppModuleInterface} from "@pristine-ts/common";
|
|
18
|
+
import {MysqlCliModule} from "@pristine-ts/mysql-cli";
|
|
19
|
+
import {SqlMigrationsModule} from "./sql-migrations/sql-migrations.module";
|
|
20
|
+
|
|
21
|
+
export const AppModule: AppModuleInterface = {
|
|
22
|
+
keyname: "my-app",
|
|
23
|
+
importModules: [
|
|
24
|
+
MysqlCliModule,
|
|
25
|
+
SqlMigrationsModule,
|
|
26
|
+
],
|
|
27
|
+
importServices: [],
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Writing a migration
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
// src/sql-migrations/01-init.sql-migrations.ts
|
|
35
|
+
import {injectable} from "tsyringe";
|
|
36
|
+
import {tag} from "@pristine-ts/common";
|
|
37
|
+
import {MysqlMigrationInterface} from "@pristine-ts/mysql-cli";
|
|
38
|
+
|
|
39
|
+
@tag("MysqlMigrationInterface")
|
|
40
|
+
@injectable()
|
|
41
|
+
export class Init_01 implements MysqlMigrationInterface {
|
|
42
|
+
readonly name = "01-init";
|
|
43
|
+
|
|
44
|
+
up(): string {
|
|
45
|
+
return `
|
|
46
|
+
CREATE TABLE users (
|
|
47
|
+
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
48
|
+
name VARCHAR(255) NOT NULL,
|
|
49
|
+
PRIMARY KEY (id)
|
|
50
|
+
);
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Each migration must be importable from your AppModule's service graph. The
|
|
57
|
+
canonical pattern is a small "migrations module":
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// src/sql-migrations/sql-migrations.module.ts
|
|
61
|
+
import {ModuleInterface} from "@pristine-ts/common";
|
|
62
|
+
// <pristine:migration-imports:start>
|
|
63
|
+
import {Init_01} from "./01-init.sql-migrations";
|
|
64
|
+
// <pristine:migration-imports:end>
|
|
65
|
+
|
|
66
|
+
export const SqlMigrationsModule: ModuleInterface = {
|
|
67
|
+
keyname: "my-app.sql-migrations",
|
|
68
|
+
importServices: [
|
|
69
|
+
// <pristine:migration-services:start>
|
|
70
|
+
Init_01,
|
|
71
|
+
// <pristine:migration-services:end>
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The marker comments are optional but enable `mysql:create` to auto-edit this file
|
|
77
|
+
when scaffolding new migrations (see `pristine.mysql-cli.scaffold.barrelPath`
|
|
78
|
+
below).
|
|
79
|
+
|
|
80
|
+
## Multi-database support
|
|
81
|
+
|
|
82
|
+
A migration applies to a specific database via the optional
|
|
83
|
+
`configUniqueKeynames` field:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
export class AnalyticsBackfill_05 implements MysqlMigrationInterface {
|
|
87
|
+
readonly name = "05-analytics-backfill";
|
|
88
|
+
readonly configUniqueKeynames = ["analytics_db"]; // only runs against this config
|
|
89
|
+
up(): string { return `...`; }
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Leave the field undefined to apply against every targeted config.
|
|
94
|
+
|
|
95
|
+
## Commands
|
|
96
|
+
|
|
97
|
+
| Command | Purpose |
|
|
98
|
+
| --- | --- |
|
|
99
|
+
| `pristine mysql:migrate [--config <k>] [--dry-run] [--force]` | Apply pending migrations. Refuses to proceed on drift unless `--force`. Halts on first failure. |
|
|
100
|
+
| `pristine mysql:status [--config <k>]` | Print Pending / Applied / Modified / Orphaned for every migration. Always exits 0. |
|
|
101
|
+
| `pristine mysql:verify [--config <k>]` | Same scan as `status`, exits non-zero on drift. Use as a CI gate. |
|
|
102
|
+
| `pristine mysql:create --name <name> [--config <k>]` | Scaffold a new `<NN>-<slug>.sql-migrations.ts` file with the next sequential number. Prompts for the name when `--name` is omitted on an interactive terminal. |
|
|
103
|
+
|
|
104
|
+
`--config` defaults to `__default__`.
|
|
105
|
+
|
|
106
|
+
## State semantics
|
|
107
|
+
|
|
108
|
+
| State | Meaning |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| `Pending` | Registered in DI, not in DB. Will run next `migrate`. |
|
|
111
|
+
| `Applied` | Registered, in DB, checksums match. Nothing to do. |
|
|
112
|
+
| `Modified` | Registered, in DB, checksums differ. Someone edited `up()` after apply. |
|
|
113
|
+
| `Orphaned` | In DB, not registered. Class was deleted, or wrong config targeted. |
|
|
114
|
+
|
|
115
|
+
`apply` refuses to run when any `Modified` or `Orphaned` entries exist. Use
|
|
116
|
+
`--force` to override (the modified migration is NOT re-run; the orphaned record
|
|
117
|
+
is NOT removed — `--force` simply lets pending migrations continue).
|
|
118
|
+
|
|
119
|
+
## Configuration
|
|
120
|
+
|
|
121
|
+
Set in `pristine.config.ts`:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
export default defineConfig({
|
|
125
|
+
cli: { appModule: { ... }, build: { ... } },
|
|
126
|
+
config: {
|
|
127
|
+
"pristine.mysql-cli.scaffold.path": "src/sql-migrations",
|
|
128
|
+
"pristine.mysql-cli.scaffold.barrelPath": "src/sql-migrations/sql-migrations.module.ts",
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
| Key | Default | Meaning |
|
|
134
|
+
| --- | --- | --- |
|
|
135
|
+
| `pristine.mysql-cli.scaffold.path` | `src/sql-migrations` | Where `mysql:create` writes new files. |
|
|
136
|
+
| `pristine.mysql-cli.scaffold.barrelPath` | (unset) | When set, `mysql:create` auto-edits this file between marker comments. When unset, the command prints manual instructions instead. |
|
|
137
|
+
|
|
138
|
+
The bookkeeping table name comes from `MysqlConfig.migrationsTableName` (default
|
|
139
|
+
`pristine_migrations`).
|
|
140
|
+
|
|
141
|
+
## Bookkeeping table schema
|
|
142
|
+
|
|
143
|
+
`mysql:migrate` creates this table on demand:
|
|
144
|
+
|
|
145
|
+
```sql
|
|
146
|
+
CREATE TABLE IF NOT EXISTS pristine_migrations (
|
|
147
|
+
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
148
|
+
filename VARCHAR(255) NOT NULL,
|
|
149
|
+
checksum CHAR(64) NOT NULL,
|
|
150
|
+
applied_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
|
151
|
+
execution_time_ms INT UNSIGNED NULL,
|
|
152
|
+
PRIMARY KEY (id),
|
|
153
|
+
UNIQUE KEY uniq_filename (filename)
|
|
154
|
+
);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
`filename` stores `MysqlMigrationInterface.name` (e.g. `"01-init"`).
|
|
158
|
+
`checksum` is the SHA-256 of the SQL returned by `up()`, canonicalized (trailing
|
|
159
|
+
whitespace + CRLF normalized so trivial editor noise doesn't trigger drift).
|
|
160
|
+
|
|
161
|
+
## Running migrations in production
|
|
162
|
+
|
|
163
|
+
The same `MysqlMigrationManager.apply()` powers the CLI command — wire it up as a
|
|
164
|
+
one-off entry point in your deployment:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
const kernel = new Kernel();
|
|
168
|
+
await kernel.start(AppModule);
|
|
169
|
+
const manager = kernel.container.resolve(MysqlMigrationManager);
|
|
170
|
+
const result = await manager.apply("__default__");
|
|
171
|
+
if (result.failedMigration !== undefined) {
|
|
172
|
+
// alert + non-zero exit
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Because migrations are TypeScript classes imported into the AppModule's service
|
|
177
|
+
graph, your bundler ships every `up()` body inside the deployment artifact — no
|
|
178
|
+
`.sql` files need to travel with it.
|
|
179
|
+
|
|
180
|
+
## Multiple statements per migration
|
|
181
|
+
|
|
182
|
+
The runner opens a dedicated mysql2 connection with `multipleStatements: true`
|
|
183
|
+
for each migration, so you can return a `;`-separated SQL string from `up()`
|
|
184
|
+
without doing the splitting yourself. The cached `MysqlClient` pool is not
|
|
185
|
+
affected — flipping `multipleStatements` on the shared pool would leak to every
|
|
186
|
+
other consumer, so the runner uses a one-shot connection it always closes.
|
|
187
|
+
|
|
188
|
+
## Numbering convention
|
|
189
|
+
|
|
190
|
+
Files are named `<NN>-<slug>.sql-migrations.ts`. The scaffold uses two-digit
|
|
191
|
+
padding by default; if you cross 99, rename the existing files to three-digit
|
|
192
|
+
padding once and the scaffold respects the new width going forward.
|
|
193
|
+
|
|
194
|
+
Two devs branching from `main` may both pick the same next number — git will
|
|
195
|
+
flag the filename collision at merge. Rename the loser on rebase.
|