@webiny/data-migration 0.0.0-unstable.496cf268ac → 0.0.0-unstable.61c048f412
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/MigrationRunner.d.ts +8 -4
- package/MigrationRunner.js +109 -51
- package/MigrationRunner.js.map +1 -1
- package/README.md +9 -4
- package/cli/CliMigrationRunReporter.d.ts +13 -0
- package/cli/CliMigrationRunReporter.js +50 -0
- package/cli/CliMigrationRunReporter.js.map +1 -0
- package/cli/InteractiveCliStatusReporter.d.ts +11 -0
- package/cli/InteractiveCliStatusReporter.js +66 -0
- package/cli/InteractiveCliStatusReporter.js.map +1 -0
- package/cli/LogReporter.d.ts +10 -0
- package/cli/LogReporter.js +36 -0
- package/cli/LogReporter.js.map +1 -0
- package/cli/LogStream.d.ts +10 -0
- package/cli/LogStream.js +51 -0
- package/cli/LogStream.js.map +1 -0
- package/cli/MigrationRunReporter.d.ts +4 -0
- package/cli/MigrationRunReporter.js +3 -0
- package/cli/MigrationRunReporter.js.map +1 -0
- package/cli/MigrationRunner.d.ts +45 -0
- package/cli/MigrationRunner.js +128 -0
- package/cli/MigrationRunner.js.map +1 -0
- package/cli/MigrationStatusReporter.d.ts +4 -0
- package/cli/MigrationStatusReporter.js +3 -0
- package/cli/MigrationStatusReporter.js.map +1 -0
- package/cli/NonInteractiveCliStatusReporter.d.ts +9 -0
- package/cli/NonInteractiveCliStatusReporter.js +35 -0
- package/cli/NonInteractiveCliStatusReporter.js.map +1 -0
- package/cli/VoidStatusReporter.d.ts +4 -0
- package/cli/VoidStatusReporter.js +7 -0
- package/cli/VoidStatusReporter.js.map +1 -0
- package/cli/getDuration.js +3 -8
- package/cli/getDuration.js.map +1 -1
- package/cli/index.d.ts +10 -3
- package/cli/index.js +11 -37
- package/cli/index.js.map +1 -1
- package/createPinoLogger.d.ts +4 -7
- package/createPinoLogger.js +11 -16
- package/createPinoLogger.js.map +1 -1
- package/createTable.d.ts +4 -4
- package/createTable.js +8 -11
- package/createTable.js.map +1 -1
- package/handlers/createDdbEsProjectMigration.d.ts +7 -7
- package/handlers/createDdbEsProjectMigration.js +41 -43
- package/handlers/createDdbEsProjectMigration.js.map +1 -1
- package/handlers/createDdbProjectMigration.d.ts +5 -5
- package/handlers/createDdbProjectMigration.js +37 -39
- package/handlers/createDdbProjectMigration.js.map +1 -1
- package/handlers/createPatternMatcher.d.ts +1 -1
- package/handlers/createPatternMatcher.js +5 -11
- package/handlers/createPatternMatcher.js.map +1 -1
- package/handlers/devVersionErrorResponse.js +3 -8
- package/handlers/devVersionErrorResponse.js.map +1 -1
- package/index.d.ts +6 -7
- package/index.js +7 -70
- package/index.js.map +1 -1
- package/package.json +20 -37
- package/repository/migrations.repository.d.ts +3 -3
- package/repository/migrations.repository.js +18 -31
- package/repository/migrations.repository.js.map +1 -1
- package/symbols.js +8 -19
- package/symbols.js.map +1 -1
- package/types.d.ts +9 -6
- package/types.js +2 -11
- package/types.js.map +1 -1
- package/cli/getMigrationStatus.d.ts +0 -9
- package/cli/getMigrationStatus.js +0 -23
- package/cli/getMigrationStatus.js.map +0 -1
- package/cli/printReport.d.ts +0 -9
- package/cli/printReport.js +0 -57
- package/cli/printReport.js.map +0 -1
- package/cli/runMigration.d.ts +0 -13
- package/cli/runMigration.js +0 -85
- package/cli/runMigration.js.map +0 -1
- package/createId.d.ts +0 -1
- package/createId.js +0 -14
- package/createId.js.map +0 -1
- package/repository/createStandardEntity.d.ts +0 -5
- package/repository/createStandardEntity.js +0 -37
- package/repository/createStandardEntity.js.map +0 -1
|
@@ -1,36 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.MigrationRepositoryImpl = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
10
|
-
var _ioc = require("@webiny/ioc");
|
|
11
|
-
var _symbols = require("../symbols");
|
|
12
|
-
var _createStandardEntity = require("./createStandardEntity");
|
|
13
|
-
class MigrationRepositoryImpl {
|
|
1
|
+
import { inject, makeInjectable } from "@webiny/ioc";
|
|
2
|
+
import { PrimaryDynamoTableSymbol } from "../symbols.js";
|
|
3
|
+
import { createGlobalEntity } from "@webiny/db-dynamodb";
|
|
4
|
+
export class MigrationRepositoryImpl {
|
|
14
5
|
constructor(table) {
|
|
15
|
-
|
|
16
|
-
(0, _defineProperty2.default)(this, "migration", void 0);
|
|
17
|
-
(0, _defineProperty2.default)(this, "checkpoint", void 0);
|
|
18
|
-
this.run = (0, _createStandardEntity.createStandardEntity)({
|
|
6
|
+
this.run = createGlobalEntity({
|
|
19
7
|
table,
|
|
20
8
|
name: "MigrationRun"
|
|
21
9
|
});
|
|
22
|
-
this.migration = (
|
|
10
|
+
this.migration = createGlobalEntity({
|
|
23
11
|
table,
|
|
24
12
|
name: "Migration"
|
|
25
13
|
});
|
|
26
|
-
this.checkpoint = (
|
|
14
|
+
this.checkpoint = createGlobalEntity({
|
|
27
15
|
table,
|
|
28
16
|
name: "MigrationCheckpoint"
|
|
29
17
|
});
|
|
30
18
|
}
|
|
31
19
|
async getLastRun() {
|
|
32
|
-
const result = await
|
|
33
|
-
entity: this.run,
|
|
20
|
+
const result = await this.run.queryOne({
|
|
34
21
|
partitionKey: "MIGRATION_RUNS",
|
|
35
22
|
options: {
|
|
36
23
|
index: "GSI1",
|
|
@@ -38,7 +25,7 @@ class MigrationRepositoryImpl {
|
|
|
38
25
|
reverse: true
|
|
39
26
|
}
|
|
40
27
|
});
|
|
41
|
-
return result
|
|
28
|
+
return result?.data || null;
|
|
42
29
|
}
|
|
43
30
|
async saveRun(run) {
|
|
44
31
|
await this.run.put({
|
|
@@ -54,8 +41,7 @@ class MigrationRepositoryImpl {
|
|
|
54
41
|
const {
|
|
55
42
|
limit
|
|
56
43
|
} = params || {};
|
|
57
|
-
const result = await
|
|
58
|
-
entity: this.migration,
|
|
44
|
+
const result = await this.migration.queryAll({
|
|
59
45
|
partitionKey: "MIGRATIONS",
|
|
60
46
|
options: {
|
|
61
47
|
index: "GSI1",
|
|
@@ -84,11 +70,11 @@ class MigrationRepositoryImpl {
|
|
|
84
70
|
TYPE: "migration.checkpoint",
|
|
85
71
|
GSI1_PK: "MIGRATION_CHECKPOINTS",
|
|
86
72
|
GSI1_SK: id,
|
|
87
|
-
data
|
|
73
|
+
data: data
|
|
88
74
|
});
|
|
89
75
|
}
|
|
90
|
-
deleteCheckpoint(id) {
|
|
91
|
-
|
|
76
|
+
async deleteCheckpoint(id) {
|
|
77
|
+
await this.checkpoint.delete({
|
|
92
78
|
PK: `MIGRATION_CHECKPOINT#${id}`,
|
|
93
79
|
SK: "A"
|
|
94
80
|
});
|
|
@@ -98,11 +84,12 @@ class MigrationRepositoryImpl {
|
|
|
98
84
|
PK: `MIGRATION_CHECKPOINT#${id}`,
|
|
99
85
|
SK: "A"
|
|
100
86
|
});
|
|
101
|
-
if (!record
|
|
87
|
+
if (!record) {
|
|
102
88
|
return null;
|
|
103
89
|
}
|
|
104
|
-
return record.
|
|
90
|
+
return record.data;
|
|
105
91
|
}
|
|
106
92
|
}
|
|
107
|
-
|
|
108
|
-
|
|
93
|
+
makeInjectable(MigrationRepositoryImpl, [inject(PrimaryDynamoTableSymbol)]);
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=migrations.repository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["MigrationRepositoryImpl","constructor","table","run","
|
|
1
|
+
{"version":3,"names":["inject","makeInjectable","PrimaryDynamoTableSymbol","createGlobalEntity","MigrationRepositoryImpl","constructor","table","run","name","migration","checkpoint","getLastRun","result","queryOne","partitionKey","options","index","gt","reverse","data","saveRun","put","PK","id","SK","TYPE","GSI1_PK","GSI1_SK","listMigrations","params","limit","queryAll","map","item","logMigration","createCheckpoint","deleteCheckpoint","delete","getCheckpoint","record","get"],"sources":["migrations.repository.ts"],"sourcesContent":["import type { Table } from \"@webiny/db-dynamodb/toolbox.js\";\nimport type { MigrationItem, MigrationRepository, MigrationRun } from \"~/types.js\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { PrimaryDynamoTableSymbol } from \"~/symbols.js\";\nimport { createGlobalEntity } from \"@webiny/db-dynamodb\";\n\ninterface MigrationCheckpoint {\n data: unknown;\n}\n\nexport class MigrationRepositoryImpl implements MigrationRepository {\n private readonly run;\n private readonly migration;\n private readonly checkpoint;\n\n constructor(table: Table<string, string, string>) {\n this.run = createGlobalEntity<MigrationRun>({\n table,\n name: \"MigrationRun\"\n });\n this.migration = createGlobalEntity<MigrationItem>({\n table,\n name: \"Migration\"\n });\n this.checkpoint = createGlobalEntity<MigrationCheckpoint>({\n table,\n name: \"MigrationCheckpoint\"\n });\n }\n\n async getLastRun(): Promise<MigrationRun | null> {\n const result = await this.run.queryOne({\n partitionKey: \"MIGRATION_RUNS\",\n options: {\n index: \"GSI1\",\n gt: \" \",\n reverse: true\n }\n });\n\n return result?.data || null;\n }\n\n async saveRun(run: MigrationRun): Promise<void> {\n await this.run.put({\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 async listMigrations(params?: { limit: number }): Promise<MigrationItem[]> {\n const { limit } = params || {};\n const result = await this.migration.queryAll({\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 this.migration.put({\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 async createCheckpoint(id: string, data: unknown): Promise<void> {\n await this.checkpoint.put({\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\",\n TYPE: \"migration.checkpoint\",\n GSI1_PK: \"MIGRATION_CHECKPOINTS\",\n GSI1_SK: id,\n data: data as MigrationCheckpoint\n });\n }\n\n async deleteCheckpoint(id: string): Promise<void> {\n await this.checkpoint.delete({\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\"\n });\n }\n\n async getCheckpoint(id: string): Promise<unknown | null> {\n const record = await this.checkpoint.get({\n PK: `MIGRATION_CHECKPOINT#${id}`,\n SK: \"A\"\n });\n\n if (!record) {\n return null;\n }\n return record.data;\n }\n}\n\nmakeInjectable(MigrationRepositoryImpl, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":"AAEA,SAASA,MAAM,EAAEC,cAAc,QAAQ,aAAa;AACpD,SAASC,wBAAwB;AACjC,SAASC,kBAAkB,QAAQ,qBAAqB;AAMxD,OAAO,MAAMC,uBAAuB,CAAgC;EAKhEC,WAAWA,CAACC,KAAoC,EAAE;IAC9C,IAAI,CAACC,GAAG,GAAGJ,kBAAkB,CAAe;MACxCG,KAAK;MACLE,IAAI,EAAE;IACV,CAAC,CAAC;IACF,IAAI,CAACC,SAAS,GAAGN,kBAAkB,CAAgB;MAC/CG,KAAK;MACLE,IAAI,EAAE;IACV,CAAC,CAAC;IACF,IAAI,CAACE,UAAU,GAAGP,kBAAkB,CAAsB;MACtDG,KAAK;MACLE,IAAI,EAAE;IACV,CAAC,CAAC;EACN;EAEA,MAAMG,UAAUA,CAAA,EAAiC;IAC7C,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACL,GAAG,CAACM,QAAQ,CAAC;MACnCC,YAAY,EAAE,gBAAgB;MAC9BC,OAAO,EAAE;QACLC,KAAK,EAAE,MAAM;QACbC,EAAE,EAAE,GAAG;QACPC,OAAO,EAAE;MACb;IACJ,CAAC,CAAC;IAEF,OAAON,MAAM,EAAEO,IAAI,IAAI,IAAI;EAC/B;EAEA,MAAMC,OAAOA,CAACb,GAAiB,EAAiB;IAC5C,MAAM,IAAI,CAACA,GAAG,CAACc,GAAG,CAAC;MACfC,EAAE,EAAE,iBAAiBf,GAAG,CAACgB,EAAE,EAAE;MAC7BC,EAAE,EAAE,GAAG;MACPC,IAAI,EAAE,eAAe;MACrBC,OAAO,EAAE,gBAAgB;MACzBC,OAAO,EAAEpB,GAAG,CAACgB,EAAE;MACfJ,IAAI,EAAEZ;IACV,CAAC,CAAC;EACN;EAEA,MAAMqB,cAAcA,CAACC,MAA0B,EAA4B;IACvE,MAAM;MAAEC;IAAM,CAAC,GAAGD,MAAM,IAAI,CAAC,CAAC;IAC9B,MAAMjB,MAAM,GAAG,MAAM,IAAI,CAACH,SAAS,CAACsB,QAAQ,CAAC;MACzCjB,YAAY,EAAE,YAAY;MAC1BC,OAAO,EAAE;QACLC,KAAK,EAAE,MAAM;QACbC,EAAE,EAAE,GAAG;QACPa,KAAK;QACL;QACAZ,OAAO,EAAE;MACb;IACJ,CAAC,CAAC;IAEF,OAAON,MAAM,CAACoB,GAAG,CAACC,IAAI,IAAIA,IAAI,CAACd,IAAI,CAAC;EACxC;EAEA,MAAMe,YAAYA,CAACzB,SAAwB,EAAiB;IACxD,MAAM,IAAI,CAACA,SAAS,CAACY,GAAG,CAAC;MACrBC,EAAE,EAAE,aAAab,SAAS,CAACc,EAAE,EAAE;MAC/BC,EAAE,EAAE,GAAG;MACPC,IAAI,EAAE,WAAW;MACjBC,OAAO,EAAE,YAAY;MACrBC,OAAO,EAAElB,SAAS,CAACc,EAAE;MACrBJ,IAAI,EAAEV;IACV,CAAC,CAAC;EACN;EAEA,MAAM0B,gBAAgBA,CAACZ,EAAU,EAAEJ,IAAa,EAAiB;IAC7D,MAAM,IAAI,CAACT,UAAU,CAACW,GAAG,CAAC;MACtBC,EAAE,EAAE,wBAAwBC,EAAE,EAAE;MAChCC,EAAE,EAAE,GAAG;MACPC,IAAI,EAAE,sBAAsB;MAC5BC,OAAO,EAAE,uBAAuB;MAChCC,OAAO,EAAEJ,EAAE;MACXJ,IAAI,EAAEA;IACV,CAAC,CAAC;EACN;EAEA,MAAMiB,gBAAgBA,CAACb,EAAU,EAAiB;IAC9C,MAAM,IAAI,CAACb,UAAU,CAAC2B,MAAM,CAAC;MACzBf,EAAE,EAAE,wBAAwBC,EAAE,EAAE;MAChCC,EAAE,EAAE;IACR,CAAC,CAAC;EACN;EAEA,MAAMc,aAAaA,CAACf,EAAU,EAA2B;IACrD,MAAMgB,MAAM,GAAG,MAAM,IAAI,CAAC7B,UAAU,CAAC8B,GAAG,CAAC;MACrClB,EAAE,EAAE,wBAAwBC,EAAE,EAAE;MAChCC,EAAE,EAAE;IACR,CAAC,CAAC;IAEF,IAAI,CAACe,MAAM,EAAE;MACT,OAAO,IAAI;IACf;IACA,OAAOA,MAAM,CAACpB,IAAI;EACtB;AACJ;AAEAlB,cAAc,CAACG,uBAAuB,EAAE,CAACJ,MAAM,CAACE,wBAAwB,CAAC,CAAC,CAAC","ignoreList":[]}
|
package/symbols.js
CHANGED
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
export const LoggerSymbol = Symbol.for("PinoLogger");
|
|
2
|
+
export const MigrationSymbol = Symbol.for("Migration");
|
|
3
|
+
export const MigrationRepositorySymbol = Symbol.for("MigrationRepository");
|
|
4
|
+
export const ElasticsearchClientSymbol = Symbol.for("ElasticsearchClient");
|
|
5
|
+
export const PrimaryDynamoTableSymbol = Symbol.for("PrimaryDynamoTable");
|
|
6
|
+
export const ElasticsearchDynamoTableSymbol = Symbol.for("ElasticsearchDynamoTable");
|
|
7
|
+
export const ExecutionTimeLimiterSymbol = Symbol.for("ExecutionTimeLimiter");
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PrimaryDynamoTableSymbol = exports.MigrationSymbol = exports.MigrationRepositorySymbol = exports.LoggerSymbol = exports.ExecutionTimeLimiterSymbol = exports.ElasticsearchDynamoTableSymbol = exports.ElasticsearchClientSymbol = void 0;
|
|
7
|
-
const LoggerSymbol = Symbol.for("PinoLogger");
|
|
8
|
-
exports.LoggerSymbol = LoggerSymbol;
|
|
9
|
-
const MigrationSymbol = Symbol.for("Migration");
|
|
10
|
-
exports.MigrationSymbol = MigrationSymbol;
|
|
11
|
-
const MigrationRepositorySymbol = Symbol.for("MigrationRepository");
|
|
12
|
-
exports.MigrationRepositorySymbol = MigrationRepositorySymbol;
|
|
13
|
-
const ElasticsearchClientSymbol = Symbol.for("ElasticsearchClient");
|
|
14
|
-
exports.ElasticsearchClientSymbol = ElasticsearchClientSymbol;
|
|
15
|
-
const PrimaryDynamoTableSymbol = Symbol.for("PrimaryDynamoTable");
|
|
16
|
-
exports.PrimaryDynamoTableSymbol = PrimaryDynamoTableSymbol;
|
|
17
|
-
const ElasticsearchDynamoTableSymbol = Symbol.for("ElasticsearchDynamoTable");
|
|
18
|
-
exports.ElasticsearchDynamoTableSymbol = ElasticsearchDynamoTableSymbol;
|
|
19
|
-
const ExecutionTimeLimiterSymbol = Symbol.for("ExecutionTimeLimiter");
|
|
20
|
-
exports.ExecutionTimeLimiterSymbol = ExecutionTimeLimiterSymbol;
|
|
9
|
+
//# sourceMappingURL=symbols.js.map
|
package/symbols.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["LoggerSymbol","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":"
|
|
1
|
+
{"version":3,"names":["LoggerSymbol","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":"AAAA,OAAO,MAAMA,YAAY,GAAGC,MAAM,CAACC,GAAG,CAAC,YAAY,CAAC;AACpD,OAAO,MAAMC,eAAe,GAAGF,MAAM,CAACC,GAAG,CAAC,WAAW,CAAC;AACtD,OAAO,MAAME,yBAAyB,GAAGH,MAAM,CAACC,GAAG,CAAC,qBAAqB,CAAC;AAC1E,OAAO,MAAMG,yBAAyB,GAAGJ,MAAM,CAACC,GAAG,CAAC,qBAAqB,CAAC;AAC1E,OAAO,MAAMI,wBAAwB,GAAGL,MAAM,CAACC,GAAG,CAAC,oBAAoB,CAAC;AACxE,OAAO,MAAMK,8BAA8B,GAAGN,MAAM,CAACC,GAAG,CAAC,0BAA0B,CAAC;AACpF,OAAO,MAAMM,0BAA0B,GAAGP,MAAM,CAACC,GAAG,CAAC,sBAAsB,CAAC","ignoreList":[]}
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Logger } from "
|
|
2
|
-
export { Logger };
|
|
1
|
+
import type { Logger } from "@webiny/logger";
|
|
2
|
+
export type { Logger };
|
|
3
3
|
export interface MigrationItem {
|
|
4
4
|
id: string;
|
|
5
5
|
description: string;
|
|
@@ -13,6 +13,7 @@ export interface MigrationRun {
|
|
|
13
13
|
finishedOn: string;
|
|
14
14
|
status: "init" | "running" | "pending" | "done" | "error";
|
|
15
15
|
migrations: MigrationRunItem[];
|
|
16
|
+
context?: Record<string, any>;
|
|
16
17
|
error?: {
|
|
17
18
|
message: string;
|
|
18
19
|
name?: string;
|
|
@@ -42,9 +43,10 @@ export interface DataMigrationContext<TCheckpoint = any> {
|
|
|
42
43
|
projectVersion: string;
|
|
43
44
|
logger: Logger;
|
|
44
45
|
checkpoint?: TCheckpoint;
|
|
46
|
+
forceExecute: boolean;
|
|
45
47
|
runningOutOfTime: () => boolean;
|
|
46
|
-
createCheckpoint: (data: TCheckpoint) => void
|
|
47
|
-
createCheckpointAndExit: (data: TCheckpoint) => void
|
|
48
|
+
createCheckpoint: (data: TCheckpoint) => Promise<void>;
|
|
49
|
+
createCheckpointAndExit: (data: TCheckpoint) => Promise<void>;
|
|
48
50
|
}
|
|
49
51
|
export interface DataMigration<TCheckpoint = any> {
|
|
50
52
|
getId(): string;
|
|
@@ -55,13 +57,14 @@ export interface DataMigration<TCheckpoint = any> {
|
|
|
55
57
|
/**
|
|
56
58
|
* Migration execution time limiter (in milliseconds).
|
|
57
59
|
*/
|
|
58
|
-
export
|
|
60
|
+
export type ExecutionTimeLimiter = () => number;
|
|
59
61
|
export interface MigrationEventPayload {
|
|
60
62
|
command: "status" | "execute";
|
|
61
63
|
version?: string;
|
|
62
64
|
pattern?: string;
|
|
65
|
+
force?: boolean;
|
|
63
66
|
}
|
|
64
|
-
export
|
|
67
|
+
export type MigrationEventHandlerResponse = undefined | MigrationStatusResponse | MigrationInvocationErrorResponse;
|
|
65
68
|
export interface MigrationInvocationErrorResponse {
|
|
66
69
|
error: {
|
|
67
70
|
message: string;
|
package/types.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "Logger", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _pino.Logger;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
var _pino = require("pino");
|
|
3
|
+
//# sourceMappingURL=types.js.map
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import { Logger } from \"
|
|
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":[]}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import LambdaClient from "aws-sdk/clients/lambda";
|
|
2
|
-
import { MigrationEventHandlerResponse } from "../types";
|
|
3
|
-
interface GetMigrationStatusParams {
|
|
4
|
-
lambdaClient: LambdaClient;
|
|
5
|
-
functionName: string;
|
|
6
|
-
payload?: Record<string, any>;
|
|
7
|
-
}
|
|
8
|
-
export declare const getMigrationStatus: ({ payload, functionName, lambdaClient }: GetMigrationStatusParams) => Promise<MigrationEventHandlerResponse>;
|
|
9
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.getMigrationStatus = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
const getMigrationStatus = async ({
|
|
10
|
-
payload,
|
|
11
|
-
functionName,
|
|
12
|
-
lambdaClient
|
|
13
|
-
}) => {
|
|
14
|
-
const response = await lambdaClient.invoke({
|
|
15
|
-
FunctionName: functionName,
|
|
16
|
-
InvocationType: "RequestResponse",
|
|
17
|
-
Payload: JSON.stringify((0, _objectSpread2.default)((0, _objectSpread2.default)({}, payload), {}, {
|
|
18
|
-
command: "status"
|
|
19
|
-
}))
|
|
20
|
-
}).promise();
|
|
21
|
-
return JSON.parse(response.Payload);
|
|
22
|
-
};
|
|
23
|
-
exports.getMigrationStatus = getMigrationStatus;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["getMigrationStatus","payload","functionName","lambdaClient","response","invoke","FunctionName","InvocationType","Payload","JSON","stringify","command","promise","parse"],"sources":["getMigrationStatus.ts"],"sourcesContent":["import LambdaClient from \"aws-sdk/clients/lambda\";\nimport { MigrationEventHandlerResponse } from \"~/types\";\n\ninterface GetMigrationStatusParams {\n lambdaClient: LambdaClient;\n functionName: string;\n payload?: Record<string, any>;\n}\n\nexport const getMigrationStatus = async ({\n payload,\n functionName,\n lambdaClient\n}: GetMigrationStatusParams) => {\n const response = await lambdaClient\n .invoke({\n FunctionName: functionName,\n InvocationType: \"RequestResponse\",\n Payload: JSON.stringify({ ...payload, command: \"status\" })\n })\n .promise();\n\n return JSON.parse(response.Payload as string) as MigrationEventHandlerResponse;\n};\n"],"mappings":";;;;;;;;AASO,MAAMA,kBAAkB,GAAG,OAAO;EACrCC,OAAO;EACPC,YAAY;EACZC;AACsB,CAAC,KAAK;EAC5B,MAAMC,QAAQ,GAAG,MAAMD,YAAY,CAC9BE,MAAM,CAAC;IACJC,YAAY,EAAEJ,YAAY;IAC1BK,cAAc,EAAE,iBAAiB;IACjCC,OAAO,EAAEC,IAAI,CAACC,SAAS,6DAAMT,OAAO;MAAEU,OAAO,EAAE;IAAQ;EAC3D,CAAC,CAAC,CACDC,OAAO,EAAE;EAEd,OAAOH,IAAI,CAACI,KAAK,CAACT,QAAQ,CAACI,OAAO,CAAW;AACjD,CAAC;AAAC"}
|
package/cli/printReport.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { CliContext } from "@webiny/cli/types";
|
|
2
|
-
import { MigrationEventHandlerResponse } from "../types";
|
|
3
|
-
interface ReportParams {
|
|
4
|
-
response: MigrationEventHandlerResponse;
|
|
5
|
-
migrationLambdaArn: string;
|
|
6
|
-
context: CliContext;
|
|
7
|
-
}
|
|
8
|
-
export declare const printReport: ({ response, migrationLambdaArn, context }: ReportParams) => void;
|
|
9
|
-
export {};
|
package/cli/printReport.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.printReport = void 0;
|
|
8
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
|
-
var _centerAlign = _interopRequireDefault(require("center-align"));
|
|
10
|
-
const _excluded = ["migrations"];
|
|
11
|
-
const isError = response => {
|
|
12
|
-
if (!response) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return "error" in response;
|
|
16
|
-
};
|
|
17
|
-
const makeEven = str => {
|
|
18
|
-
if (str.length % 2 > 0) {
|
|
19
|
-
return str + " ";
|
|
20
|
-
}
|
|
21
|
-
return str;
|
|
22
|
-
};
|
|
23
|
-
const printReport = ({
|
|
24
|
-
response,
|
|
25
|
-
migrationLambdaArn,
|
|
26
|
-
context
|
|
27
|
-
}) => {
|
|
28
|
-
if (!response) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (isError(response)) {
|
|
32
|
-
context.error(response.error.message);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const functionName = migrationLambdaArn.split(":").pop();
|
|
36
|
-
context.success(`Data migration Lambda %s executed successfully!`, functionName);
|
|
37
|
-
const _response$data = response.data,
|
|
38
|
-
{
|
|
39
|
-
migrations
|
|
40
|
-
} = _response$data,
|
|
41
|
-
run = (0, _objectWithoutProperties2.default)(_response$data, _excluded);
|
|
42
|
-
if (!migrations.length) {
|
|
43
|
-
context.info(`No applicable migrations were found!`);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const maxLength = Math.max(...migrations.map(mig => mig.status.length)) + 2;
|
|
47
|
-
context.info(`Migration run: %s`, run.id);
|
|
48
|
-
context.info(`Status: %s`, run.status);
|
|
49
|
-
context.info(`Started on: %s`, run.startedOn);
|
|
50
|
-
if (run.status === "done") {
|
|
51
|
-
context.info(`Finished on: %s`, run.finishedOn);
|
|
52
|
-
}
|
|
53
|
-
for (const migration of migrations) {
|
|
54
|
-
context.info(...[`[%s] %s: ${migration.description}`, (0, _centerAlign.default)(makeEven(migration.status), maxLength), migration.id]);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
exports.printReport = printReport;
|
package/cli/printReport.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["isError","response","makeEven","str","length","printReport","migrationLambdaArn","context","error","message","functionName","split","pop","success","data","migrations","run","info","maxLength","Math","max","map","mig","status","id","startedOn","finishedOn","migration","description","center"],"sources":["printReport.ts"],"sourcesContent":["import { CliContext } from \"@webiny/cli/types\";\nimport { MigrationEventHandlerResponse, MigrationInvocationErrorResponse } from \"~/types\";\nimport center from \"center-align\";\n\ninterface ReportParams {\n response: MigrationEventHandlerResponse;\n migrationLambdaArn: string;\n context: CliContext;\n}\n\nconst isError = (\n response: MigrationEventHandlerResponse\n): response is MigrationInvocationErrorResponse => {\n if (!response) {\n return false;\n }\n\n return \"error\" in response;\n};\n\nconst makeEven = (str: string) => {\n if (str.length % 2 > 0) {\n return str + \" \";\n }\n return str;\n};\n\nexport const printReport = ({ response, migrationLambdaArn, context }: ReportParams) => {\n if (!response) {\n return;\n }\n\n if (isError(response)) {\n context.error(response.error.message);\n return;\n }\n\n const functionName = migrationLambdaArn.split(\":\").pop();\n context.success(`Data migration Lambda %s executed successfully!`, functionName);\n\n const { migrations, ...run } = response.data;\n if (!migrations.length) {\n context.info(`No applicable migrations were found!`);\n return;\n }\n\n const maxLength = Math.max(...migrations.map(mig => mig.status.length)) + 2;\n context.info(`Migration run: %s`, run.id);\n context.info(`Status: %s`, run.status);\n context.info(`Started on: %s`, run.startedOn);\n if (run.status === \"done\") {\n context.info(`Finished on: %s`, run.finishedOn);\n }\n for (const migration of migrations) {\n context.info(\n ...[\n `[%s] %s: ${migration.description}`,\n center(makeEven(migration.status), maxLength),\n migration.id\n ]\n );\n }\n};\n"],"mappings":";;;;;;;;AAEA;AAAkC;AAQlC,MAAMA,OAAO,GACTC,QAAuC,IACQ;EAC/C,IAAI,CAACA,QAAQ,EAAE;IACX,OAAO,KAAK;EAChB;EAEA,OAAO,OAAO,IAAIA,QAAQ;AAC9B,CAAC;AAED,MAAMC,QAAQ,GAAIC,GAAW,IAAK;EAC9B,IAAIA,GAAG,CAACC,MAAM,GAAG,CAAC,GAAG,CAAC,EAAE;IACpB,OAAOD,GAAG,GAAG,GAAG;EACpB;EACA,OAAOA,GAAG;AACd,CAAC;AAEM,MAAME,WAAW,GAAG,CAAC;EAAEJ,QAAQ;EAAEK,kBAAkB;EAAEC;AAAsB,CAAC,KAAK;EACpF,IAAI,CAACN,QAAQ,EAAE;IACX;EACJ;EAEA,IAAID,OAAO,CAACC,QAAQ,CAAC,EAAE;IACnBM,OAAO,CAACC,KAAK,CAACP,QAAQ,CAACO,KAAK,CAACC,OAAO,CAAC;IACrC;EACJ;EAEA,MAAMC,YAAY,GAAGJ,kBAAkB,CAACK,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,EAAE;EACxDL,OAAO,CAACM,OAAO,CAAE,iDAAgD,EAAEH,YAAY,CAAC;EAEhF,uBAA+BT,QAAQ,CAACa,IAAI;IAAtC;MAAEC;IAAmB,CAAC;IAALC,GAAG;EAC1B,IAAI,CAACD,UAAU,CAACX,MAAM,EAAE;IACpBG,OAAO,CAACU,IAAI,CAAE,sCAAqC,CAAC;IACpD;EACJ;EAEA,MAAMC,SAAS,GAAGC,IAAI,CAACC,GAAG,CAAC,GAAGL,UAAU,CAACM,GAAG,CAACC,GAAG,IAAIA,GAAG,CAACC,MAAM,CAACnB,MAAM,CAAC,CAAC,GAAG,CAAC;EAC3EG,OAAO,CAACU,IAAI,CAAE,mBAAkB,EAAED,GAAG,CAACQ,EAAE,CAAC;EACzCjB,OAAO,CAACU,IAAI,CAAE,YAAW,EAAED,GAAG,CAACO,MAAM,CAAC;EACtChB,OAAO,CAACU,IAAI,CAAE,gBAAe,EAAED,GAAG,CAACS,SAAS,CAAC;EAC7C,IAAIT,GAAG,CAACO,MAAM,KAAK,MAAM,EAAE;IACvBhB,OAAO,CAACU,IAAI,CAAE,iBAAgB,EAAED,GAAG,CAACU,UAAU,CAAC;EACnD;EACA,KAAK,MAAMC,SAAS,IAAIZ,UAAU,EAAE;IAChCR,OAAO,CAACU,IAAI,CACR,GAAG,CACE,YAAWU,SAAS,CAACC,WAAY,EAAC,EACnC,IAAAC,oBAAM,EAAC3B,QAAQ,CAACyB,SAAS,CAACJ,MAAM,CAAC,EAAEL,SAAS,CAAC,EAC7CS,SAAS,CAACH,EAAE,CACf,CACJ;EACL;AACJ,CAAC;AAAC"}
|
package/cli/runMigration.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import LambdaClient from "aws-sdk/clients/lambda";
|
|
2
|
-
import { MigrationInvocationErrorResponse, MigrationRun, MigrationStatusResponse } from "../types";
|
|
3
|
-
interface RunMigrationParams {
|
|
4
|
-
lambdaClient: LambdaClient;
|
|
5
|
-
functionName: string;
|
|
6
|
-
payload?: Record<string, any>;
|
|
7
|
-
statusCallback?: (status: MigrationRun) => void;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Run the migration Lambda, and re-run when resuming is requested.
|
|
11
|
-
*/
|
|
12
|
-
export declare const runMigration: ({ payload, functionName, lambdaClient, statusCallback }: RunMigrationParams) => Promise<MigrationStatusResponse | MigrationInvocationErrorResponse>;
|
|
13
|
-
export {};
|
package/cli/runMigration.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.runMigration = void 0;
|
|
8
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
9
|
-
var _getMigrationStatus = require("./getMigrationStatus");
|
|
10
|
-
const getMigrationStatusReportInterval = () => {
|
|
11
|
-
const envKey = "MIGRATION_STATUS_REPORT_INTERVAL";
|
|
12
|
-
if (envKey in process.env) {
|
|
13
|
-
return parseInt(String(process.env[envKey]));
|
|
14
|
-
}
|
|
15
|
-
return 2000;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Run the migration Lambda, and re-run when resuming is requested.
|
|
20
|
-
*/
|
|
21
|
-
const runMigration = async ({
|
|
22
|
-
payload,
|
|
23
|
-
functionName,
|
|
24
|
-
lambdaClient,
|
|
25
|
-
statusCallback
|
|
26
|
-
}) => {
|
|
27
|
-
// We don't report status, if `stdout` is not TTY (usually in CIs, and child processes spawned programmatically).
|
|
28
|
-
const reportStatus = data => {
|
|
29
|
-
if (!process.stdout.isTTY || typeof statusCallback !== "function") {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
statusCallback(data);
|
|
33
|
-
};
|
|
34
|
-
const invokeMigration = async () => {
|
|
35
|
-
const response = await lambdaClient.invoke({
|
|
36
|
-
FunctionName: functionName,
|
|
37
|
-
InvocationType: "Event",
|
|
38
|
-
Payload: JSON.stringify((0, _objectSpread2.default)((0, _objectSpread2.default)({}, payload), {}, {
|
|
39
|
-
command: "execute"
|
|
40
|
-
}))
|
|
41
|
-
}).promise();
|
|
42
|
-
return response.StatusCode;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// Execute migration function.
|
|
46
|
-
await invokeMigration();
|
|
47
|
-
|
|
48
|
-
// Poll for status and re-execute when migration is in "pending" state.
|
|
49
|
-
let response;
|
|
50
|
-
while (true) {
|
|
51
|
-
await new Promise(resolve => setTimeout(resolve, getMigrationStatusReportInterval()));
|
|
52
|
-
response = await (0, _getMigrationStatus.getMigrationStatus)({
|
|
53
|
-
payload,
|
|
54
|
-
functionName,
|
|
55
|
-
lambdaClient
|
|
56
|
-
});
|
|
57
|
-
if (!response) {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
const {
|
|
61
|
-
data,
|
|
62
|
-
error
|
|
63
|
-
} = response;
|
|
64
|
-
|
|
65
|
-
// If we received an error, it must be an unrecoverable error, and we don't retry.
|
|
66
|
-
if (error) {
|
|
67
|
-
return response;
|
|
68
|
-
}
|
|
69
|
-
switch (data.status) {
|
|
70
|
-
case "init":
|
|
71
|
-
reportStatus(data);
|
|
72
|
-
continue;
|
|
73
|
-
case "pending":
|
|
74
|
-
await invokeMigration();
|
|
75
|
-
break;
|
|
76
|
-
case "running":
|
|
77
|
-
reportStatus(data);
|
|
78
|
-
break;
|
|
79
|
-
case "done":
|
|
80
|
-
default:
|
|
81
|
-
return response;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
exports.runMigration = runMigration;
|
package/cli/runMigration.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["getMigrationStatusReportInterval","envKey","process","env","parseInt","String","runMigration","payload","functionName","lambdaClient","statusCallback","reportStatus","data","stdout","isTTY","invokeMigration","response","invoke","FunctionName","InvocationType","Payload","JSON","stringify","command","promise","StatusCode","Promise","resolve","setTimeout","getMigrationStatus","error","status"],"sources":["runMigration.ts"],"sourcesContent":["import LambdaClient from \"aws-sdk/clients/lambda\";\nimport {\n MigrationEventHandlerResponse,\n MigrationInvocationErrorResponse,\n MigrationRun,\n MigrationStatus,\n MigrationStatusResponse\n} from \"~/types\";\nimport { getMigrationStatus } from \"./getMigrationStatus\";\n\ninterface RunMigrationParams {\n lambdaClient: LambdaClient;\n functionName: string;\n payload?: Record<string, any>;\n statusCallback?: (status: MigrationRun) => void;\n}\n\nconst getMigrationStatusReportInterval = () => {\n const envKey = \"MIGRATION_STATUS_REPORT_INTERVAL\";\n if (envKey in process.env) {\n return parseInt(String(process.env[envKey]));\n }\n return 2000;\n};\n\n/**\n * Run the migration Lambda, and re-run when resuming is requested.\n */\nexport const runMigration = async ({\n payload,\n functionName,\n lambdaClient,\n statusCallback\n}: RunMigrationParams): Promise<MigrationStatusResponse | MigrationInvocationErrorResponse> => {\n // We don't report status, if `stdout` is not TTY (usually in CIs, and child processes spawned programmatically).\n const reportStatus = (data: MigrationStatus) => {\n if (!process.stdout.isTTY || typeof statusCallback !== \"function\") {\n return;\n }\n\n statusCallback(data);\n };\n\n const invokeMigration = async () => {\n const response = await lambdaClient\n .invoke({\n FunctionName: functionName,\n InvocationType: \"Event\",\n Payload: JSON.stringify({ ...payload, command: \"execute\" })\n })\n .promise();\n\n return response.StatusCode;\n };\n\n // Execute migration function.\n await invokeMigration();\n\n // Poll for status and re-execute when migration is in \"pending\" state.\n let response: MigrationEventHandlerResponse;\n while (true) {\n await new Promise(resolve => setTimeout(resolve, getMigrationStatusReportInterval()));\n\n response = await getMigrationStatus({\n payload,\n functionName,\n lambdaClient\n });\n\n if (!response) {\n continue;\n }\n\n const { data, error } = response;\n\n // If we received an error, it must be an unrecoverable error, and we don't retry.\n if (error) {\n return response;\n }\n\n switch (data.status) {\n case \"init\":\n reportStatus(data);\n continue;\n case \"pending\":\n await invokeMigration();\n break;\n case \"running\":\n reportStatus(data);\n break;\n case \"done\":\n default:\n return response;\n }\n }\n};\n"],"mappings":";;;;;;;;AAQA;AASA,MAAMA,gCAAgC,GAAG,MAAM;EAC3C,MAAMC,MAAM,GAAG,kCAAkC;EACjD,IAAIA,MAAM,IAAIC,OAAO,CAACC,GAAG,EAAE;IACvB,OAAOC,QAAQ,CAACC,MAAM,CAACH,OAAO,CAACC,GAAG,CAACF,MAAM,CAAC,CAAC,CAAC;EAChD;EACA,OAAO,IAAI;AACf,CAAC;;AAED;AACA;AACA;AACO,MAAMK,YAAY,GAAG,OAAO;EAC/BC,OAAO;EACPC,YAAY;EACZC,YAAY;EACZC;AACgB,CAAC,KAA0E;EAC3F;EACA,MAAMC,YAAY,GAAIC,IAAqB,IAAK;IAC5C,IAAI,CAACV,OAAO,CAACW,MAAM,CAACC,KAAK,IAAI,OAAOJ,cAAc,KAAK,UAAU,EAAE;MAC/D;IACJ;IAEAA,cAAc,CAACE,IAAI,CAAC;EACxB,CAAC;EAED,MAAMG,eAAe,GAAG,YAAY;IAChC,MAAMC,QAAQ,GAAG,MAAMP,YAAY,CAC9BQ,MAAM,CAAC;MACJC,YAAY,EAAEV,YAAY;MAC1BW,cAAc,EAAE,OAAO;MACvBC,OAAO,EAAEC,IAAI,CAACC,SAAS,6DAAMf,OAAO;QAAEgB,OAAO,EAAE;MAAS;IAC5D,CAAC,CAAC,CACDC,OAAO,EAAE;IAEd,OAAOR,QAAQ,CAACS,UAAU;EAC9B,CAAC;;EAED;EACA,MAAMV,eAAe,EAAE;;EAEvB;EACA,IAAIC,QAAuC;EAC3C,OAAO,IAAI,EAAE;IACT,MAAM,IAAIU,OAAO,CAACC,OAAO,IAAIC,UAAU,CAACD,OAAO,EAAE3B,gCAAgC,EAAE,CAAC,CAAC;IAErFgB,QAAQ,GAAG,MAAM,IAAAa,sCAAkB,EAAC;MAChCtB,OAAO;MACPC,YAAY;MACZC;IACJ,CAAC,CAAC;IAEF,IAAI,CAACO,QAAQ,EAAE;MACX;IACJ;IAEA,MAAM;MAAEJ,IAAI;MAAEkB;IAAM,CAAC,GAAGd,QAAQ;;IAEhC;IACA,IAAIc,KAAK,EAAE;MACP,OAAOd,QAAQ;IACnB;IAEA,QAAQJ,IAAI,CAACmB,MAAM;MACf,KAAK,MAAM;QACPpB,YAAY,CAACC,IAAI,CAAC;QAClB;MACJ,KAAK,SAAS;QACV,MAAMG,eAAe,EAAE;QACvB;MACJ,KAAK,SAAS;QACVJ,YAAY,CAACC,IAAI,CAAC;QAClB;MACJ,KAAK,MAAM;MACX;QACI,OAAOI,QAAQ;IAAC;EAE5B;AACJ,CAAC;AAAC"}
|
package/createId.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const createId: () => any;
|
package/createId.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.createId = void 0;
|
|
8
|
-
var _mdbid = _interopRequireDefault(require("mdbid"));
|
|
9
|
-
// @ts-ignore mdbid doesn't have TS types.
|
|
10
|
-
|
|
11
|
-
const createId = () => {
|
|
12
|
-
return (0, _mdbid.default)();
|
|
13
|
-
};
|
|
14
|
-
exports.createId = createId;
|
package/createId.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createId","mdbid"],"sources":["createId.ts"],"sourcesContent":["// @ts-ignore mdbid doesn't have TS types.\nimport mdbid from \"mdbid\";\n\nexport const createId = () => {\n return mdbid();\n};\n"],"mappings":";;;;;;;AACA;AADA;;AAGO,MAAMA,QAAQ,GAAG,MAAM;EAC1B,OAAO,IAAAC,cAAK,GAAE;AAClB,CAAC;AAAC"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createStandardEntity = void 0;
|
|
7
|
-
var _dynamodbToolbox = require("dynamodb-toolbox");
|
|
8
|
-
const createStandardEntity = ({
|
|
9
|
-
table,
|
|
10
|
-
name
|
|
11
|
-
}) => {
|
|
12
|
-
return new _dynamodbToolbox.Entity({
|
|
13
|
-
name,
|
|
14
|
-
table,
|
|
15
|
-
attributes: {
|
|
16
|
-
PK: {
|
|
17
|
-
partitionKey: true
|
|
18
|
-
},
|
|
19
|
-
SK: {
|
|
20
|
-
sortKey: true
|
|
21
|
-
},
|
|
22
|
-
GSI1_PK: {
|
|
23
|
-
type: "string"
|
|
24
|
-
},
|
|
25
|
-
GSI1_SK: {
|
|
26
|
-
type: "string"
|
|
27
|
-
},
|
|
28
|
-
TYPE: {
|
|
29
|
-
type: "string"
|
|
30
|
-
},
|
|
31
|
-
data: {
|
|
32
|
-
type: "map"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
exports.createStandardEntity = createStandardEntity;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["createStandardEntity","table","name","Entity","attributes","PK","partitionKey","SK","sortKey","GSI1_PK","type","GSI1_SK","TYPE","data"],"sources":["createStandardEntity.ts"],"sourcesContent":["import { Table, Entity } from \"dynamodb-toolbox\";\n\nexport const createStandardEntity = ({ table, name }: { table: Table; name: string }) => {\n return new Entity({\n name,\n table,\n attributes: {\n PK: {\n partitionKey: true\n },\n SK: {\n sortKey: true\n },\n GSI1_PK: {\n type: \"string\"\n },\n GSI1_SK: {\n type: \"string\"\n },\n TYPE: {\n type: \"string\"\n },\n data: {\n type: \"map\"\n }\n }\n });\n};\n"],"mappings":";;;;;;AAAA;AAEO,MAAMA,oBAAoB,GAAG,CAAC;EAAEC,KAAK;EAAEC;AAAqC,CAAC,KAAK;EACrF,OAAO,IAAIC,uBAAM,CAAC;IACdD,IAAI;IACJD,KAAK;IACLG,UAAU,EAAE;MACRC,EAAE,EAAE;QACAC,YAAY,EAAE;MAClB,CAAC;MACDC,EAAE,EAAE;QACAC,OAAO,EAAE;MACb,CAAC;MACDC,OAAO,EAAE;QACLC,IAAI,EAAE;MACV,CAAC;MACDC,OAAO,EAAE;QACLD,IAAI,EAAE;MACV,CAAC;MACDE,IAAI,EAAE;QACFF,IAAI,EAAE;MACV,CAAC;MACDG,IAAI,EAAE;QACFH,IAAI,EAAE;MACV;IACJ;EACJ,CAAC,CAAC;AACN,CAAC;AAAC"}
|