@studiosonrai/nestjs-migrations 1.0.0 → 1.1.0
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/README.md +56 -0
- package/dist/bin/cli.js +35 -4
- package/dist/bin/cli.js.map +1 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +3 -6
- package/dist/src/index.js.map +1 -0
- package/dist/src/migration-core.d.ts +11 -32
- package/dist/src/migration-core.js +106 -50
- package/dist/src/migration-core.js.map +1 -0
- package/dist/src/migration.module.d.ts +0 -30
- package/dist/src/migration.module.js +1 -31
- package/dist/src/migration.module.js.map +1 -0
- package/dist/src/migration.service.d.ts +0 -13
- package/dist/src/migration.service.js +1 -14
- package/dist/src/migration.service.js.map +1 -0
- package/dist/src/types.d.ts +11 -52
- package/dist/src/types.js +18 -2
- package/dist/src/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +2 -2
|
@@ -11,33 +11,7 @@ exports.MigrationModule = void 0;
|
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
12
|
const migration_service_1 = require("./migration.service");
|
|
13
13
|
const types_1 = require("./types");
|
|
14
|
-
/**
|
|
15
|
-
* NestJS module for SQL Server migrations.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* // Synchronous configuration
|
|
19
|
-
* MigrationModule.forRoot({
|
|
20
|
-
* migrationsDir: path.join(__dirname, '../migrations'),
|
|
21
|
-
* autoRun: true,
|
|
22
|
-
* verbose: true,
|
|
23
|
-
* })
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* // Asynchronous configuration with ConfigService
|
|
27
|
-
* MigrationModule.forRootAsync({
|
|
28
|
-
* imports: [ConfigModule],
|
|
29
|
-
* inject: [ConfigService],
|
|
30
|
-
* useFactory: (configService: ConfigService) => ({
|
|
31
|
-
* migrationsDir: path.join(__dirname, '../migrations'),
|
|
32
|
-
* autoRun: configService.get<boolean>('AUTO_RUN_MIGRATIONS', false),
|
|
33
|
-
* verbose: true,
|
|
34
|
-
* }),
|
|
35
|
-
* })
|
|
36
|
-
*/
|
|
37
14
|
let MigrationModule = MigrationModule_1 = class MigrationModule {
|
|
38
|
-
/**
|
|
39
|
-
* Configure the migration module with static options.
|
|
40
|
-
*/
|
|
41
15
|
static forRoot(options) {
|
|
42
16
|
return {
|
|
43
17
|
module: MigrationModule_1,
|
|
@@ -51,10 +25,6 @@ let MigrationModule = MigrationModule_1 = class MigrationModule {
|
|
|
51
25
|
exports: [migration_service_1.MigrationService],
|
|
52
26
|
};
|
|
53
27
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Configure the migration module with async options.
|
|
56
|
-
* Useful when options depend on ConfigService or other async providers.
|
|
57
|
-
*/
|
|
58
28
|
static forRootAsync(options) {
|
|
59
29
|
return {
|
|
60
30
|
module: MigrationModule_1,
|
|
@@ -105,4 +75,4 @@ exports.MigrationModule = MigrationModule;
|
|
|
105
75
|
exports.MigrationModule = MigrationModule = MigrationModule_1 = __decorate([
|
|
106
76
|
(0, common_1.Module)({})
|
|
107
77
|
], MigrationModule);
|
|
108
|
-
//# sourceMappingURL=
|
|
78
|
+
//# sourceMappingURL=migration.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.module.js","sourceRoot":"","sources":["../../src/migration.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AACjE,2DAAuD;AACvD,mCAKiB;AA0BV,IAAM,eAAe,uBAArB,MAAM,eAAe;IAI1B,MAAM,CAAC,OAAO,CAAC,OAA+B;QAC5C,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,gCAAwB;oBACjC,QAAQ,EAAE,OAAO;iBAClB;gBACD,oCAAgB;aACjB;YACD,OAAO,EAAE,CAAC,oCAAgB,CAAC;SAC5B,CAAC;IACJ,CAAC;IAMD,MAAM,CAAC,YAAY,CAAC,OAAo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@@
|
|
|
1
1
|
import { OnModuleInit } from '@nestjs/common';
|
|
2
2
|
import { DataSource } from 'typeorm';
|
|
3
3
|
import { MigrationModuleOptions, MigrationResult, MigrationRunOptions } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* NestJS service for running SQL Server migrations.
|
|
6
|
-
* Automatically runs migrations on module initialization if autoRun is enabled.
|
|
7
|
-
*/
|
|
8
4
|
export declare class MigrationService implements OnModuleInit {
|
|
9
5
|
private readonly options;
|
|
10
6
|
private readonly migrationCore;
|
|
@@ -12,17 +8,8 @@ export declare class MigrationService implements OnModuleInit {
|
|
|
12
8
|
private readonly verbose;
|
|
13
9
|
constructor(options: MigrationModuleOptions, dataSource: DataSource);
|
|
14
10
|
onModuleInit(): Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* Run all pending migrations.
|
|
17
|
-
*/
|
|
18
11
|
runMigrations(options?: MigrationRunOptions): Promise<MigrationResult>;
|
|
19
|
-
/**
|
|
20
|
-
* Get list of pending migration files.
|
|
21
|
-
*/
|
|
22
12
|
getPendingMigrations(): Promise<string[]>;
|
|
23
|
-
/**
|
|
24
|
-
* Get migration status information.
|
|
25
|
-
*/
|
|
26
13
|
getStatus(): Promise<{
|
|
27
14
|
total: number;
|
|
28
15
|
applied: number;
|
|
@@ -17,10 +17,6 @@ const common_1 = require("@nestjs/common");
|
|
|
17
17
|
const typeorm_1 = require("typeorm");
|
|
18
18
|
const migration_core_1 = require("./migration-core");
|
|
19
19
|
const types_1 = require("./types");
|
|
20
|
-
/**
|
|
21
|
-
* NestJS service for running SQL Server migrations.
|
|
22
|
-
* Automatically runs migrations on module initialization if autoRun is enabled.
|
|
23
|
-
*/
|
|
24
20
|
let MigrationService = class MigrationService {
|
|
25
21
|
options;
|
|
26
22
|
migrationCore;
|
|
@@ -46,24 +42,15 @@ let MigrationService = class MigrationService {
|
|
|
46
42
|
}
|
|
47
43
|
await this.runMigrations();
|
|
48
44
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Run all pending migrations.
|
|
51
|
-
*/
|
|
52
45
|
async runMigrations(options) {
|
|
53
46
|
return this.migrationCore.runMigrations({
|
|
54
47
|
verbose: this.verbose,
|
|
55
48
|
...options,
|
|
56
49
|
});
|
|
57
50
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Get list of pending migration files.
|
|
60
|
-
*/
|
|
61
51
|
async getPendingMigrations() {
|
|
62
52
|
return this.migrationCore.getPendingMigrations();
|
|
63
53
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Get migration status information.
|
|
66
|
-
*/
|
|
67
54
|
async getStatus() {
|
|
68
55
|
return this.migrationCore.getStatus();
|
|
69
56
|
}
|
|
@@ -74,4 +61,4 @@ exports.MigrationService = MigrationService = __decorate([
|
|
|
74
61
|
__param(0, (0, common_1.Inject)(types_1.MIGRATION_MODULE_OPTIONS)),
|
|
75
62
|
__metadata("design:paramtypes", [Object, typeorm_1.DataSource])
|
|
76
63
|
], MigrationService);
|
|
77
|
-
//# sourceMappingURL=
|
|
64
|
+
//# sourceMappingURL=migration.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.service.js","sourceRoot":"","sources":["../../src/migration.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAkE;AAClE,qCAAqC;AACrC,qDAAiD;AACjD,mCAKiB;AAOV,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAOR;IANF,aAAa,CAAgB;IAC7B,OAAO,CAAU;IACjB,OAAO,CAAU;IAElC,YAEmB,OAA+B,EAChD,UAAsB;QADL,YAAO,GAAP,OAAO,CAAwB;QAGhD,IAAI,CAAC,aAAa,GAAG,IAAI,8BAAa,CAAC,UAAU,EAAE;YACjD,aAAa,EAAE,OAAO,CAAC,aAAa;SACrC,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;YAC9C,CAAC;YACD,OAAO;QACT,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QAC5C,CAAC;QAED,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;IAC7B,CAAC;IAKD,KAAK,CAAC,aAAa,CAAC,OAA6B;QAC/C,OAAO,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC;YACtC,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAKD,KAAK,CAAC,oBAAoB;QACxB,OAAO,IAAI,CAAC,aAAa,CAAC,oBAAoB,EAAE,CAAC;IACnD,CAAC;IAKD,KAAK,CAAC,SAAS;QAMb,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;IACxC,CAAC;CACF,CAAA;AA5DY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAOR,WAAA,IAAA,eAAM,EAAC,gCAAwB,CAAC,CAAA;6CAErB,oBAAU;GARb,gBAAgB,CA4D5B"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,83 +1,42 @@
|
|
|
1
1
|
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
2
|
export interface MigrationModuleOptions {
|
|
3
|
-
/**
|
|
4
|
-
* Path to the directory containing SQL migration files
|
|
5
|
-
*/
|
|
6
3
|
migrationsDir: string;
|
|
7
|
-
/**
|
|
8
|
-
* Whether to automatically run migrations on module initialization
|
|
9
|
-
* @default false
|
|
10
|
-
*/
|
|
11
4
|
autoRun?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Whether to log verbose output during migration execution
|
|
14
|
-
* @default true
|
|
15
|
-
*/
|
|
16
5
|
verbose?: boolean;
|
|
17
6
|
}
|
|
18
7
|
export interface MigrationModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
19
|
-
/**
|
|
20
|
-
* Factory function to create MigrationModuleOptions
|
|
21
|
-
*/
|
|
22
8
|
useFactory: (...args: any[]) => Promise<MigrationModuleOptions> | MigrationModuleOptions;
|
|
23
|
-
/**
|
|
24
|
-
* Dependencies to inject into the factory function
|
|
25
|
-
*/
|
|
26
9
|
inject?: any[];
|
|
27
|
-
/**
|
|
28
|
-
* Optional class to use for creating options
|
|
29
|
-
*/
|
|
30
10
|
useClass?: Type<MigrationModuleOptionsFactory>;
|
|
31
|
-
/**
|
|
32
|
-
* Optional existing instance to use for options
|
|
33
|
-
*/
|
|
34
11
|
useExisting?: Type<MigrationModuleOptionsFactory>;
|
|
35
12
|
}
|
|
36
13
|
export interface MigrationModuleOptionsFactory {
|
|
37
14
|
createMigrationOptions(): Promise<MigrationModuleOptions> | MigrationModuleOptions;
|
|
38
15
|
}
|
|
39
16
|
export interface MigrationResult {
|
|
40
|
-
/**
|
|
41
|
-
* Whether the migration run was successful
|
|
42
|
-
*/
|
|
43
17
|
success: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Total number of migration files found
|
|
46
|
-
*/
|
|
47
18
|
totalMigrations: number;
|
|
48
|
-
/**
|
|
49
|
-
* Number of migrations already applied
|
|
50
|
-
*/
|
|
51
19
|
appliedMigrations: number;
|
|
52
|
-
/**
|
|
53
|
-
* Number of pending migrations to apply
|
|
54
|
-
*/
|
|
55
20
|
pendingMigrations: number;
|
|
56
|
-
/**
|
|
57
|
-
* Name of the failed migration file (if any)
|
|
58
|
-
*/
|
|
59
21
|
failedMigration?: string;
|
|
60
|
-
/**
|
|
61
|
-
* Error object if migration failed
|
|
62
|
-
*/
|
|
63
22
|
error?: any;
|
|
64
23
|
}
|
|
65
24
|
export interface MigrationRunOptions {
|
|
66
|
-
/**
|
|
67
|
-
* If true, only list pending migrations without applying them
|
|
68
|
-
* @default false
|
|
69
|
-
*/
|
|
70
25
|
dryRun?: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* Whether to log verbose output
|
|
73
|
-
* @default false
|
|
74
|
-
*/
|
|
75
26
|
verbose?: boolean;
|
|
76
27
|
}
|
|
77
28
|
export interface MigrationCoreOptions {
|
|
78
|
-
/**
|
|
79
|
-
* Path to the directory containing SQL migration files
|
|
80
|
-
*/
|
|
81
29
|
migrationsDir: string;
|
|
82
30
|
}
|
|
83
31
|
export declare const MIGRATION_MODULE_OPTIONS: unique symbol;
|
|
32
|
+
export interface AppliedMigration {
|
|
33
|
+
name: string;
|
|
34
|
+
content_hash: string;
|
|
35
|
+
run_on: Date;
|
|
36
|
+
}
|
|
37
|
+
export declare class HashMismatchError extends Error {
|
|
38
|
+
readonly migrationName: string;
|
|
39
|
+
readonly expectedHash: string;
|
|
40
|
+
readonly actualHash: string;
|
|
41
|
+
constructor(migrationName: string, expectedHash: string, actualHash: string);
|
|
42
|
+
}
|
package/dist/src/types.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MIGRATION_MODULE_OPTIONS = void 0;
|
|
3
|
+
exports.HashMismatchError = exports.MIGRATION_MODULE_OPTIONS = void 0;
|
|
4
4
|
exports.MIGRATION_MODULE_OPTIONS = Symbol('MIGRATION_MODULE_OPTIONS');
|
|
5
|
-
|
|
5
|
+
class HashMismatchError extends Error {
|
|
6
|
+
migrationName;
|
|
7
|
+
expectedHash;
|
|
8
|
+
actualHash;
|
|
9
|
+
constructor(migrationName, expectedHash, actualHash) {
|
|
10
|
+
super(`Migration file "${migrationName}" has been modified after being applied.\n` +
|
|
11
|
+
` Expected hash: ${expectedHash}\n` +
|
|
12
|
+
` Actual hash: ${actualHash}\n` +
|
|
13
|
+
`This is a critical error. Migration files must not be modified after being applied.`);
|
|
14
|
+
this.migrationName = migrationName;
|
|
15
|
+
this.expectedHash = expectedHash;
|
|
16
|
+
this.actualHash = actualHash;
|
|
17
|
+
this.name = 'HashMismatchError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.HashMismatchError = HashMismatchError;
|
|
21
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAyGa,QAAA,wBAAwB,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC;AAyB3E,MAAa,iBAAkB,SAAQ,KAAK;IAExB;IACA;IACA;IAHlB,YACkB,aAAqB,EACrB,YAAoB,EACpB,UAAkB;QAElC,KAAK,CACH,mBAAmB,aAAa,4CAA4C;YAC1E,oBAAoB,YAAY,IAAI;YACpC,oBAAoB,UAAU,IAAI;YAClC,qFAAqF,CACxF,CAAC;QATc,kBAAa,GAAb,aAAa,CAAQ;QACrB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,eAAU,GAAV,UAAU,CAAQ;QAQlC,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAdD,8CAcC"}
|