@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.
Files changed (175) hide show
  1. package/LICENSE +201 -0
  2. package/dist/lib/cjs/commands/commands.js +25 -0
  3. package/dist/lib/cjs/commands/commands.js.map +1 -0
  4. package/dist/lib/cjs/commands/mysql-migrate-create.command-options.js +37 -0
  5. package/dist/lib/cjs/commands/mysql-migrate-create.command-options.js.map +1 -0
  6. package/dist/lib/cjs/commands/mysql-migrate-create.command.js +120 -0
  7. package/dist/lib/cjs/commands/mysql-migrate-create.command.js.map +1 -0
  8. package/dist/lib/cjs/commands/mysql-migrate-status.command-options.js +27 -0
  9. package/dist/lib/cjs/commands/mysql-migrate-status.command-options.js.map +1 -0
  10. package/dist/lib/cjs/commands/mysql-migrate-status.command.js +104 -0
  11. package/dist/lib/cjs/commands/mysql-migrate-status.command.js.map +1 -0
  12. package/dist/lib/cjs/commands/mysql-migrate-verify.command-options.js +27 -0
  13. package/dist/lib/cjs/commands/mysql-migrate-verify.command-options.js.map +1 -0
  14. package/dist/lib/cjs/commands/mysql-migrate-verify.command.js +74 -0
  15. package/dist/lib/cjs/commands/mysql-migrate-verify.command.js.map +1 -0
  16. package/dist/lib/cjs/commands/mysql-migrate.command-options.js +41 -0
  17. package/dist/lib/cjs/commands/mysql-migrate.command-options.js.map +1 -0
  18. package/dist/lib/cjs/commands/mysql-migrate.command.js +86 -0
  19. package/dist/lib/cjs/commands/mysql-migrate.command.js.map +1 -0
  20. package/dist/lib/cjs/enums/enums.js +18 -0
  21. package/dist/lib/cjs/enums/enums.js.map +1 -0
  22. package/dist/lib/cjs/enums/migration-state.enum.js +28 -0
  23. package/dist/lib/cjs/enums/migration-state.enum.js.map +1 -0
  24. package/dist/lib/cjs/errors/errors.js +22 -0
  25. package/dist/lib/cjs/errors/errors.js.map +1 -0
  26. package/dist/lib/cjs/errors/migration-checksum-mismatch.error.js +24 -0
  27. package/dist/lib/cjs/errors/migration-checksum-mismatch.error.js.map +1 -0
  28. package/dist/lib/cjs/errors/migration-duplicate-name.error.js +21 -0
  29. package/dist/lib/cjs/errors/migration-duplicate-name.error.js.map +1 -0
  30. package/dist/lib/cjs/errors/migration-execution.error.js +21 -0
  31. package/dist/lib/cjs/errors/migration-execution.error.js.map +1 -0
  32. package/dist/lib/cjs/errors/migration-invalid-name.error.js +20 -0
  33. package/dist/lib/cjs/errors/migration-invalid-name.error.js.map +1 -0
  34. package/dist/lib/cjs/errors/migration-orphaned-record.error.js +22 -0
  35. package/dist/lib/cjs/errors/migration-orphaned-record.error.js.map +1 -0
  36. package/dist/lib/cjs/interfaces/interfaces.js +18 -0
  37. package/dist/lib/cjs/interfaces/interfaces.js.map +1 -0
  38. package/dist/lib/cjs/interfaces/mysql-migration.interface.js +3 -0
  39. package/dist/lib/cjs/interfaces/mysql-migration.interface.js.map +1 -0
  40. package/dist/lib/cjs/managers/managers.js +22 -0
  41. package/dist/lib/cjs/managers/managers.js.map +1 -0
  42. package/dist/lib/cjs/managers/mysql-migration-checksum.manager.js +35 -0
  43. package/dist/lib/cjs/managers/mysql-migration-checksum.manager.js.map +1 -0
  44. package/dist/lib/cjs/managers/mysql-migration-record.manager.js +96 -0
  45. package/dist/lib/cjs/managers/mysql-migration-record.manager.js.map +1 -0
  46. package/dist/lib/cjs/managers/mysql-migration-runner.manager.js +96 -0
  47. package/dist/lib/cjs/managers/mysql-migration-runner.manager.js.map +1 -0
  48. package/dist/lib/cjs/managers/mysql-migration-scaffold.manager.js +217 -0
  49. package/dist/lib/cjs/managers/mysql-migration-scaffold.manager.js.map +1 -0
  50. package/dist/lib/cjs/managers/mysql-migration.manager.js +261 -0
  51. package/dist/lib/cjs/managers/mysql-migration.manager.js.map +1 -0
  52. package/dist/lib/cjs/models/migration-apply-entry.model.js +11 -0
  53. package/dist/lib/cjs/models/migration-apply-entry.model.js.map +1 -0
  54. package/dist/lib/cjs/models/migration-apply-result.model.js +18 -0
  55. package/dist/lib/cjs/models/migration-apply-result.model.js.map +1 -0
  56. package/dist/lib/cjs/models/migration-plan-entry.model.js +11 -0
  57. package/dist/lib/cjs/models/migration-plan-entry.model.js.map +1 -0
  58. package/dist/lib/cjs/models/migration-plan.model.js +24 -0
  59. package/dist/lib/cjs/models/migration-plan.model.js.map +1 -0
  60. package/dist/lib/cjs/models/migration-record.model.js +12 -0
  61. package/dist/lib/cjs/models/migration-record.model.js.map +1 -0
  62. package/dist/lib/cjs/models/models.js +22 -0
  63. package/dist/lib/cjs/models/models.js.map +1 -0
  64. package/dist/lib/cjs/mysql-cli.configuration-keys.js +20 -0
  65. package/dist/lib/cjs/mysql-cli.configuration-keys.js.map +1 -0
  66. package/dist/lib/cjs/mysql-cli.module.js +63 -0
  67. package/dist/lib/cjs/mysql-cli.module.js.map +1 -0
  68. package/dist/lib/cjs/mysql-cli.module.keyname.js +5 -0
  69. package/dist/lib/cjs/mysql-cli.module.keyname.js.map +1 -0
  70. package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  71. package/dist/lib/esm/commands/commands.js +9 -0
  72. package/dist/lib/esm/commands/commands.js.map +1 -0
  73. package/dist/lib/esm/commands/mysql-migrate-create.command-options.js +33 -0
  74. package/dist/lib/esm/commands/mysql-migrate-create.command-options.js.map +1 -0
  75. package/dist/lib/esm/commands/mysql-migrate-create.command.js +114 -0
  76. package/dist/lib/esm/commands/mysql-migrate-create.command.js.map +1 -0
  77. package/dist/lib/esm/commands/mysql-migrate-status.command-options.js +23 -0
  78. package/dist/lib/esm/commands/mysql-migrate-status.command-options.js.map +1 -0
  79. package/dist/lib/esm/commands/mysql-migrate-status.command.js +101 -0
  80. package/dist/lib/esm/commands/mysql-migrate-status.command.js.map +1 -0
  81. package/dist/lib/esm/commands/mysql-migrate-verify.command-options.js +23 -0
  82. package/dist/lib/esm/commands/mysql-migrate-verify.command-options.js.map +1 -0
  83. package/dist/lib/esm/commands/mysql-migrate-verify.command.js +71 -0
  84. package/dist/lib/esm/commands/mysql-migrate-verify.command.js.map +1 -0
  85. package/dist/lib/esm/commands/mysql-migrate.command-options.js +37 -0
  86. package/dist/lib/esm/commands/mysql-migrate.command-options.js.map +1 -0
  87. package/dist/lib/esm/commands/mysql-migrate.command.js +83 -0
  88. package/dist/lib/esm/commands/mysql-migrate.command.js.map +1 -0
  89. package/dist/lib/esm/enums/enums.js +2 -0
  90. package/dist/lib/esm/enums/enums.js.map +1 -0
  91. package/dist/lib/esm/enums/migration-state.enum.js +25 -0
  92. package/dist/lib/esm/enums/migration-state.enum.js.map +1 -0
  93. package/dist/lib/esm/errors/errors.js +6 -0
  94. package/dist/lib/esm/errors/errors.js.map +1 -0
  95. package/dist/lib/esm/errors/migration-checksum-mismatch.error.js +20 -0
  96. package/dist/lib/esm/errors/migration-checksum-mismatch.error.js.map +1 -0
  97. package/dist/lib/esm/errors/migration-duplicate-name.error.js +17 -0
  98. package/dist/lib/esm/errors/migration-duplicate-name.error.js.map +1 -0
  99. package/dist/lib/esm/errors/migration-execution.error.js +17 -0
  100. package/dist/lib/esm/errors/migration-execution.error.js.map +1 -0
  101. package/dist/lib/esm/errors/migration-invalid-name.error.js +16 -0
  102. package/dist/lib/esm/errors/migration-invalid-name.error.js.map +1 -0
  103. package/dist/lib/esm/errors/migration-orphaned-record.error.js +18 -0
  104. package/dist/lib/esm/errors/migration-orphaned-record.error.js.map +1 -0
  105. package/dist/lib/esm/interfaces/interfaces.js +2 -0
  106. package/dist/lib/esm/interfaces/interfaces.js.map +1 -0
  107. package/dist/lib/esm/interfaces/mysql-migration.interface.js +2 -0
  108. package/dist/lib/esm/interfaces/mysql-migration.interface.js.map +1 -0
  109. package/dist/lib/esm/managers/managers.js +6 -0
  110. package/dist/lib/esm/managers/managers.js.map +1 -0
  111. package/dist/lib/esm/managers/mysql-migration-checksum.manager.js +32 -0
  112. package/dist/lib/esm/managers/mysql-migration-checksum.manager.js.map +1 -0
  113. package/dist/lib/esm/managers/mysql-migration-record.manager.js +93 -0
  114. package/dist/lib/esm/managers/mysql-migration-record.manager.js.map +1 -0
  115. package/dist/lib/esm/managers/mysql-migration-runner.manager.js +93 -0
  116. package/dist/lib/esm/managers/mysql-migration-runner.manager.js.map +1 -0
  117. package/dist/lib/esm/managers/mysql-migration-scaffold.manager.js +211 -0
  118. package/dist/lib/esm/managers/mysql-migration-scaffold.manager.js.map +1 -0
  119. package/dist/lib/esm/managers/mysql-migration.manager.js +258 -0
  120. package/dist/lib/esm/managers/mysql-migration.manager.js.map +1 -0
  121. package/dist/lib/esm/models/migration-apply-entry.model.js +7 -0
  122. package/dist/lib/esm/models/migration-apply-entry.model.js.map +1 -0
  123. package/dist/lib/esm/models/migration-apply-result.model.js +14 -0
  124. package/dist/lib/esm/models/migration-apply-result.model.js.map +1 -0
  125. package/dist/lib/esm/models/migration-plan-entry.model.js +7 -0
  126. package/dist/lib/esm/models/migration-plan-entry.model.js.map +1 -0
  127. package/dist/lib/esm/models/migration-plan.model.js +20 -0
  128. package/dist/lib/esm/models/migration-plan.model.js.map +1 -0
  129. package/dist/lib/esm/models/migration-record.model.js +8 -0
  130. package/dist/lib/esm/models/migration-record.model.js.map +1 -0
  131. package/dist/lib/esm/models/models.js +6 -0
  132. package/dist/lib/esm/models/models.js.map +1 -0
  133. package/dist/lib/esm/mysql-cli.configuration-keys.js +17 -0
  134. package/dist/lib/esm/mysql-cli.configuration-keys.js.map +1 -0
  135. package/dist/lib/esm/mysql-cli.module.js +46 -0
  136. package/dist/lib/esm/mysql-cli.module.js.map +1 -0
  137. package/dist/lib/esm/mysql-cli.module.keyname.js +2 -0
  138. package/dist/lib/esm/mysql-cli.module.keyname.js.map +1 -0
  139. package/dist/lib/esm/tsconfig.tsbuildinfo +1 -0
  140. package/dist/types/commands/commands.d.ts +8 -0
  141. package/dist/types/commands/mysql-migrate-create.command-options.d.ts +12 -0
  142. package/dist/types/commands/mysql-migrate-create.command.d.ts +32 -0
  143. package/dist/types/commands/mysql-migrate-status.command-options.d.ts +8 -0
  144. package/dist/types/commands/mysql-migrate-status.command.d.ts +25 -0
  145. package/dist/types/commands/mysql-migrate-verify.command-options.d.ts +8 -0
  146. package/dist/types/commands/mysql-migrate-verify.command.d.ts +23 -0
  147. package/dist/types/commands/mysql-migrate.command-options.d.ts +14 -0
  148. package/dist/types/commands/mysql-migrate.command.d.ts +23 -0
  149. package/dist/types/enums/enums.d.ts +1 -0
  150. package/dist/types/enums/migration-state.enum.d.ts +23 -0
  151. package/dist/types/errors/errors.d.ts +5 -0
  152. package/dist/types/errors/migration-checksum-mismatch.error.d.ts +14 -0
  153. package/dist/types/errors/migration-duplicate-name.error.d.ts +11 -0
  154. package/dist/types/errors/migration-execution.error.d.ts +12 -0
  155. package/dist/types/errors/migration-invalid-name.error.d.ts +10 -0
  156. package/dist/types/errors/migration-orphaned-record.error.d.ts +12 -0
  157. package/dist/types/interfaces/interfaces.d.ts +1 -0
  158. package/dist/types/interfaces/mysql-migration.interface.d.ts +40 -0
  159. package/dist/types/managers/managers.d.ts +5 -0
  160. package/dist/types/managers/mysql-migration-checksum.manager.d.ts +15 -0
  161. package/dist/types/managers/mysql-migration-record.manager.d.ts +22 -0
  162. package/dist/types/managers/mysql-migration-runner.manager.d.ts +16 -0
  163. package/dist/types/managers/mysql-migration-scaffold.manager.d.ts +40 -0
  164. package/dist/types/managers/mysql-migration.manager.d.ts +41 -0
  165. package/dist/types/models/migration-apply-entry.model.d.ts +9 -0
  166. package/dist/types/models/migration-apply-result.model.d.ts +14 -0
  167. package/dist/types/models/migration-plan-entry.model.d.ts +15 -0
  168. package/dist/types/models/migration-plan.model.d.ts +14 -0
  169. package/dist/types/models/migration-record.model.d.ts +12 -0
  170. package/dist/types/models/models.d.ts +5 -0
  171. package/dist/types/mysql-cli.configuration-keys.d.ts +29 -0
  172. package/dist/types/mysql-cli.module.d.ts +10 -0
  173. package/dist/types/mysql-cli.module.keyname.d.ts +1 -0
  174. package/package.json +75 -0
  175. 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.