@webiny/data-migration 0.0.0-unstable.06b2ede40f
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 +21 -0
- package/MigrationRunner.d.ts +22 -0
- package/MigrationRunner.js +341 -0
- package/MigrationRunner.js.map +1 -0
- package/README.md +6 -0
- package/cli/CliMigrationRunReporter.d.ts +10 -0
- package/cli/CliMigrationRunReporter.js +55 -0
- package/cli/CliMigrationRunReporter.js.map +1 -0
- package/cli/InteractiveCliStatusReporter.d.ts +11 -0
- package/cli/InteractiveCliStatusReporter.js +74 -0
- package/cli/InteractiveCliStatusReporter.js.map +1 -0
- package/cli/LogReporter.d.ts +10 -0
- package/cli/LogReporter.js +43 -0
- package/cli/LogReporter.js.map +1 -0
- package/cli/LogStream.d.ts +10 -0
- package/cli/LogStream.js +58 -0
- package/cli/LogStream.js.map +1 -0
- package/cli/MigrationRunReporter.d.ts +4 -0
- package/cli/MigrationRunReporter.js +7 -0
- package/cli/MigrationRunReporter.js.map +1 -0
- package/cli/MigrationRunner.d.ts +45 -0
- package/cli/MigrationRunner.js +136 -0
- package/cli/MigrationRunner.js.map +1 -0
- package/cli/MigrationStatusReporter.d.ts +4 -0
- package/cli/MigrationStatusReporter.js +7 -0
- package/cli/MigrationStatusReporter.js.map +1 -0
- package/cli/NonInteractiveCliStatusReporter.d.ts +9 -0
- package/cli/NonInteractiveCliStatusReporter.js +42 -0
- package/cli/NonInteractiveCliStatusReporter.js.map +1 -0
- package/cli/VoidStatusReporter.d.ts +4 -0
- package/cli/VoidStatusReporter.js +14 -0
- package/cli/VoidStatusReporter.js.map +1 -0
- package/cli/getDuration.d.ts +5 -0
- package/cli/getDuration.js +23 -0
- package/cli/getDuration.js.map +1 -0
- package/cli/index.d.ts +10 -0
- package/cli/index.js +117 -0
- package/cli/index.js.map +1 -0
- package/createPinoLogger.d.ts +4 -0
- package/createPinoLogger.js +26 -0
- package/createPinoLogger.js.map +1 -0
- package/createTable.d.ts +7 -0
- package/createTable.js +33 -0
- package/createTable.js.map +1 -0
- package/handlers/createDdbEsProjectMigration.d.ts +16 -0
- package/handlers/createDdbEsProjectMigration.js +84 -0
- package/handlers/createDdbEsProjectMigration.js.map +1 -0
- package/handlers/createDdbProjectMigration.d.ts +13 -0
- package/handlers/createDdbProjectMigration.js +80 -0
- package/handlers/createDdbProjectMigration.js.map +1 -0
- package/handlers/createPatternMatcher.d.ts +2 -0
- package/handlers/createPatternMatcher.js +19 -0
- package/handlers/createPatternMatcher.js.map +1 -0
- package/handlers/devVersionErrorResponse.d.ts +5 -0
- package/handlers/devVersionErrorResponse.js +16 -0
- package/handlers/devVersionErrorResponse.js.map +1 -0
- package/index.d.ts +6 -0
- package/index.js +62 -0
- package/index.js.map +1 -0
- package/package.json +47 -0
- package/repository/createStandardEntity.d.ts +52 -0
- package/repository/createStandardEntity.js +39 -0
- package/repository/createStandardEntity.js.map +1 -0
- package/repository/migrations.repository.d.ts +17 -0
- package/repository/migrations.repository.js +121 -0
- package/repository/migrations.repository.js.map +1 -0
- package/symbols.d.ts +7 -0
- package/symbols.js +15 -0
- package/symbols.js.map +1 -0
- package/types.d.ts +83 -0
- package/types.js +7 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MigrationRepositoryImpl = void 0;
|
|
7
|
+
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
8
|
+
var _ioc = require("@webiny/ioc");
|
|
9
|
+
var _symbols = require("../symbols");
|
|
10
|
+
var _createStandardEntity = require("./createStandardEntity");
|
|
11
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
12
|
+
class MigrationRepositoryImpl {
|
|
13
|
+
constructor(table) {
|
|
14
|
+
this.run = (0, _createStandardEntity.createStandardEntity)({
|
|
15
|
+
table,
|
|
16
|
+
name: "MigrationRun"
|
|
17
|
+
});
|
|
18
|
+
this.migration = (0, _createStandardEntity.createStandardEntity)({
|
|
19
|
+
table,
|
|
20
|
+
name: "Migration"
|
|
21
|
+
});
|
|
22
|
+
this.checkpoint = (0, _createStandardEntity.createStandardEntity)({
|
|
23
|
+
table,
|
|
24
|
+
name: "MigrationCheckpoint"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async getLastRun() {
|
|
28
|
+
const result = await (0, _query.queryOne)({
|
|
29
|
+
entity: this.run,
|
|
30
|
+
partitionKey: "MIGRATION_RUNS",
|
|
31
|
+
options: {
|
|
32
|
+
index: "GSI1",
|
|
33
|
+
gt: " ",
|
|
34
|
+
reverse: true
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return result ? result.data : null;
|
|
38
|
+
}
|
|
39
|
+
async saveRun(run) {
|
|
40
|
+
await (0, _dbDynamodb.put)({
|
|
41
|
+
entity: this.run,
|
|
42
|
+
item: {
|
|
43
|
+
PK: `MIGRATION_RUN#${run.id}`,
|
|
44
|
+
SK: "A",
|
|
45
|
+
TYPE: "migration.run",
|
|
46
|
+
GSI1_PK: "MIGRATION_RUNS",
|
|
47
|
+
GSI1_SK: run.id,
|
|
48
|
+
data: run
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async listMigrations(params) {
|
|
53
|
+
const {
|
|
54
|
+
limit
|
|
55
|
+
} = params || {};
|
|
56
|
+
const result = await (0, _query.queryAll)({
|
|
57
|
+
entity: this.migration,
|
|
58
|
+
partitionKey: "MIGRATIONS",
|
|
59
|
+
options: {
|
|
60
|
+
index: "GSI1",
|
|
61
|
+
gt: " ",
|
|
62
|
+
limit,
|
|
63
|
+
// Sort by GSI1_SK in descending order.
|
|
64
|
+
reverse: true
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return result.map(item => item.data);
|
|
68
|
+
}
|
|
69
|
+
async logMigration(migration) {
|
|
70
|
+
await (0, _dbDynamodb.put)({
|
|
71
|
+
entity: this.migration,
|
|
72
|
+
item: {
|
|
73
|
+
PK: `MIGRATION#${migration.id}`,
|
|
74
|
+
SK: "A",
|
|
75
|
+
TYPE: "migration",
|
|
76
|
+
GSI1_PK: "MIGRATIONS",
|
|
77
|
+
GSI1_SK: migration.id,
|
|
78
|
+
data: migration
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async createCheckpoint(id, data) {
|
|
83
|
+
await (0, _dbDynamodb.put)({
|
|
84
|
+
entity: this.checkpoint,
|
|
85
|
+
item: {
|
|
86
|
+
PK: `MIGRATION_CHECKPOINT#${id}`,
|
|
87
|
+
SK: "A",
|
|
88
|
+
TYPE: "migration.checkpoint",
|
|
89
|
+
GSI1_PK: "MIGRATION_CHECKPOINTS",
|
|
90
|
+
GSI1_SK: id,
|
|
91
|
+
data
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async deleteCheckpoint(id) {
|
|
96
|
+
await (0, _dbDynamodb.deleteItem)({
|
|
97
|
+
entity: this.checkpoint,
|
|
98
|
+
keys: {
|
|
99
|
+
PK: `MIGRATION_CHECKPOINT#${id}`,
|
|
100
|
+
SK: "A"
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
async getCheckpoint(id) {
|
|
105
|
+
const record = await (0, _dbDynamodb.get)({
|
|
106
|
+
entity: this.checkpoint,
|
|
107
|
+
keys: {
|
|
108
|
+
PK: `MIGRATION_CHECKPOINT#${id}`,
|
|
109
|
+
SK: "A"
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
if (!record) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return record.data;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.MigrationRepositoryImpl = MigrationRepositoryImpl;
|
|
119
|
+
(0, _ioc.makeInjectable)(MigrationRepositoryImpl, [(0, _ioc.inject)(_symbols.PrimaryDynamoTableSymbol)]);
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=migrations.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_query","require","_ioc","_symbols","_createStandardEntity","_dbDynamodb","MigrationRepositoryImpl","constructor","table","run","createStandardEntity","name","migration","checkpoint","getLastRun","result","queryOne","entity","partitionKey","options","index","gt","reverse","data","saveRun","put","item","PK","id","SK","TYPE","GSI1_PK","GSI1_SK","listMigrations","params","limit","queryAll","map","logMigration","createCheckpoint","deleteCheckpoint","deleteItem","keys","getCheckpoint","record","get","exports","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["migrations.repository.ts"],"sourcesContent":["import type { Entity, Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { queryAll, queryOne } from \"@webiny/db-dynamodb/utils/query\";\nimport type { MigrationItem, MigrationRepository, MigrationRun } from \"~/types\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { PrimaryDynamoTableSymbol } from \"~/symbols\";\nimport { createStandardEntity } from \"./createStandardEntity\";\nimport { deleteItem, get, put } from \"@webiny/db-dynamodb\";\n\ninterface MigrationCheckpoint {\n data: unknown;\n}\n\nexport class MigrationRepositoryImpl implements MigrationRepository {\n private readonly run: Entity<any>;\n private readonly migration: Entity<any>;\n private readonly checkpoint: Entity<any>;\n\n constructor(table: Table<string, string, string>) {\n this.run = createStandardEntity({ table, name: \"MigrationRun\" });\n this.migration = createStandardEntity({ table, name: \"Migration\" });\n this.checkpoint = createStandardEntity({ table, name: \"MigrationCheckpoint\" });\n }\n\n async getLastRun(): Promise<MigrationRun | null> {\n const result = await queryOne<{ data: MigrationRun }>({\n entity: this.run,\n partitionKey: \"MIGRATION_RUNS\",\n options: {\n index: \"GSI1\",\n gt: \" \",\n reverse: true\n }\n });\n\n return result ? result.data : null;\n }\n\n async saveRun(run: MigrationRun): Promise<void> {\n await put({\n entity: this.run,\n item: {\n PK: `MIGRATION_RUN#${run.id}`,\n SK: \"A\",\n TYPE: \"migration.run\",\n GSI1_PK: \"MIGRATION_RUNS\",\n GSI1_SK: run.id,\n data: run\n }\n });\n }\n\n async listMigrations(params?: { limit: number }): Promise<MigrationItem[]> {\n const { limit } = params || {};\n const result = await queryAll<{ data: MigrationItem }>({\n entity: this.migration,\n partitionKey: \"MIGRATIONS\",\n options: {\n index: \"GSI1\",\n gt: \" \",\n limit,\n // Sort by GSI1_SK in descending order.\n reverse: true\n }\n });\n\n return result.map(item => item.data);\n }\n\n async logMigration(migration: MigrationItem): Promise<void> {\n await put({\n entity: this.migration,\n item: {\n PK: `MIGRATION#${migration.id}`,\n SK: \"A\",\n TYPE: \"migration\",\n GSI1_PK: \"MIGRATIONS\",\n GSI1_SK: migration.id,\n data: migration\n }\n });\n }\n\n async createCheckpoint(id: string, data: unknown): Promise<void> {\n await put({\n entity: this.checkpoint,\n item: {\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\",\n TYPE: \"migration.checkpoint\",\n GSI1_PK: \"MIGRATION_CHECKPOINTS\",\n GSI1_SK: id,\n data\n }\n });\n }\n\n async deleteCheckpoint(id: string): Promise<void> {\n await deleteItem({\n entity: this.checkpoint,\n keys: {\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\"\n }\n });\n }\n\n async getCheckpoint(id: string): Promise<unknown | null> {\n const record = await get<MigrationCheckpoint>({\n entity: this.checkpoint,\n keys: {\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\"\n }\n });\n\n if (!record) {\n return null;\n }\n return record.data;\n }\n}\n\nmakeInjectable(MigrationRepositoryImpl, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAMO,MAAMK,uBAAuB,CAAgC;EAKhEC,WA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AI,CAACJ,UAAU;MACvB6B,IAAI,EAAE;QACFf,EAAE,EAAE,wBAAwBC,EAAE,EAAE;QAChCC,EAAE,EAAE;MACR;IACJ,CAAC,CAAC;IAEF,IAAI,CAACe,MAAM,EAAE;MACT,OAAO,IAAI;IACf;IACA,OAAOA,MAAM,CAACrB,IAAI;EACtB;AACJ;AAACuB,OAAA,CAAAxC,uBAAA,GAAAA,uBAAA;AAED,IAAAyC,mBAAc,EAACzC,uBAAuB,EAAE,CAAC,IAAA0C,WAAM,EAACC,iCAAwB,CAAC,CAAC,CAAC","ignoreList":[]}
|
package/symbols.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const LoggerSymbol: unique symbol;
|
|
2
|
+
export declare const MigrationSymbol: unique symbol;
|
|
3
|
+
export declare const MigrationRepositorySymbol: unique symbol;
|
|
4
|
+
export declare const ElasticsearchClientSymbol: unique symbol;
|
|
5
|
+
export declare const PrimaryDynamoTableSymbol: unique symbol;
|
|
6
|
+
export declare const ElasticsearchDynamoTableSymbol: unique symbol;
|
|
7
|
+
export declare const ExecutionTimeLimiterSymbol: unique symbol;
|
package/symbols.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PrimaryDynamoTableSymbol = exports.MigrationSymbol = exports.MigrationRepositorySymbol = exports.LoggerSymbol = exports.ExecutionTimeLimiterSymbol = exports.ElasticsearchDynamoTableSymbol = exports.ElasticsearchClientSymbol = void 0;
|
|
7
|
+
const LoggerSymbol = exports.LoggerSymbol = Symbol.for("PinoLogger");
|
|
8
|
+
const MigrationSymbol = exports.MigrationSymbol = Symbol.for("Migration");
|
|
9
|
+
const MigrationRepositorySymbol = exports.MigrationRepositorySymbol = Symbol.for("MigrationRepository");
|
|
10
|
+
const ElasticsearchClientSymbol = exports.ElasticsearchClientSymbol = Symbol.for("ElasticsearchClient");
|
|
11
|
+
const PrimaryDynamoTableSymbol = exports.PrimaryDynamoTableSymbol = Symbol.for("PrimaryDynamoTable");
|
|
12
|
+
const ElasticsearchDynamoTableSymbol = exports.ElasticsearchDynamoTableSymbol = Symbol.for("ElasticsearchDynamoTable");
|
|
13
|
+
const ExecutionTimeLimiterSymbol = exports.ExecutionTimeLimiterSymbol = Symbol.for("ExecutionTimeLimiter");
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=symbols.js.map
|
package/symbols.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LoggerSymbol","exports","Symbol","for","MigrationSymbol","MigrationRepositorySymbol","ElasticsearchClientSymbol","PrimaryDynamoTableSymbol","ElasticsearchDynamoTableSymbol","ExecutionTimeLimiterSymbol"],"sources":["symbols.ts"],"sourcesContent":["export const LoggerSymbol = Symbol.for(\"PinoLogger\");\nexport const MigrationSymbol = Symbol.for(\"Migration\");\nexport const MigrationRepositorySymbol = Symbol.for(\"MigrationRepository\");\nexport const ElasticsearchClientSymbol = Symbol.for(\"ElasticsearchClient\");\nexport const PrimaryDynamoTableSymbol = Symbol.for(\"PrimaryDynamoTable\");\nexport const ElasticsearchDynamoTableSymbol = Symbol.for(\"ElasticsearchDynamoTable\");\nexport const ExecutionTimeLimiterSymbol = Symbol.for(\"ExecutionTimeLimiter\");\n"],"mappings":";;;;;;AAAO,MAAMA,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAGE,MAAM,CAACC,GAAG,CAAC,YAAY,CAAC;AAC7C,MAAMC,eAAe,GAAAH,OAAA,CAAAG,eAAA,GAAGF,MAAM,CAACC,GAAG,CAAC,WAAW,CAAC;AAC/C,MAAME,yBAAyB,GAAAJ,OAAA,CAAAI,yBAAA,GAAGH,MAAM,CAACC,GAAG,CAAC,qBAAqB,CAAC;AACnE,MAAMG,yBAAyB,GAAAL,OAAA,CAAAK,yBAAA,GAAGJ,MAAM,CAACC,GAAG,CAAC,qBAAqB,CAAC;AACnE,MAAMI,wBAAwB,GAAAN,OAAA,CAAAM,wBAAA,GAAGL,MAAM,CAACC,GAAG,CAAC,oBAAoB,CAAC;AACjE,MAAMK,8BAA8B,GAAAP,OAAA,CAAAO,8BAAA,GAAGN,MAAM,CAACC,GAAG,CAAC,0BAA0B,CAAC;AAC7E,MAAMM,0BAA0B,GAAAR,OAAA,CAAAQ,0BAAA,GAAGP,MAAM,CAACC,GAAG,CAAC,sBAAsB,CAAC","ignoreList":[]}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Logger } from "@webiny/logger";
|
|
2
|
+
export type { Logger };
|
|
3
|
+
export interface MigrationItem {
|
|
4
|
+
id: string;
|
|
5
|
+
description: string;
|
|
6
|
+
reason: string;
|
|
7
|
+
startedOn?: string;
|
|
8
|
+
finishedOn?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface MigrationRun {
|
|
11
|
+
id: string;
|
|
12
|
+
startedOn: string;
|
|
13
|
+
finishedOn: string;
|
|
14
|
+
status: "init" | "running" | "pending" | "done" | "error";
|
|
15
|
+
migrations: MigrationRunItem[];
|
|
16
|
+
context?: Record<string, any>;
|
|
17
|
+
error?: {
|
|
18
|
+
message: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
code?: string;
|
|
21
|
+
data?: Record<string, any>;
|
|
22
|
+
stack?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface MigrationRunItem {
|
|
26
|
+
id: string;
|
|
27
|
+
status: "done" | "running" | "skipped" | "pending" | "not-applicable" | "error";
|
|
28
|
+
startedOn?: string;
|
|
29
|
+
finishedOn?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface MigrationRepository {
|
|
32
|
+
getLastRun(): Promise<MigrationRun | null>;
|
|
33
|
+
saveRun(run: MigrationRun): Promise<void>;
|
|
34
|
+
listMigrations(params?: {
|
|
35
|
+
limit: number;
|
|
36
|
+
}): Promise<MigrationItem[]>;
|
|
37
|
+
logMigration(migration: MigrationItem): Promise<void>;
|
|
38
|
+
createCheckpoint(id: string, data: unknown): Promise<void>;
|
|
39
|
+
getCheckpoint(id: string): Promise<unknown>;
|
|
40
|
+
deleteCheckpoint(id: string): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export interface DataMigrationContext<TCheckpoint = any> {
|
|
43
|
+
projectVersion: string;
|
|
44
|
+
logger: Logger;
|
|
45
|
+
checkpoint?: TCheckpoint;
|
|
46
|
+
forceExecute: boolean;
|
|
47
|
+
runningOutOfTime: () => boolean;
|
|
48
|
+
createCheckpoint: (data: TCheckpoint) => Promise<void>;
|
|
49
|
+
createCheckpointAndExit: (data: TCheckpoint) => Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export interface DataMigration<TCheckpoint = any> {
|
|
52
|
+
getId(): string;
|
|
53
|
+
getDescription(): string;
|
|
54
|
+
shouldExecute(context: DataMigrationContext<TCheckpoint>): Promise<boolean>;
|
|
55
|
+
execute(context: DataMigrationContext<TCheckpoint>): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Migration execution time limiter (in milliseconds).
|
|
59
|
+
*/
|
|
60
|
+
export type ExecutionTimeLimiter = () => number;
|
|
61
|
+
export interface MigrationEventPayload {
|
|
62
|
+
command: "status" | "execute";
|
|
63
|
+
version?: string;
|
|
64
|
+
pattern?: string;
|
|
65
|
+
force?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export type MigrationEventHandlerResponse = undefined | MigrationStatusResponse | MigrationInvocationErrorResponse;
|
|
68
|
+
export interface MigrationInvocationErrorResponse {
|
|
69
|
+
error: {
|
|
70
|
+
message: string;
|
|
71
|
+
};
|
|
72
|
+
data?: undefined;
|
|
73
|
+
}
|
|
74
|
+
export interface MigrationStatusRunItem extends MigrationRunItem {
|
|
75
|
+
description: string;
|
|
76
|
+
}
|
|
77
|
+
export interface MigrationStatus extends MigrationRun {
|
|
78
|
+
migrations: MigrationStatusRunItem[];
|
|
79
|
+
}
|
|
80
|
+
export interface MigrationStatusResponse {
|
|
81
|
+
data: MigrationStatus;
|
|
82
|
+
error?: undefined;
|
|
83
|
+
}
|
package/types.js
ADDED
package/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { Logger } from \"@webiny/logger\";\n\nexport type { Logger };\n\nexport interface MigrationItem {\n id: string;\n description: string;\n reason: string;\n startedOn?: string;\n finishedOn?: string;\n}\n\nexport interface MigrationRun {\n id: string;\n startedOn: string;\n finishedOn: string;\n status: \"init\" | \"running\" | \"pending\" | \"done\" | \"error\";\n migrations: MigrationRunItem[];\n context?: Record<string, any>;\n error?: {\n message: string;\n name?: string;\n code?: string;\n data?: Record<string, any>;\n stack?: string;\n };\n}\n\nexport interface MigrationRunItem {\n id: string;\n status: \"done\" | \"running\" | \"skipped\" | \"pending\" | \"not-applicable\" | \"error\";\n startedOn?: string;\n finishedOn?: string;\n}\n\nexport interface MigrationRepository {\n getLastRun(): Promise<MigrationRun | null>;\n saveRun(run: MigrationRun): Promise<void>;\n listMigrations(params?: { limit: number }): Promise<MigrationItem[]>;\n logMigration(migration: MigrationItem): Promise<void>;\n createCheckpoint(id: string, data: unknown): Promise<void>;\n getCheckpoint(id: string): Promise<unknown>;\n deleteCheckpoint(id: string): Promise<void>;\n}\n\nexport interface DataMigrationContext<TCheckpoint = any> {\n projectVersion: string;\n logger: Logger;\n checkpoint?: TCheckpoint;\n forceExecute: boolean;\n runningOutOfTime: () => boolean;\n createCheckpoint: (data: TCheckpoint) => Promise<void>;\n createCheckpointAndExit: (data: TCheckpoint) => Promise<void>;\n}\n\nexport interface DataMigration<TCheckpoint = any> {\n getId(): string;\n getDescription(): string;\n // This function should check of the migration needs to apply some changes to the system.\n // Returning `false` means \"everything is ok, mark this migration as executed\".\n shouldExecute(context: DataMigrationContext<TCheckpoint>): Promise<boolean>;\n execute(context: DataMigrationContext<TCheckpoint>): Promise<void>;\n}\n\n/**\n * Migration execution time limiter (in milliseconds).\n */\nexport type ExecutionTimeLimiter = () => number;\n\nexport interface MigrationEventPayload {\n command: \"status\" | \"execute\";\n version?: string;\n pattern?: string;\n force?: boolean;\n}\n\nexport type MigrationEventHandlerResponse =\n // When migration is triggered (via `Event` invocation type), it simply gets invoked, and returns nothing.\n | undefined\n // Last migration run state.\n | MigrationStatusResponse\n // If an unhandled error is thrown, return the error object.\n | MigrationInvocationErrorResponse;\n\nexport interface MigrationInvocationErrorResponse {\n error: { message: string };\n data?: undefined;\n}\n\nexport interface MigrationStatusRunItem extends MigrationRunItem {\n description: string;\n}\n\nexport interface MigrationStatus extends MigrationRun {\n migrations: MigrationStatusRunItem[];\n}\n\nexport interface MigrationStatusResponse {\n data: MigrationStatus;\n error?: undefined;\n}\n"],"mappings":"","ignoreList":[]}
|