@webiny/data-migration 5.39.0-beta.0 → 5.39.0-beta.2
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.js +10 -14
- package/MigrationRunner.js.map +1 -1
- package/cli/CliMigrationRunReporter.js +3 -8
- package/cli/CliMigrationRunReporter.js.map +1 -1
- package/cli/InteractiveCliStatusReporter.js +2 -4
- package/cli/InteractiveCliStatusReporter.js.map +1 -1
- package/cli/LogReporter.js +1 -5
- package/cli/LogReporter.js.map +1 -1
- package/cli/LogStream.js +3 -9
- package/cli/LogStream.js.map +1 -1
- package/cli/MigrationRunner.d.ts +1 -1
- package/cli/MigrationRunner.js +24 -23
- package/cli/MigrationRunner.js.map +1 -1
- package/cli/NonInteractiveCliStatusReporter.js +2 -5
- package/cli/NonInteractiveCliStatusReporter.js.map +1 -1
- package/createTable.d.ts +4 -4
- package/createTable.js +6 -3
- package/createTable.js.map +1 -1
- package/handlers/createDdbEsProjectMigration.d.ts +3 -3
- package/handlers/createDdbEsProjectMigration.js +12 -16
- package/handlers/createDdbEsProjectMigration.js.map +1 -1
- package/handlers/createDdbProjectMigration.d.ts +2 -2
- package/handlers/createDdbProjectMigration.js +10 -14
- package/handlers/createDdbProjectMigration.js.map +1 -1
- package/package.json +11 -11
- package/repository/createStandardEntity.d.ts +49 -3
- package/repository/createStandardEntity.js +2 -2
- package/repository/createStandardEntity.js.map +1 -1
- package/repository/migrations.repository.d.ts +2 -2
- package/repository/migrations.repository.js +46 -35
- package/repository/migrations.repository.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NonInteractiveCliStatusReporter","
|
|
1
|
+
{"version":3,"names":["NonInteractiveCliStatusReporter","firstCall","constructor","logReporter","console","log","report","migrationStatus","status","context","currentLogStreamName","logStreamName","initializeStream","printLogStreamLinks","process","stdout","write","printLogs","includes","Promise","resolve","setTimeout","exports"],"sources":["NonInteractiveCliStatusReporter.ts"],"sourcesContent":["import { MigrationStatusReporter } from \"~/cli/MigrationStatusReporter\";\nimport { MigrationStatus } from \"~/types\";\nimport { LogReporter } from \"~/cli/LogReporter\";\n\nexport class NonInteractiveCliStatusReporter implements MigrationStatusReporter {\n private logReporter: LogReporter;\n private firstCall = true;\n\n constructor(logReporter: LogReporter) {\n this.logReporter = logReporter;\n console.log(`Using \"NonInteractiveCliStatusReporter\".`);\n }\n\n async report(migrationStatus: MigrationStatus) {\n const { status, context } = migrationStatus;\n\n const currentLogStreamName = context?.logStreamName;\n\n if (currentLogStreamName) {\n this.logReporter.initializeStream(currentLogStreamName);\n if (this.firstCall) {\n this.logReporter.printLogStreamLinks();\n process.stdout.write(`\\n---------- MIGRATION LOGS START ----------\\n\\n`);\n }\n await this.logReporter.printLogs(currentLogStreamName);\n }\n\n if ([\"done\", \"error\"].includes(status)) {\n // We want to give AWS some time for the latest log events to become available.\n await new Promise(resolve => {\n setTimeout(resolve, 10000);\n });\n\n if (currentLogStreamName) {\n await this.logReporter.printLogs(currentLogStreamName);\n process.stdout.write(`\\n---------- MIGRATION LOGS END ----------\\n`);\n }\n }\n\n this.firstCall = false;\n }\n}\n"],"mappings":";;;;;;AAIO,MAAMA,+BAA+B,CAAoC;EAEpEC,SAAS,GAAG,IAAI;EAExBC,WAAWA,CAACC,WAAwB,EAAE;IAClC,IAAI,CAACA,WAAW,GAAGA,WAAW;IAC9BC,OAAO,CAACC,GAAG,CAAE,0CAAyC,CAAC;EAC3D;EAEA,MAAMC,MAAMA,CAACC,eAAgC,EAAE;IAC3C,MAAM;MAAEC,MAAM;MAAEC;IAAQ,CAAC,GAAGF,eAAe;IAE3C,MAAMG,oBAAoB,GAAGD,OAAO,EAAEE,aAAa;IAEnD,IAAID,oBAAoB,EAAE;MACtB,IAAI,CAACP,WAAW,CAACS,gBAAgB,CAACF,oBAAoB,CAAC;MACvD,IAAI,IAAI,CAACT,SAAS,EAAE;QAChB,IAAI,CAACE,WAAW,CAACU,mBAAmB,CAAC,CAAC;QACtCC,OAAO,CAACC,MAAM,CAACC,KAAK,CAAE,kDAAiD,CAAC;MAC5E;MACA,MAAM,IAAI,CAACb,WAAW,CAACc,SAAS,CAACP,oBAAoB,CAAC;IAC1D;IAEA,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAACQ,QAAQ,CAACV,MAAM,CAAC,EAAE;MACpC;MACA,MAAM,IAAIW,OAAO,CAACC,OAAO,IAAI;QACzBC,UAAU,CAACD,OAAO,EAAE,KAAK,CAAC;MAC9B,CAAC,CAAC;MAEF,IAAIV,oBAAoB,EAAE;QACtB,MAAM,IAAI,CAACP,WAAW,CAACc,SAAS,CAACP,oBAAoB,CAAC;QACtDI,OAAO,CAACC,MAAM,CAACC,KAAK,CAAE,8CAA6C,CAAC;MACxE;IACJ;IAEA,IAAI,CAACf,SAAS,GAAG,KAAK;EAC1B;AACJ;AAACqB,OAAA,CAAAtB,+BAAA,GAAAA,+BAAA"}
|
package/createTable.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Table } from "dynamodb
|
|
1
|
+
import { DynamoDBClient } from "@webiny/aws-sdk/client-dynamodb";
|
|
2
|
+
import { Table } from "@webiny/db-dynamodb/toolbox";
|
|
3
3
|
export interface CreateTableParams {
|
|
4
4
|
name: string;
|
|
5
|
-
documentClient:
|
|
5
|
+
documentClient: DynamoDBClient;
|
|
6
6
|
}
|
|
7
|
-
export declare const createTable: ({ name, documentClient }: CreateTableParams) => Table
|
|
7
|
+
export declare const createTable: ({ name, documentClient }: CreateTableParams) => Table<string, "PK", "SK">;
|
package/createTable.js
CHANGED
|
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createTable = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _toolbox = require("@webiny/db-dynamodb/toolbox");
|
|
8
8
|
const createTable = ({
|
|
9
9
|
name,
|
|
10
10
|
documentClient
|
|
11
11
|
}) => {
|
|
12
|
-
return new
|
|
12
|
+
return new _toolbox.Table({
|
|
13
13
|
name,
|
|
14
14
|
partitionKey: "PK",
|
|
15
15
|
sortKey: "SK",
|
|
@@ -23,7 +23,10 @@ const createTable = ({
|
|
|
23
23
|
// partitionKey: "GSI2_PK",
|
|
24
24
|
// sortKey: "GSI2_SK"
|
|
25
25
|
// }
|
|
26
|
-
}
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
autoExecute: true,
|
|
29
|
+
autoParse: true
|
|
27
30
|
});
|
|
28
31
|
};
|
|
29
32
|
exports.createTable = createTable;
|
package/createTable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_toolbox","require","createTable","name","documentClient","Table","partitionKey","sortKey","DocumentClient","indexes","GSI1","autoExecute","autoParse","exports"],"sources":["createTable.ts"],"sourcesContent":["import { DynamoDBClient } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { Table } from \"@webiny/db-dynamodb/toolbox\";\n\nexport interface CreateTableParams {\n name: string;\n documentClient: DynamoDBClient;\n}\n\nexport const createTable = ({ name, documentClient }: CreateTableParams) => {\n return new Table({\n name,\n partitionKey: \"PK\",\n sortKey: \"SK\",\n DocumentClient: documentClient,\n indexes: {\n GSI1: {\n partitionKey: \"GSI1_PK\",\n sortKey: \"GSI1_SK\"\n }\n // GSI2: {\n // partitionKey: \"GSI2_PK\",\n // sortKey: \"GSI2_SK\"\n // }\n },\n autoExecute: true,\n autoParse: true\n });\n};\n"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAOO,MAAMC,WAAW,GAAGA,CAAC;EAAEC,IAAI;EAAEC;AAAkC,CAAC,KAAK;EACxE,OAAO,IAAIC,cAAK,CAAC;IACbF,IAAI;IACJG,YAAY,EAAE,IAAI;IAClBC,OAAO,EAAE,IAAI;IACbC,cAAc,EAAEJ,cAAc;IAC9BK,OAAO,EAAE;MACLC,IAAI,EAAE;QACFJ,YAAY,EAAE,SAAS;QACvBC,OAAO,EAAE;MACb;MACA;MACA;MACA;MACA;IACJ,CAAC;;IACDI,WAAW,EAAE,IAAI;IACjBC,SAAS,EAAE;EACf,CAAC,CAAC;AACN,CAAC;AAACC,OAAA,CAAAX,WAAA,GAAAA,WAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Client as ElasticsearchClient } from "@elastic/elasticsearch";
|
|
2
|
-
import { Table } from "dynamodb
|
|
2
|
+
import { Table } from "@webiny/db-dynamodb/toolbox";
|
|
3
3
|
import { Constructor } from "@webiny/ioc";
|
|
4
4
|
import { DataMigration, ExecutionTimeLimiter, MigrationEventHandlerResponse, MigrationEventPayload, MigrationRepository } from "../types";
|
|
5
5
|
import { IsMigrationApplicable } from "../MigrationRunner";
|
|
6
6
|
interface CreateDdbEsDataMigrationConfig {
|
|
7
7
|
elasticsearchClient: ElasticsearchClient;
|
|
8
|
-
primaryTable: Table
|
|
9
|
-
dynamoToEsTable: Table
|
|
8
|
+
primaryTable: Table<string, string, string>;
|
|
9
|
+
dynamoToEsTable: Table<string, string, string>;
|
|
10
10
|
migrations: Constructor<DataMigration>[];
|
|
11
11
|
isMigrationApplicable?: IsMigrationApplicable;
|
|
12
12
|
repository?: MigrationRepository;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.createDdbEsProjectMigration = void 0;
|
|
8
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
7
|
var _handlerAws = require("@webiny/handler-aws");
|
|
10
8
|
var _ioc = require("@webiny/ioc");
|
|
11
9
|
var _symbols = require("../symbols");
|
|
@@ -14,24 +12,22 @@ var _migrations = require("../repository/migrations.repository");
|
|
|
14
12
|
var _devVersionErrorResponse = require("./devVersionErrorResponse");
|
|
15
13
|
var _createPatternMatcher = require("./createPatternMatcher");
|
|
16
14
|
var _semver = require("semver");
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} = _ref,
|
|
27
|
-
config = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
15
|
+
const createDdbEsProjectMigration = ({
|
|
16
|
+
migrations,
|
|
17
|
+
elasticsearchClient,
|
|
18
|
+
primaryTable,
|
|
19
|
+
dynamoToEsTable,
|
|
20
|
+
isMigrationApplicable = undefined,
|
|
21
|
+
repository = undefined,
|
|
22
|
+
...config
|
|
23
|
+
}) => {
|
|
28
24
|
return (0, _handlerAws.createRawEventHandler)(async ({
|
|
29
25
|
payload,
|
|
30
26
|
lambdaContext
|
|
31
27
|
}) => {
|
|
32
|
-
const projectVersion = String(
|
|
28
|
+
const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);
|
|
33
29
|
const version = (0, _semver.coerce)(projectVersion);
|
|
34
|
-
if (
|
|
30
|
+
if (version?.version === "0.0.0") {
|
|
35
31
|
return (0, _devVersionErrorResponse.devVersionErrorResponse)();
|
|
36
32
|
}
|
|
37
33
|
|
|
@@ -40,7 +36,7 @@ const createDdbEsProjectMigration = _ref => {
|
|
|
40
36
|
container.bind(_symbols.PrimaryDynamoTableSymbol).toConstantValue(primaryTable);
|
|
41
37
|
container.bind(_symbols.ElasticsearchDynamoTableSymbol).toConstantValue(dynamoToEsTable);
|
|
42
38
|
container.bind(_symbols.ElasticsearchClientSymbol).toConstantValue(elasticsearchClient);
|
|
43
|
-
const timeLimiter = config.timeLimiter ||
|
|
39
|
+
const timeLimiter = config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);
|
|
44
40
|
container.bind(_symbols.ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);
|
|
45
41
|
if (repository) {
|
|
46
42
|
// Repository implementation provided by the user.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_handlerAws","require","_ioc","_symbols","_MigrationRunner","_migrations","_devVersionErrorResponse","_createPatternMatcher","_semver","
|
|
1
|
+
{"version":3,"names":["_handlerAws","require","_ioc","_symbols","_MigrationRunner","_migrations","_devVersionErrorResponse","_createPatternMatcher","_semver","createDdbEsProjectMigration","migrations","elasticsearchClient","primaryTable","dynamoToEsTable","isMigrationApplicable","undefined","repository","config","createRawEventHandler","payload","lambdaContext","projectVersion","String","version","process","env","WEBINY_VERSION","semverCoerce","devVersionErrorResponse","container","createContainer","bind","PrimaryDynamoTableSymbol","toConstantValue","ElasticsearchDynamoTableSymbol","ElasticsearchClientSymbol","timeLimiter","getRemainingTimeInMillis","ExecutionTimeLimiterSymbol","MigrationRepositorySymbol","to","MigrationRepositoryImpl","forEach","migration","MigrationSymbol","patternMatcher","pattern","createPatternMatcher","runner","resolve","MigrationRunner","setContext","logGroupName","AWS_LAMBDA_LOG_GROUP_NAME","logStreamName","AWS_LAMBDA_LOG_STREAM_NAME","command","execute","data","getStatus","err","error","message","exports"],"sources":["createDdbEsProjectMigration.ts"],"sourcesContent":["import { Client as ElasticsearchClient } from \"@elastic/elasticsearch\";\nimport { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { Constructor, createContainer } from \"@webiny/ioc\";\nimport {\n DataMigration,\n ExecutionTimeLimiter,\n MigrationEventHandlerResponse,\n MigrationEventPayload,\n MigrationRepository\n} from \"~/types\";\nimport {\n ElasticsearchClientSymbol,\n ElasticsearchDynamoTableSymbol,\n ExecutionTimeLimiterSymbol,\n MigrationRepositorySymbol,\n MigrationSymbol,\n PrimaryDynamoTableSymbol\n} from \"~/symbols\";\nimport { IsMigrationApplicable, MigrationRunner } from \"~/MigrationRunner\";\nimport { MigrationRepositoryImpl } from \"~/repository/migrations.repository\";\nimport { devVersionErrorResponse } from \"~/handlers/devVersionErrorResponse\";\nimport { createPatternMatcher } from \"~/handlers/createPatternMatcher\";\nimport { coerce as semverCoerce } from \"semver\";\n\ninterface CreateDdbEsDataMigrationConfig {\n elasticsearchClient: ElasticsearchClient;\n primaryTable: Table<string, string, string>;\n dynamoToEsTable: Table<string, string, string>;\n migrations: Constructor<DataMigration>[];\n isMigrationApplicable?: IsMigrationApplicable;\n repository?: MigrationRepository;\n timeLimiter?: ExecutionTimeLimiter;\n}\n\nexport const createDdbEsProjectMigration = ({\n migrations,\n elasticsearchClient,\n primaryTable,\n dynamoToEsTable,\n isMigrationApplicable = undefined,\n repository = undefined,\n ...config\n}: CreateDdbEsDataMigrationConfig) => {\n return createRawEventHandler<MigrationEventPayload, any, MigrationEventHandlerResponse>(\n async ({ payload, lambdaContext }) => {\n const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);\n\n const version = semverCoerce(projectVersion);\n if (version?.version === \"0.0.0\") {\n return devVersionErrorResponse();\n }\n\n // COMPOSITION ROOT\n const container = createContainer();\n container.bind(PrimaryDynamoTableSymbol).toConstantValue(primaryTable);\n container.bind(ElasticsearchDynamoTableSymbol).toConstantValue(dynamoToEsTable);\n container.bind(ElasticsearchClientSymbol).toConstantValue(elasticsearchClient);\n\n const timeLimiter: ExecutionTimeLimiter =\n config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);\n container.bind(ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);\n\n if (repository) {\n // Repository implementation provided by the user.\n container.bind(MigrationRepositorySymbol).toConstantValue(repository);\n } else {\n // Default repository implementation.\n container.bind(MigrationRepositorySymbol).to(MigrationRepositoryImpl);\n }\n\n // Bind the provided migrations.\n migrations.forEach(migration => container.bind(MigrationSymbol).to(migration));\n\n // If handler was invoked with a `pattern`, filter migrations that match the pattern only.\n let patternMatcher;\n if (payload.pattern) {\n patternMatcher = createPatternMatcher(payload.pattern);\n }\n\n // Inject dependencies and execute.\n try {\n const runner = await container.resolve(MigrationRunner);\n runner.setContext({\n logGroupName: process.env.AWS_LAMBDA_LOG_GROUP_NAME,\n logStreamName: process.env.AWS_LAMBDA_LOG_STREAM_NAME\n });\n\n if (payload.command === \"execute\") {\n await runner.execute(projectVersion, patternMatcher || isMigrationApplicable);\n return;\n }\n\n return { data: await runner.getStatus() };\n } catch (err) {\n return { error: { message: err.message } };\n }\n }\n );\n};\n"],"mappings":";;;;;;AAEA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAQA,IAAAE,QAAA,GAAAF,OAAA;AAQA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,wBAAA,GAAAL,OAAA;AACA,IAAAM,qBAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AAYO,MAAMQ,2BAA2B,GAAGA,CAAC;EACxCC,UAAU;EACVC,mBAAmB;EACnBC,YAAY;EACZC,eAAe;EACfC,qBAAqB,GAAGC,SAAS;EACjCC,UAAU,GAAGD,SAAS;EACtB,GAAGE;AACyB,CAAC,KAAK;EAClC,OAAO,IAAAC,iCAAqB,EACxB,OAAO;IAAEC,OAAO;IAAEC;EAAc,CAAC,KAAK;IAClC,MAAMC,cAAc,GAAGC,MAAM,CAACH,OAAO,EAAEI,OAAO,IAAIC,OAAO,CAACC,GAAG,CAACC,cAAc,CAAC;IAE7E,MAAMH,OAAO,GAAG,IAAAI,cAAY,EAACN,cAAc,CAAC;IAC5C,IAAIE,OAAO,EAAEA,OAAO,KAAK,OAAO,EAAE;MAC9B,OAAO,IAAAK,gDAAuB,EAAC,CAAC;IACpC;;IAEA;IACA,MAAMC,SAAS,GAAG,IAAAC,oBAAe,EAAC,CAAC;IACnCD,SAAS,CAACE,IAAI,CAACC,iCAAwB,CAAC,CAACC,eAAe,CAACrB,YAAY,CAAC;IACtEiB,SAAS,CAACE,IAAI,CAACG,uCAA8B,CA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AS,CAAC;MAAE,CAAC;IAC7C,CAAC,CAAC,OAAOC,GAAG,EAAE;MACV,OAAO;QAAEC,KAAK,EAAE;UAAEC,OAAO,EAAEF,GAAG,CAACE;QAAQ;MAAE,CAAC;IAC9C;EACJ,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAtD,2BAAA,GAAAA,2BAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Table } from "dynamodb
|
|
1
|
+
import { Table } from "@webiny/db-dynamodb/toolbox";
|
|
2
2
|
import { Constructor } from "@webiny/ioc";
|
|
3
3
|
import { IsMigrationApplicable } from "../MigrationRunner";
|
|
4
4
|
import { DataMigration, ExecutionTimeLimiter, MigrationEventHandlerResponse, MigrationEventPayload, MigrationRepository } from "../types";
|
|
5
5
|
interface CreateDdbDataMigrationConfig {
|
|
6
6
|
migrations: Constructor<DataMigration>[];
|
|
7
|
-
primaryTable: Table
|
|
7
|
+
primaryTable: Table<string, string, string>;
|
|
8
8
|
repository?: MigrationRepository;
|
|
9
9
|
isMigrationApplicable?: IsMigrationApplicable;
|
|
10
10
|
timeLimiter?: ExecutionTimeLimiter;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.createDdbProjectMigration = void 0;
|
|
8
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
7
|
var _handlerAws = require("@webiny/handler-aws");
|
|
10
8
|
var _ioc = require("@webiny/ioc");
|
|
11
9
|
var _MigrationRunner = require("../MigrationRunner");
|
|
@@ -14,29 +12,27 @@ var _migrations = require("../repository/migrations.repository");
|
|
|
14
12
|
var _devVersionErrorResponse = require("./devVersionErrorResponse");
|
|
15
13
|
var _createPatternMatcher = require("./createPatternMatcher");
|
|
16
14
|
var _semver = require("semver");
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} = _ref,
|
|
25
|
-
config = (0, _objectWithoutProperties2.default)(_ref, _excluded);
|
|
15
|
+
const createDdbProjectMigration = ({
|
|
16
|
+
migrations,
|
|
17
|
+
primaryTable,
|
|
18
|
+
isMigrationApplicable = undefined,
|
|
19
|
+
repository = undefined,
|
|
20
|
+
...config
|
|
21
|
+
}) => {
|
|
26
22
|
return (0, _handlerAws.createRawEventHandler)(async ({
|
|
27
23
|
payload,
|
|
28
24
|
lambdaContext
|
|
29
25
|
}) => {
|
|
30
|
-
const projectVersion = String(
|
|
26
|
+
const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);
|
|
31
27
|
const version = (0, _semver.coerce)(projectVersion);
|
|
32
|
-
if (
|
|
28
|
+
if (version?.version === "0.0.0") {
|
|
33
29
|
return (0, _devVersionErrorResponse.devVersionErrorResponse)();
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
// COMPOSITION ROOT
|
|
37
33
|
const container = (0, _ioc.createContainer)();
|
|
38
34
|
container.bind(_symbols.PrimaryDynamoTableSymbol).toConstantValue(primaryTable);
|
|
39
|
-
const timeLimiter = config.timeLimiter ||
|
|
35
|
+
const timeLimiter = config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);
|
|
40
36
|
container.bind(_symbols.ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);
|
|
41
37
|
if (repository) {
|
|
42
38
|
// Repository implementation provided by the user.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_handlerAws","require","_ioc","_MigrationRunner","_symbols","_migrations","_devVersionErrorResponse","_createPatternMatcher","_semver","
|
|
1
|
+
{"version":3,"names":["_handlerAws","require","_ioc","_MigrationRunner","_symbols","_migrations","_devVersionErrorResponse","_createPatternMatcher","_semver","createDdbProjectMigration","migrations","primaryTable","isMigrationApplicable","undefined","repository","config","createRawEventHandler","payload","lambdaContext","projectVersion","String","version","process","env","WEBINY_VERSION","semverCoerce","devVersionErrorResponse","container","createContainer","bind","PrimaryDynamoTableSymbol","toConstantValue","timeLimiter","getRemainingTimeInMillis","ExecutionTimeLimiterSymbol","MigrationRepositorySymbol","to","MigrationRepositoryImpl","forEach","migration","MigrationSymbol","patternMatcher","pattern","createPatternMatcher","runner","resolve","MigrationRunner","setContext","logGroupName","AWS_LAMBDA_LOG_GROUP_NAME","logStreamName","AWS_LAMBDA_LOG_STREAM_NAME","command","execute","data","getStatus","err","error","message","exports"],"sources":["createDdbProjectMigration.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport { Constructor, createContainer } from \"@webiny/ioc\";\nimport { IsMigrationApplicable, MigrationRunner } from \"~/MigrationRunner\";\nimport {\n ExecutionTimeLimiterSymbol,\n MigrationRepositorySymbol,\n MigrationSymbol,\n PrimaryDynamoTableSymbol\n} from \"~/symbols\";\nimport { MigrationRepositoryImpl } from \"~/repository/migrations.repository\";\nimport { devVersionErrorResponse } from \"./devVersionErrorResponse\";\nimport { createPatternMatcher } from \"./createPatternMatcher\";\nimport {\n DataMigration,\n ExecutionTimeLimiter,\n MigrationEventHandlerResponse,\n MigrationEventPayload,\n MigrationRepository\n} from \"~/types\";\nimport { coerce as semverCoerce } from \"semver\";\n\ninterface CreateDdbDataMigrationConfig {\n migrations: Constructor<DataMigration>[];\n primaryTable: Table<string, string, string>;\n repository?: MigrationRepository;\n isMigrationApplicable?: IsMigrationApplicable;\n timeLimiter?: ExecutionTimeLimiter;\n}\n\nexport const createDdbProjectMigration = ({\n migrations,\n primaryTable,\n isMigrationApplicable = undefined,\n repository = undefined,\n ...config\n}: CreateDdbDataMigrationConfig) => {\n return createRawEventHandler<MigrationEventPayload, any, MigrationEventHandlerResponse>(\n async ({ payload, lambdaContext }) => {\n const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);\n\n const version = semverCoerce(projectVersion);\n if (version?.version === \"0.0.0\") {\n return devVersionErrorResponse();\n }\n\n // COMPOSITION ROOT\n const container = createContainer();\n container.bind(PrimaryDynamoTableSymbol).toConstantValue(primaryTable);\n\n const timeLimiter: ExecutionTimeLimiter =\n config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);\n container.bind(ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);\n\n if (repository) {\n // Repository implementation provided by the user.\n container.bind(MigrationRepositorySymbol).toConstantValue(repository);\n } else {\n // Default repository implementation.\n container.bind(MigrationRepositorySymbol).to(MigrationRepositoryImpl);\n }\n\n // Bind the provided migrations.\n migrations.forEach(migration => container.bind(MigrationSymbol).to(migration));\n\n // If handler was invoked with a `pattern`, filter migrations that match the pattern only.\n let patternMatcher;\n if (payload.pattern) {\n patternMatcher = createPatternMatcher(payload.pattern);\n }\n\n // Inject dependencies and execute.\n try {\n const runner = await container.resolve(MigrationRunner);\n runner.setContext({\n logGroupName: process.env.AWS_LAMBDA_LOG_GROUP_NAME,\n logStreamName: process.env.AWS_LAMBDA_LOG_STREAM_NAME\n });\n\n if (payload.command === \"execute\") {\n await runner.execute(projectVersion, patternMatcher || isMigrationApplicable);\n return;\n }\n\n return {\n data: await runner.getStatus()\n };\n } catch (err) {\n return { error: { message: err.message } };\n }\n }\n );\n};\n"],"mappings":";;;;;;AACA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAMA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,wBAAA,GAAAL,OAAA;AACA,IAAAM,qBAAA,GAAAN,OAAA;AAQA,IAAAO,OAAA,GAAAP,OAAA;AAUO,MAAMQ,yBAAyB,GAAGA,CAAC;EACtCC,UAAU;EACVC,YAAY;EACZC,qBAAqB,GAAG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,MAAM,GAAG,MAAMjB,SAAS,CAACkB,OAAO,CAACC,gCAAe,CAAC;MACvDF,MAAM,CAACG,UAAU,CAAC;QACdC,YAAY,EAAE1B,OAAO,CAACC,GAAG,CAAC0B,yBAAyB;QACnDC,aAAa,EAAE5B,OAAO,CAACC,GAAG,CAAC4B;MAC/B,CAAC,CAAC;MAEF,IAAIlC,OAAO,CAACmC,OAAO,KAAK,SAAS,EAAE;QAC/B,MAAMR,MAAM,CAACS,OAAO,CAAClC,cAAc,EAAEsB,cAAc,IAAI7B,qBAAqB,CAAC;QAC7E;MACJ;MAEA,OAAO;QACH0C,IAAI,EAAE,MAAMV,MAAM,CAACW,SAAS,CAAC;MACjC,CAAC;IACL,CAAC,CAAC,OAAOC,GAAG,EAAE;MACV,OAAO;QAAEC,KAAK,EAAE;UAAEC,OAAO,EAAEF,GAAG,CAACE;QAAQ;MAAE,CAAC;IAC9C;EACJ,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAlD,yBAAA,GAAAA,yBAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/data-migration",
|
|
3
|
-
"version": "5.39.0-beta.
|
|
3
|
+
"version": "5.39.0-beta.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "types.ts",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
"@babel/runtime": "7.22.6",
|
|
15
15
|
"@elastic/elasticsearch": "7.12.0",
|
|
16
16
|
"@types/pino": "7.0.5",
|
|
17
|
-
"@webiny/
|
|
18
|
-
"@webiny/
|
|
19
|
-
"@webiny/
|
|
20
|
-
"@webiny/
|
|
21
|
-
"@webiny/
|
|
17
|
+
"@webiny/aws-sdk": "5.39.0-beta.2",
|
|
18
|
+
"@webiny/db-dynamodb": "5.39.0-beta.2",
|
|
19
|
+
"@webiny/handler-aws": "5.39.0-beta.2",
|
|
20
|
+
"@webiny/ioc": "5.39.0-beta.2",
|
|
21
|
+
"@webiny/logger": "5.39.0-beta.2",
|
|
22
|
+
"@webiny/utils": "5.39.0-beta.2",
|
|
22
23
|
"center-align": "1.0.1",
|
|
23
24
|
"chalk": "4.1.2",
|
|
24
|
-
"dynamodb-toolbox": "0.3.5",
|
|
25
25
|
"minimatch": "5.1.6",
|
|
26
26
|
"pino-pretty": "9.4.0",
|
|
27
|
-
"semver": "
|
|
27
|
+
"semver": "7.5.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/cli": "7.22.6",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"@babel/preset-env": "7.22.7",
|
|
33
33
|
"@types/center-align": "1.0.0",
|
|
34
34
|
"@types/semver": "7.3.13",
|
|
35
|
-
"@webiny/cli": "5.39.0-beta.
|
|
36
|
-
"@webiny/project-utils": "5.39.0-beta.
|
|
35
|
+
"@webiny/cli": "5.39.0-beta.2",
|
|
36
|
+
"@webiny/project-utils": "5.39.0-beta.2",
|
|
37
37
|
"jest": "29.5.0",
|
|
38
38
|
"jest-dynalite": "3.6.1",
|
|
39
39
|
"jest-mock-console": "1.3.0",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
]
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "193039382160557448f23f43685f29136f58f87a"
|
|
59
59
|
}
|
|
@@ -1,5 +1,51 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Entity, Table } from "@webiny/db-dynamodb/toolbox";
|
|
2
2
|
export declare const createStandardEntity: ({ table, name }: {
|
|
3
|
-
table: Table
|
|
3
|
+
table: Table<string, string, string>;
|
|
4
4
|
name: string;
|
|
5
|
-
}) => Entity<{
|
|
5
|
+
}) => Entity<string, import("dynamodb-toolbox/dist/cjs/classes/Entity").Overlay, import("dynamodb-toolbox/dist/cjs/classes/Entity").Overlay, Table<string, string, string>, boolean, boolean, boolean, string, string, string, boolean, {
|
|
6
|
+
PK: {
|
|
7
|
+
partitionKey: true;
|
|
8
|
+
};
|
|
9
|
+
SK: {
|
|
10
|
+
sortKey: true;
|
|
11
|
+
};
|
|
12
|
+
GSI1_PK: {
|
|
13
|
+
type: "string";
|
|
14
|
+
};
|
|
15
|
+
GSI1_SK: {
|
|
16
|
+
type: "string";
|
|
17
|
+
};
|
|
18
|
+
TYPE: {
|
|
19
|
+
type: "string";
|
|
20
|
+
};
|
|
21
|
+
data: {
|
|
22
|
+
type: "map";
|
|
23
|
+
};
|
|
24
|
+
}, {
|
|
25
|
+
PK: {
|
|
26
|
+
partitionKey: true;
|
|
27
|
+
};
|
|
28
|
+
SK: {
|
|
29
|
+
sortKey: true;
|
|
30
|
+
};
|
|
31
|
+
GSI1_PK: {
|
|
32
|
+
type: "string";
|
|
33
|
+
};
|
|
34
|
+
GSI1_SK: {
|
|
35
|
+
type: "string";
|
|
36
|
+
};
|
|
37
|
+
TYPE: {
|
|
38
|
+
type: "string";
|
|
39
|
+
};
|
|
40
|
+
data: {
|
|
41
|
+
type: "map";
|
|
42
|
+
};
|
|
43
|
+
}, import("dynamodb-toolbox/dist/cjs/classes/Entity").ParsedAttributes<import("ts-toolbelt/out/Any/Key").Key>, any, {
|
|
44
|
+
[x: string]: any;
|
|
45
|
+
[x: number]: any;
|
|
46
|
+
[x: symbol]: any;
|
|
47
|
+
}, {
|
|
48
|
+
[x: string]: any;
|
|
49
|
+
[x: number]: any;
|
|
50
|
+
[x: symbol]: any;
|
|
51
|
+
}>;
|
|
@@ -4,12 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createStandardEntity = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _toolbox = require("@webiny/db-dynamodb/toolbox");
|
|
8
8
|
const createStandardEntity = ({
|
|
9
9
|
table,
|
|
10
10
|
name
|
|
11
11
|
}) => {
|
|
12
|
-
return new
|
|
12
|
+
return new _toolbox.Entity({
|
|
13
13
|
name,
|
|
14
14
|
table,
|
|
15
15
|
attributes: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_toolbox","require","createStandardEntity","table","name","Entity","attributes","PK","partitionKey","SK","sortKey","GSI1_PK","type","GSI1_SK","TYPE","data","exports"],"sources":["createStandardEntity.ts"],"sourcesContent":["import { Entity, Table } from \"@webiny/db-dynamodb/toolbox\";\n\nexport const createStandardEntity = ({\n table,\n name\n}: {\n table: Table<string, string, string>;\n name: string;\n}) => {\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,IAAAA,QAAA,GAAAC,OAAA;AAEO,MAAMC,oBAAoB,GAAGA,CAAC;EACjCC,KAAK;EACLC;AAIJ,CAAC,KAAK;EACF,OAAO,IAAIC,eAAM,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;AAACI,OAAA,CAAAd,oBAAA,GAAAA,oBAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Table } from "dynamodb
|
|
1
|
+
import { Table } from "@webiny/db-dynamodb/toolbox";
|
|
2
2
|
import { MigrationItem, MigrationRepository, MigrationRun } from "../types";
|
|
3
3
|
export declare class MigrationRepositoryImpl implements MigrationRepository {
|
|
4
4
|
private readonly run;
|
|
5
5
|
private readonly migration;
|
|
6
6
|
private readonly checkpoint;
|
|
7
|
-
constructor(table: Table);
|
|
7
|
+
constructor(table: Table<string, string, string>);
|
|
8
8
|
getLastRun(): Promise<MigrationRun | null>;
|
|
9
9
|
saveRun(run: MigrationRun): Promise<void>;
|
|
10
10
|
listMigrations(params?: {
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.MigrationRepositoryImpl = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
7
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
10
8
|
var _ioc = require("@webiny/ioc");
|
|
11
9
|
var _symbols = require("../symbols");
|
|
12
10
|
var _createStandardEntity = require("./createStandardEntity");
|
|
11
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
13
12
|
class MigrationRepositoryImpl {
|
|
14
13
|
constructor(table) {
|
|
15
|
-
(0, _defineProperty2.default)(this, "run", void 0);
|
|
16
|
-
(0, _defineProperty2.default)(this, "migration", void 0);
|
|
17
|
-
(0, _defineProperty2.default)(this, "checkpoint", void 0);
|
|
18
14
|
this.run = (0, _createStandardEntity.createStandardEntity)({
|
|
19
15
|
table,
|
|
20
16
|
name: "MigrationRun"
|
|
@@ -41,13 +37,16 @@ class MigrationRepositoryImpl {
|
|
|
41
37
|
return result ? result.data : null;
|
|
42
38
|
}
|
|
43
39
|
async saveRun(run) {
|
|
44
|
-
await
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
+
}
|
|
51
50
|
});
|
|
52
51
|
}
|
|
53
52
|
async listMigrations(params) {
|
|
@@ -68,40 +67,52 @@ class MigrationRepositoryImpl {
|
|
|
68
67
|
return result.map(item => item.data);
|
|
69
68
|
}
|
|
70
69
|
async logMigration(migration) {
|
|
71
|
-
await
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
+
}
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
async createCheckpoint(id, data) {
|
|
81
|
-
await
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
+
}
|
|
88
93
|
});
|
|
89
94
|
}
|
|
90
|
-
deleteCheckpoint(id) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
async deleteCheckpoint(id) {
|
|
96
|
+
await (0, _dbDynamodb.deleteItem)({
|
|
97
|
+
entity: this.checkpoint,
|
|
98
|
+
keys: {
|
|
99
|
+
PK: `MIGRATION_CHECKPOINT#${id}`,
|
|
100
|
+
SK: "A"
|
|
101
|
+
}
|
|
94
102
|
});
|
|
95
103
|
}
|
|
96
104
|
async getCheckpoint(id) {
|
|
97
|
-
const record = await
|
|
98
|
-
|
|
99
|
-
|
|
105
|
+
const record = await (0, _dbDynamodb.get)({
|
|
106
|
+
entity: this.checkpoint,
|
|
107
|
+
keys: {
|
|
108
|
+
PK: `MIGRATION_CHECKPOINT#${id}`,
|
|
109
|
+
SK: "A"
|
|
110
|
+
}
|
|
100
111
|
});
|
|
101
|
-
if (!record
|
|
112
|
+
if (!record) {
|
|
102
113
|
return null;
|
|
103
114
|
}
|
|
104
|
-
return record.
|
|
115
|
+
return record.data;
|
|
105
116
|
}
|
|
106
117
|
}
|
|
107
118
|
exports.MigrationRepositoryImpl = MigrationRepositoryImpl;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_query","require","_ioc","_symbols","_createStandardEntity","MigrationRepositoryImpl","constructor","table","
|
|
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 { Entity, Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { queryAll, queryOne } from \"@webiny/db-dynamodb/utils/query\";\nimport { 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,WAAWA,CAACC,KAAoC,EAAE;IAC9C,IAAI,CAACC,GAAG,GAAG,IAAAC,0CAAoB,EAAC;MAAEF,KAAK;MAAEG,IAAI,EAAE;IAAe,CAAC,CAAC;IAChE,IAAI,CAACC,SAAS,GAAG,IAAAF,0CAAoB,EAAC;MAAEF,KAAK;MAAEG,IAAI,EAAE;IAAY,CAAC,CAAC;IACnE,IAAI,CAACE,UAAU,GAAG,IAAAH,0CAAoB,EAAC;MAAEF,KAAK;MAAEG,IAAI,EAAE;IAAsB,CAAC,CAAC;EAClF;EAEA,MAAMG,UAAUA,CAAA,EAAiC;IAC7C,MAAMC,MAAM,GAAG,MAAM,IAAAC,eAAQ,EAAyB;MAClDC,MAAM,EAAE,IAAI,CAACR,GAAG;MAChBS,YAAY,EAAE,gBAAgB;MAC9BC,OAAO,EAAE;QACLC,KAAK,EAAE,MAAM;QACbC,EAAE,EAAE,GAAG;QACPC,OAAO,EAAE;MACb;IAC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