@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
@@ -0,0 +1,12 @@
1
+ import "reflect-metadata";
2
+ /**
3
+ * Flags for `pristine mysql:create --name <name> [--config <keyname>]`.
4
+ *
5
+ * `name` is the human-readable description (e.g. `add-products-table`). The scaffold
6
+ * slugifies it, prepends the next sequential number, and writes the `.ts` file. It is
7
+ * required; when it isn't passed and the terminal is interactive, the CLI asks for it.
8
+ */
9
+ export declare class MysqlMigrateCreateCommandOptions {
10
+ name: string;
11
+ config?: string;
12
+ }
@@ -0,0 +1,32 @@
1
+ import { ExitCode } from "@pristine-ts/common";
2
+ import { LogHandlerInterface } from "@pristine-ts/logging";
3
+ import { CommandInterface, CliOutput } from "@pristine-ts/cli";
4
+ import { MysqlMigrationScaffoldManager } from "../managers/mysql-migration-scaffold.manager";
5
+ import { MysqlMigrateCreateCommandOptions } from "./mysql-migrate-create.command-options";
6
+ /**
7
+ * `pristine mysql:create --name <name> [--config <keyname>]`
8
+ *
9
+ * Scaffolds a new `.sql-migrations.ts` file under the configured scaffold path
10
+ * (`pristine.mysql-cli.scaffold.path`, default `src/sql-migrations`). When the
11
+ * config key `pristine.mysql-cli.scaffold.barrelPath` is set, splices the new
12
+ * import and class reference into that file between the marker comments
13
+ * `<pristine:migration-imports:start/end>` and `<pristine:migration-services:start/end>`.
14
+ *
15
+ * Numbering is sequential: the scaffold scans the target directory for files
16
+ * matching `<digits>-<slug>.sql-migrations.ts`, picks `max + 1`, pads to the
17
+ * existing width (default 2). If you cross 99, do a one-time rename of the
18
+ * existing files to 3-digit width and the scaffold respects it going forward.
19
+ */
20
+ export declare class MysqlMigrateCreateCommand implements CommandInterface<MysqlMigrateCreateCommandOptions> {
21
+ private readonly scaffoldPath;
22
+ private readonly scaffoldBarrelPath;
23
+ private readonly scaffoldManager;
24
+ private readonly cliOutput;
25
+ private readonly logHandler;
26
+ optionsType: typeof MysqlMigrateCreateCommandOptions;
27
+ name: string;
28
+ description: string;
29
+ constructor(scaffoldPath: string, scaffoldBarrelPath: string, scaffoldManager: MysqlMigrationScaffoldManager, cliOutput: CliOutput, logHandler: LogHandlerInterface);
30
+ run(args: MysqlMigrateCreateCommandOptions): Promise<ExitCode | number>;
31
+ private printManualInstructions;
32
+ }
@@ -0,0 +1,8 @@
1
+ import "reflect-metadata";
2
+ /**
3
+ * Flags for `pristine mysql:status [--config <keyname>]`. Status is informational
4
+ * and always exits 0 — for a CI gate that fails on drift, use `mysql:verify`.
5
+ */
6
+ export declare class MysqlMigrateStatusCommandOptions {
7
+ config?: string;
8
+ }
@@ -0,0 +1,25 @@
1
+ import { ExitCode } from "@pristine-ts/common";
2
+ import { LogHandlerInterface } from "@pristine-ts/logging";
3
+ import { CommandInterface, CliOutput } from "@pristine-ts/cli";
4
+ import { MysqlMigrationManager } from "../managers/mysql-migration.manager";
5
+ import { MysqlMigrateStatusCommandOptions } from "./mysql-migrate-status.command-options";
6
+ /**
7
+ * `pristine mysql:status [--config <keyname>]`
8
+ *
9
+ * Prints the disk-vs-database diff. Reports each migration as Pending, Applied,
10
+ * Modified, or Orphaned. Informational only — always exits 0. Use `mysql:verify`
11
+ * to fail on drift.
12
+ */
13
+ export declare class MysqlMigrateStatusCommand implements CommandInterface<MysqlMigrateStatusCommandOptions> {
14
+ private readonly migrationManager;
15
+ private readonly cliOutput;
16
+ private readonly logHandler;
17
+ optionsType: typeof MysqlMigrateStatusCommandOptions;
18
+ name: string;
19
+ description: string;
20
+ private static readonly DefaultConfigKeyname;
21
+ constructor(migrationManager: MysqlMigrationManager, cliOutput: CliOutput, logHandler: LogHandlerInterface);
22
+ run(args: MysqlMigrateStatusCommandOptions): Promise<ExitCode | number>;
23
+ private formatState;
24
+ private formatSuffix;
25
+ }
@@ -0,0 +1,8 @@
1
+ import "reflect-metadata";
2
+ /**
3
+ * Flags for `pristine mysql:verify [--config <keyname>]`. Verify exits non-zero
4
+ * when any Modified or Orphaned entries are detected; designed for CI gates.
5
+ */
6
+ export declare class MysqlMigrateVerifyCommandOptions {
7
+ config?: string;
8
+ }
@@ -0,0 +1,23 @@
1
+ import { ExitCode } from "@pristine-ts/common";
2
+ import { LogHandlerInterface } from "@pristine-ts/logging";
3
+ import { CommandInterface, CliOutput } from "@pristine-ts/cli";
4
+ import { MysqlMigrationManager } from "../managers/mysql-migration.manager";
5
+ import { MysqlMigrateVerifyCommandOptions } from "./mysql-migrate-verify.command-options";
6
+ /**
7
+ * `pristine mysql:verify [--config <keyname>]`
8
+ *
9
+ * Same scan as `mysql:status`, but exits non-zero if any Modified or Orphaned
10
+ * entries exist. Designed for CI gates: a clean exit means the database and the
11
+ * registered migrations are in agreement.
12
+ */
13
+ export declare class MysqlMigrateVerifyCommand implements CommandInterface<MysqlMigrateVerifyCommandOptions> {
14
+ private readonly migrationManager;
15
+ private readonly cliOutput;
16
+ private readonly logHandler;
17
+ optionsType: typeof MysqlMigrateVerifyCommandOptions;
18
+ name: string;
19
+ description: string;
20
+ private static readonly DefaultConfigKeyname;
21
+ constructor(migrationManager: MysqlMigrationManager, cliOutput: CliOutput, logHandler: LogHandlerInterface);
22
+ run(args: MysqlMigrateVerifyCommandOptions): Promise<ExitCode | number>;
23
+ }
@@ -0,0 +1,14 @@
1
+ import "reflect-metadata";
2
+ /**
3
+ * Flags for `pristine mysql:migrate [--config <keyname>] [--dry-run] [--force]`.
4
+ *
5
+ * `--config` picks the `MysqlConfig.uniqueKeyname` to target. Defaults to
6
+ * `__default__`. `--dry-run` prints the plan without writing anything. `--force`
7
+ * overrides the refusal-to-proceed when drift (Modified / Orphaned entries) is
8
+ * detected — used sparingly, on environments you're comfortable diverging.
9
+ */
10
+ export declare class MysqlMigrateCommandOptions {
11
+ config?: string;
12
+ "dry-run"?: boolean;
13
+ force?: boolean;
14
+ }
@@ -0,0 +1,23 @@
1
+ import { ExitCode } from "@pristine-ts/common";
2
+ import { LogHandlerInterface } from "@pristine-ts/logging";
3
+ import { CommandInterface, CliOutput } from "@pristine-ts/cli";
4
+ import { MysqlMigrationManager } from "../managers/mysql-migration.manager";
5
+ import { MysqlMigrateCommandOptions } from "./mysql-migrate.command-options";
6
+ /**
7
+ * `pristine mysql:migrate [--config <keyname>] [--dry-run] [--force]`
8
+ *
9
+ * Applies every Pending migration against the targeted database. Halts on the first
10
+ * failure. Refuses to proceed when drift (Modified / Orphaned entries) exists unless
11
+ * `--force` is given.
12
+ */
13
+ export declare class MysqlMigrateCommand implements CommandInterface<MysqlMigrateCommandOptions> {
14
+ private readonly migrationManager;
15
+ private readonly cliOutput;
16
+ private readonly logHandler;
17
+ optionsType: typeof MysqlMigrateCommandOptions;
18
+ name: string;
19
+ description: string;
20
+ private static readonly DefaultConfigKeyname;
21
+ constructor(migrationManager: MysqlMigrationManager, cliOutput: CliOutput, logHandler: LogHandlerInterface);
22
+ run(args: MysqlMigrateCommandOptions): Promise<ExitCode | number>;
23
+ }
@@ -0,0 +1 @@
1
+ export * from "./migration-state.enum";
@@ -0,0 +1,23 @@
1
+ /**
2
+ * State of a single migration as observed by `MysqlMigrationManager.status` /
3
+ * `verify`. Computed from the union of registered migrations (DI) and applied
4
+ * records (the `pristine_migrations` table).
5
+ */
6
+ export declare enum MigrationStateEnum {
7
+ /** Registered in DI, not in the database. Will be applied next `migrate` run. */
8
+ Pending = "pending",
9
+ /** Registered in DI, in the database, checksums match. Nothing to do. */
10
+ Applied = "applied",
11
+ /**
12
+ * Registered in DI, in the database, checksums differ. The migration's `up()` was
13
+ * edited after it was applied. Verify fails; apply refuses to proceed (unless
14
+ * `--force`).
15
+ */
16
+ Modified = "modified",
17
+ /**
18
+ * In the database, not registered in DI. The class was deleted from the codebase,
19
+ * or the CLI is targeting the wrong config. Verify fails; apply refuses to proceed
20
+ * (unless `--force`).
21
+ */
22
+ Orphaned = "orphaned"
23
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./migration-checksum-mismatch.error";
2
+ export * from "./migration-duplicate-name.error";
3
+ export * from "./migration-execution.error";
4
+ export * from "./migration-invalid-name.error";
5
+ export * from "./migration-orphaned-record.error";
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Thrown by `verify` (and by `apply` without `--force`) when a migration that's
3
+ * already applied has had its `up()` body edited since. Indicates someone changed
4
+ * a migration after it ran somewhere — the new SQL was never applied to that
5
+ * database. The fix is either to revert the change or to write a new migration
6
+ * that produces the desired state.
7
+ */
8
+ export declare class MigrationChecksumMismatchError extends Error {
9
+ readonly migrationName: string;
10
+ readonly configUniqueKeyname: string;
11
+ readonly diskChecksum: string;
12
+ readonly appliedChecksum: string;
13
+ constructor(migrationName: string, configUniqueKeyname: string, diskChecksum: string, appliedChecksum: string);
14
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Thrown when two registered migrations share the same `name` after filtering by
3
+ * `configUniqueKeynames` for the targeted config. Names must be globally unique per
4
+ * config because the database stores them in a `UNIQUE` column. The usual cause is
5
+ * a copy-paste mistake at scaffold time.
6
+ */
7
+ export declare class MigrationDuplicateNameError extends Error {
8
+ readonly migrationName: string;
9
+ readonly configUniqueKeyname: string;
10
+ constructor(migrationName: string, configUniqueKeyname: string);
11
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Thrown when mysql2 raises an error while executing a migration's SQL. Carries the
3
+ * failing migration name and wraps the underlying error for context. The `apply`
4
+ * orchestrator catches this, halts further migrations, and reports it as the
5
+ * `failedMigration` entry on the result.
6
+ */
7
+ export declare class MigrationExecutionError extends Error {
8
+ readonly migrationName: string;
9
+ readonly configUniqueKeyname: string;
10
+ readonly cause: Error;
11
+ constructor(migrationName: string, configUniqueKeyname: string, cause: Error);
12
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Thrown when a registered migration's `name` doesn't satisfy the
3
+ * `<NN>-<kebab-slug>` regex (`/^\d+-[a-z0-9-]+$/`). Indicates a hand-edited or
4
+ * misnamed migration class. The fix is to rename to the convention and update the
5
+ * `name` field.
6
+ */
7
+ export declare class MigrationInvalidNameError extends Error {
8
+ readonly migrationName: string;
9
+ constructor(migrationName: string);
10
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Thrown by `verify` (and by `apply` without `--force`) when the bookkeeping table
3
+ * holds a record for a migration that no longer exists in the registered DI graph.
4
+ * Indicates a deleted migration class, a renamed `name` field, or running against
5
+ * the wrong config. The fix is to restore the class, fix the name, or run against
6
+ * the correct config.
7
+ */
8
+ export declare class MigrationOrphanedRecordError extends Error {
9
+ readonly migrationName: string;
10
+ readonly configUniqueKeyname: string;
11
+ constructor(migrationName: string, configUniqueKeyname: string);
12
+ }
@@ -0,0 +1 @@
1
+ export * from "./mysql-migration.interface";
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Contract every MySQL migration class implements. Implementations are discovered by
3
+ * the MysqlMigrationManager via the tsyringe DI container — register each class with
4
+ * `@tag("MysqlMigrationInterface") @injectable()` and import it (directly or via a
5
+ * MigrationsModule) into the AppModule's service graph.
6
+ *
7
+ * Migrations are forward-only by design. There is no `down()`. Roll forward by writing
8
+ * a new migration.
9
+ */
10
+ export interface MysqlMigrationInterface {
11
+ /**
12
+ * Unique, sortable identifier. Convention: `<NN>-<kebab-slug>` matching the filename
13
+ * minus `.sql-migrations.ts`. Lexicographic sort across `name` defines the apply
14
+ * order. Stored verbatim in pristine_migrations.filename.
15
+ *
16
+ * Use the convention. Manual identifiers break apply ordering and confuse the
17
+ * scaffold command. `pristine mysql:create` produces compliant names automatically.
18
+ */
19
+ readonly name: string;
20
+ /**
21
+ * Which database configs this migration applies to. Each entry is a
22
+ * `MysqlConfig.uniqueKeyname`.
23
+ *
24
+ * Leave undefined to apply to every registered config; set to an explicit list to
25
+ * scope this migration to one or more specific databases — useful for multi-DB apps
26
+ * where, say, a schema change only lands in the analytics DB.
27
+ *
28
+ * The CLI's `--config <keyname>` flag picks the database being targeted in this
29
+ * invocation; a migration is selected for that invocation iff
30
+ * `configUniqueKeynames === undefined || configUniqueKeynames.includes(targetConfig)`.
31
+ */
32
+ readonly configUniqueKeynames?: string[];
33
+ /**
34
+ * Returns the SQL to execute. The string may contain multiple statements separated
35
+ * by `;`; the runner connection has `multipleStatements: true`. Async so migrations
36
+ * can pull dynamic content — but the returned SQL MUST be deterministic across runs,
37
+ * otherwise checksum-based drift detection will generate false positives.
38
+ */
39
+ up(): Promise<string> | string;
40
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./mysql-migration-checksum.manager";
2
+ export * from "./mysql-migration-record.manager";
3
+ export * from "./mysql-migration-runner.manager";
4
+ export * from "./mysql-migration-scaffold.manager";
5
+ export * from "./mysql-migration.manager";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Computes the stable sha256 hex digest of a migration's SQL string. Used both at
3
+ * apply time (to record what was applied) and at status/verify time (to detect
4
+ * drift). Canonicalization strips trivial editor noise — trailing whitespace per
5
+ * line, CRLF endings, leading/trailing whitespace — so identical SQL with different
6
+ * line-ending or final-newline conventions hashes the same.
7
+ *
8
+ * Whitespace *between* tokens is preserved: changing `SELECT *` to `SELECT *`
9
+ * does change the checksum. That's deliberate — anything beyond formatting noise
10
+ * is a real edit, and the user should know.
11
+ */
12
+ export declare class MysqlMigrationChecksumManager {
13
+ compute(sql: string): string;
14
+ private canonicalize;
15
+ }
@@ -0,0 +1,22 @@
1
+ import { LogHandlerInterface } from "@pristine-ts/logging";
2
+ import { MysqlClientInterface } from "@pristine-ts/mysql";
3
+ import { MigrationRecord } from "../models/migration-record.model";
4
+ /**
5
+ * Owns the `pristine_migrations` bookkeeping table — creates it on demand, reads
6
+ * the applied rows back, and inserts a new row when a migration finishes.
7
+ *
8
+ * Uses the regular `MysqlClient` pool (no `multipleStatements` needed for any of
9
+ * these queries — they're single statements with parameter placeholders).
10
+ */
11
+ export declare class MysqlMigrationRecordManager {
12
+ private readonly mysqlClient;
13
+ private readonly logHandler;
14
+ constructor(mysqlClient: MysqlClientInterface, logHandler: LogHandlerInterface);
15
+ ensureTable(configUniqueKeyname: string, tableName: string): Promise<void>;
16
+ listApplied(configUniqueKeyname: string, tableName: string): Promise<MigrationRecord[]>;
17
+ recordApplied(configUniqueKeyname: string, tableName: string, record: {
18
+ filename: string;
19
+ checksum: string;
20
+ executionTimeMs: number;
21
+ }): Promise<void>;
22
+ }
@@ -0,0 +1,16 @@
1
+ import { LogHandlerInterface } from "@pristine-ts/logging";
2
+ import { MysqlConfigProviderInterface } from "@pristine-ts/mysql";
3
+ /**
4
+ * Executes a single migration's SQL string against a target database. Opens a
5
+ * one-shot mysql2 connection with `multipleStatements: true` for the call and
6
+ * closes it in `finally` — does NOT touch the cached `MysqlClient` pool because
7
+ * flipping `multipleStatements` on the pool would leak to every other consumer
8
+ * of the client. A dedicated connection per migration is the cleanest isolation.
9
+ */
10
+ export declare class MysqlMigrationRunner {
11
+ private readonly mysqlConfigProviders;
12
+ private readonly logHandler;
13
+ constructor(mysqlConfigProviders: MysqlConfigProviderInterface[], logHandler: LogHandlerInterface);
14
+ execute(configUniqueKeyname: string, migrationName: string, sql: string): Promise<number>;
15
+ private resolveConfig;
16
+ }
@@ -0,0 +1,40 @@
1
+ import { LogHandlerInterface } from "@pristine-ts/logging";
2
+ /**
3
+ * Generates a new `.sql-migrations.ts` file and optionally splices its registration
4
+ * into a marker-annotated migrations module file. Pure dev-time scaffolding — never
5
+ * touches the database, never resolved at runtime in production.
6
+ *
7
+ * Numbering: scans the target directory for files matching `<digits>-<slug>.sql-migrations.ts`,
8
+ * picks `max + 1`, and pads to the current width (default 2 digits, never narrows).
9
+ * If you cross 99 you'll want to rename existing files to 3-digit padding once; the
10
+ * scaffold respects whichever width it finds.
11
+ */
12
+ export declare class MysqlMigrationScaffoldManager {
13
+ private readonly logHandler;
14
+ private static readonly FilenamePattern;
15
+ private static readonly ImportsStart;
16
+ private static readonly ImportsEnd;
17
+ private static readonly ServicesStart;
18
+ private static readonly ServicesEnd;
19
+ constructor(logHandler: LogHandlerInterface);
20
+ create(options: {
21
+ scaffoldPath: string;
22
+ descriptiveName: string;
23
+ barrelPath?: string;
24
+ configUniqueKeynames?: string[];
25
+ }): Promise<{
26
+ filePath: string;
27
+ className: string;
28
+ migrationName: string;
29
+ barrelUpdated: boolean;
30
+ }>;
31
+ renderMigrationFile(className: string, migrationName: string, configUniqueKeynames?: string[]): string;
32
+ buildClassName(slug: string, paddedNumber: string): string;
33
+ slugify(input: string): string;
34
+ private tryUpdateBarrel;
35
+ private insertSortedBetween;
36
+ private relativeImportSpecifier;
37
+ private listExistingNumberPrefixes;
38
+ private resolveWidth;
39
+ private exists;
40
+ }
@@ -0,0 +1,41 @@
1
+ import { LogHandlerInterface } from "@pristine-ts/logging";
2
+ import { MysqlConfigProviderInterface } from "@pristine-ts/mysql";
3
+ import { MysqlMigrationInterface } from "../interfaces/mysql-migration.interface";
4
+ import { MigrationPlan } from "../models/migration-plan.model";
5
+ import { MigrationApplyResult } from "../models/migration-apply-result.model";
6
+ import { MysqlMigrationChecksumManager } from "./mysql-migration-checksum.manager";
7
+ import { MysqlMigrationRecordManager } from "./mysql-migration-record.manager";
8
+ import { MysqlMigrationRunner } from "./mysql-migration-runner.manager";
9
+ /**
10
+ * Public orchestrator for migration operations. The CLI commands and any deploy-time
11
+ * runner should depend on this class — never on `MysqlMigrationRunner` /
12
+ * `MysqlMigrationRecordManager` directly.
13
+ *
14
+ * Discovery is DI-based: every migration registered with
15
+ * `@tag("MysqlMigrationInterface") @injectable()` and reachable through the AppModule's
16
+ * `importServices` graph is injected here via `@injectAll`. There is no filesystem
17
+ * scan at apply time, which means this works identically in a bundled Lambda and on
18
+ * a dev laptop.
19
+ */
20
+ export declare class MysqlMigrationManager {
21
+ private readonly registeredMigrations;
22
+ private readonly mysqlConfigProviders;
23
+ private readonly recordManager;
24
+ private readonly runner;
25
+ private readonly checksumManager;
26
+ private readonly logHandler;
27
+ private static readonly DefaultTableName;
28
+ private static readonly ValidNamePattern;
29
+ constructor(registeredMigrations: MysqlMigrationInterface[], mysqlConfigProviders: MysqlConfigProviderInterface[], recordManager: MysqlMigrationRecordManager, runner: MysqlMigrationRunner, checksumManager: MysqlMigrationChecksumManager, logHandler: LogHandlerInterface);
30
+ status(configUniqueKeyname: string): Promise<MigrationPlan>;
31
+ verify(configUniqueKeyname: string): Promise<MigrationPlan>;
32
+ apply(configUniqueKeyname: string, options?: {
33
+ dryRun?: boolean;
34
+ force?: boolean;
35
+ }): Promise<MigrationApplyResult>;
36
+ private resolveConfig;
37
+ private resolveTableName;
38
+ private selectMigrations;
39
+ private buildPlan;
40
+ private assertNoDrift;
41
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * One row of a `MigrationApplyResult`: the outcome of applying a single migration.
3
+ * `error` is populated only when the migration failed.
4
+ */
5
+ export declare class MigrationApplyEntry {
6
+ name: string;
7
+ executionTimeMs: number;
8
+ error?: string;
9
+ }
@@ -0,0 +1,14 @@
1
+ import { MigrationApplyEntry } from "./migration-apply-entry.model";
2
+ /**
3
+ * Output of `MysqlMigrationManager.apply`. `appliedMigrations` is the in-order list
4
+ * of migrations that ran successfully. `skippedAlreadyApplied` is the list of
5
+ * names that were already in the database (no-op). `failedMigration` is set when
6
+ * the run halted on a failure — subsequent pending migrations were not attempted.
7
+ */
8
+ export declare class MigrationApplyResult {
9
+ configUniqueKeyname: string;
10
+ dryRun: boolean;
11
+ appliedMigrations: MigrationApplyEntry[];
12
+ skippedAlreadyApplied: string[];
13
+ failedMigration?: MigrationApplyEntry;
14
+ }
@@ -0,0 +1,15 @@
1
+ import { MigrationStateEnum } from "../enums/migration-state.enum";
2
+ /**
3
+ * One row of a `MigrationPlan`: the union view of a single migration as it appears
4
+ * to both the DI registry and the bookkeeping table. State combines the two views.
5
+ */
6
+ export declare class MigrationPlanEntry {
7
+ name: string;
8
+ state: MigrationStateEnum;
9
+ /** sha256 of the SQL returned by the registered migration's `up()` — undefined when Orphaned. */
10
+ diskChecksum?: string;
11
+ /** sha256 stored at the time of apply — undefined when Pending. */
12
+ appliedChecksum?: string;
13
+ /** When the migration was applied — undefined when Pending. */
14
+ appliedAt?: Date;
15
+ }
@@ -0,0 +1,14 @@
1
+ import { MigrationStateEnum } from "../enums/migration-state.enum";
2
+ import { MigrationPlanEntry } from "./migration-plan-entry.model";
3
+ /**
4
+ * Output of `MysqlMigrationManager.status` (and `verify` when no drift exists). The
5
+ * `entries` array is sorted lexicographically by `name`, matching apply order.
6
+ */
7
+ export declare class MigrationPlan {
8
+ configUniqueKeyname: string;
9
+ tableName: string;
10
+ entries: MigrationPlanEntry[];
11
+ hasPending(): boolean;
12
+ hasDrift(): boolean;
13
+ countByState(state: MigrationStateEnum): number;
14
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * One row of the `pristine_migrations` bookkeeping table. Mirrors the schema exactly
3
+ * (snake_case in the database; the manager handles translation when reading rows
4
+ * back via `MysqlClient.executeSql`).
5
+ */
6
+ export declare class MigrationRecord {
7
+ id: number;
8
+ filename: string;
9
+ checksum: string;
10
+ appliedAt: Date;
11
+ executionTimeMs?: number;
12
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./migration-apply-entry.model";
2
+ export * from "./migration-apply-result.model";
3
+ export * from "./migration-plan-entry.model";
4
+ export * from "./migration-plan.model";
5
+ export * from "./migration-record.model";
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Typed configuration keys for `@pristine-ts/mysql-cli`. Use these constants with
3
+ * `@injectConfig` for autocomplete + rename safety, instead of typing the parameter
4
+ * name as a string.
5
+ *
6
+ * ```ts
7
+ * import {injectConfig} from "@pristine-ts/common";
8
+ * import {MysqlCliConfigurationKeys} from "@pristine-ts/mysql-cli";
9
+ *
10
+ * constructor(@injectConfig(MysqlCliConfigurationKeys.ScaffoldPath) path: string) {}
11
+ * ```
12
+ */
13
+ export declare const MysqlCliConfigurationKeys: {
14
+ readonly ScaffoldPath: "pristine.mysql-cli.scaffold.path";
15
+ readonly ScaffoldBarrelPath: "pristine.mysql-cli.scaffold.barrelPath";
16
+ };
17
+ export interface MysqlCliConfigurationValueMap {
18
+ "pristine.mysql-cli.scaffold.path": string;
19
+ /**
20
+ * Empty string means "not set" — the command treats `""` and a real path
21
+ * differently. `ConfigurationDefinition` does not allow `undefined` defaults,
22
+ * so we use an empty string as the unset sentinel.
23
+ */
24
+ "pristine.mysql-cli.scaffold.barrelPath": string;
25
+ }
26
+ declare module "@pristine-ts/common" {
27
+ interface PristineConfigurationValueMap extends MysqlCliConfigurationValueMap {
28
+ }
29
+ }
@@ -0,0 +1,10 @@
1
+ import { ModuleInterface } from "@pristine-ts/common";
2
+ export * from "./commands/commands";
3
+ export * from "./enums/enums";
4
+ export * from "./errors/errors";
5
+ export * from "./interfaces/interfaces";
6
+ export * from "./managers/managers";
7
+ export * from "./models/models";
8
+ export * from "./mysql-cli.configuration-keys";
9
+ export * from "./mysql-cli.module.keyname";
10
+ export declare const MysqlCliModule: ModuleInterface;
@@ -0,0 +1 @@
1
+ export declare const MysqlCliModuleKeyname: string;