@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,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getChildLogger = exports.createPinoLogger = void 0;
|
|
8
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
9
|
+
var _pinoPretty = _interopRequireDefault(require("pino-pretty"));
|
|
10
|
+
var _logger = require("@webiny/logger");
|
|
11
|
+
const createPinoLogger = () => {
|
|
12
|
+
return (0, _logger.createPinoLogger)({
|
|
13
|
+
level: (0, _logger.getLogLevel)(process.env.MIGRATIONS_LOG_LEVEL, "trace")
|
|
14
|
+
}, (0, _pinoPretty.default)({
|
|
15
|
+
ignore: "pid,hostname"
|
|
16
|
+
}));
|
|
17
|
+
};
|
|
18
|
+
exports.createPinoLogger = createPinoLogger;
|
|
19
|
+
const getChildLogger = (logger, migration) => {
|
|
20
|
+
return logger.child({}, {
|
|
21
|
+
msgPrefix: _chalk.default.blueBright(`[${migration.getId()}]`) + " "
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.getChildLogger = getChildLogger;
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=createPinoLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_chalk","_interopRequireDefault","require","_pinoPretty","_logger","createPinoLogger","baseCreatePinoLogger","level","getLogLevel","process","env","MIGRATIONS_LOG_LEVEL","pinoPretty","ignore","exports","getChildLogger","logger","migration","child","msgPrefix","chalk","blueBright","getId"],"sources":["createPinoLogger.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport pinoPretty from \"pino-pretty\";\nimport type { DataMigration } from \"~/types\";\nimport type { Logger } from \"@webiny/logger\";\nimport { createPinoLogger as baseCreatePinoLogger, getLogLevel } from \"@webiny/logger\";\n\nexport const createPinoLogger = () => {\n return baseCreatePinoLogger(\n {\n level: getLogLevel(process.env.MIGRATIONS_LOG_LEVEL, \"trace\")\n },\n pinoPretty({\n ignore: \"pid,hostname\"\n })\n );\n};\n\nexport const getChildLogger = (logger: Logger, migration: DataMigration) => {\n return logger.child({}, { msgPrefix: chalk.blueBright(`[${migration.getId()}]`) + \" \" });\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAF,sBAAA,CAAAC,OAAA;AAGA,IAAAE,OAAA,GAAAF,OAAA;AAEO,MAAMG,gBAAgB,GAAGA,CAAA,KAAM;EAClC,OAAO,IAAAC,wBAAoB,EACvB;IACIC,KAAK,EAAE,IAAAC,mBAAW,EAACC,OAAO,CAACC,GAAG,CAACC,oBAAoB,EAAE,OAAO;EAChE,CAAC,EACD,IAAAC,mBAAU,EAAC;IACPC,MAAM,EAAE;EACZ,CAAC,CACL,CAAC;AACL,CAAC;AAACC,OAAA,CAAAT,gBAAA,GAAAA,gBAAA;AAEK,MAAMU,cAAc,GAAGA,CAACC,MAAc,EAAEC,SAAwB,KAAK;EACxE,OAAOD,MAAM,CAACE,KAAK,CAAC,CAAC,CAAC,EAAE;IAAEC,SAAS,EAAEC,cAAK,CAACC,UAAU,CAAC,IAAIJ,SAAS,CAACK,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG;EAAI,CAAC,CAAC;AAC5F,CAAC;AAACR,OAAA,CAAAC,cAAA,GAAAA,cAAA","ignoreList":[]}
|
package/createTable.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { DynamoDBDocument } from "@webiny/aws-sdk/client-dynamodb";
|
|
2
|
+
import { Table } from "@webiny/db-dynamodb/toolbox";
|
|
3
|
+
export interface CreateTableParams {
|
|
4
|
+
name: string;
|
|
5
|
+
documentClient: DynamoDBDocument;
|
|
6
|
+
}
|
|
7
|
+
export declare const createTable: ({ name, documentClient }: CreateTableParams) => Table<string, "PK", "SK">;
|
package/createTable.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createTable = void 0;
|
|
7
|
+
var _toolbox = require("@webiny/db-dynamodb/toolbox");
|
|
8
|
+
const createTable = ({
|
|
9
|
+
name,
|
|
10
|
+
documentClient
|
|
11
|
+
}) => {
|
|
12
|
+
return new _toolbox.Table({
|
|
13
|
+
name,
|
|
14
|
+
partitionKey: "PK",
|
|
15
|
+
sortKey: "SK",
|
|
16
|
+
DocumentClient: documentClient,
|
|
17
|
+
indexes: {
|
|
18
|
+
GSI1: {
|
|
19
|
+
partitionKey: "GSI1_PK",
|
|
20
|
+
sortKey: "GSI1_SK"
|
|
21
|
+
}
|
|
22
|
+
// GSI2: {
|
|
23
|
+
// partitionKey: "GSI2_PK",
|
|
24
|
+
// sortKey: "GSI2_SK"
|
|
25
|
+
// }
|
|
26
|
+
},
|
|
27
|
+
autoExecute: true,
|
|
28
|
+
autoParse: true
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
exports.createTable = createTable;
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=createTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_toolbox","require","createTable","name","documentClient","Table","partitionKey","sortKey","DocumentClient","indexes","GSI1","autoExecute","autoParse","exports"],"sources":["createTable.ts"],"sourcesContent":["import type { DynamoDBDocument } from \"@webiny/aws-sdk/client-dynamodb\";\nimport { Table } from \"@webiny/db-dynamodb/toolbox\";\n\nexport interface CreateTableParams {\n name: string;\n documentClient: DynamoDBDocument;\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","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Client as ElasticsearchClient } from "@elastic/elasticsearch";
|
|
2
|
+
import type { Table } from "@webiny/db-dynamodb/toolbox";
|
|
3
|
+
import type { Constructor } from "@webiny/ioc";
|
|
4
|
+
import type { DataMigration, ExecutionTimeLimiter, MigrationEventHandlerResponse, MigrationEventPayload, MigrationRepository } from "../types";
|
|
5
|
+
import type { IsMigrationApplicable } from "../MigrationRunner";
|
|
6
|
+
interface CreateDdbEsDataMigrationConfig {
|
|
7
|
+
elasticsearchClient: ElasticsearchClient;
|
|
8
|
+
primaryTable: Table<string, string, string>;
|
|
9
|
+
dynamoToEsTable: Table<string, string, string>;
|
|
10
|
+
migrations: Constructor<DataMigration>[];
|
|
11
|
+
isMigrationApplicable?: IsMigrationApplicable;
|
|
12
|
+
repository?: MigrationRepository;
|
|
13
|
+
timeLimiter?: ExecutionTimeLimiter;
|
|
14
|
+
}
|
|
15
|
+
export declare const createDdbEsProjectMigration: ({ migrations, elasticsearchClient, primaryTable, dynamoToEsTable, isMigrationApplicable, repository, ...config }: CreateDdbEsDataMigrationConfig) => import("@webiny/handler-aws").RawEventHandler<MigrationEventPayload, any, MigrationEventHandlerResponse>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDdbEsProjectMigration = void 0;
|
|
7
|
+
var _handlerAws = require("@webiny/handler-aws");
|
|
8
|
+
var _ioc = require("@webiny/ioc");
|
|
9
|
+
var _symbols = require("../symbols");
|
|
10
|
+
var _MigrationRunner = require("../MigrationRunner");
|
|
11
|
+
var _migrations = require("../repository/migrations.repository");
|
|
12
|
+
var _devVersionErrorResponse = require("./devVersionErrorResponse");
|
|
13
|
+
var _createPatternMatcher = require("./createPatternMatcher");
|
|
14
|
+
var _semver = require("semver");
|
|
15
|
+
const createDdbEsProjectMigration = ({
|
|
16
|
+
migrations,
|
|
17
|
+
elasticsearchClient,
|
|
18
|
+
primaryTable,
|
|
19
|
+
dynamoToEsTable,
|
|
20
|
+
isMigrationApplicable = undefined,
|
|
21
|
+
repository = undefined,
|
|
22
|
+
...config
|
|
23
|
+
}) => {
|
|
24
|
+
return (0, _handlerAws.createRawEventHandler)(async ({
|
|
25
|
+
payload,
|
|
26
|
+
lambdaContext
|
|
27
|
+
}) => {
|
|
28
|
+
const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);
|
|
29
|
+
const forceExecute = payload.force === true;
|
|
30
|
+
const version = (0, _semver.coerce)(projectVersion);
|
|
31
|
+
if (version?.version === "0.0.0") {
|
|
32
|
+
return (0, _devVersionErrorResponse.devVersionErrorResponse)();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// COMPOSITION ROOT
|
|
36
|
+
const container = (0, _ioc.createContainer)();
|
|
37
|
+
container.bind(_symbols.PrimaryDynamoTableSymbol).toConstantValue(primaryTable);
|
|
38
|
+
container.bind(_symbols.ElasticsearchDynamoTableSymbol).toConstantValue(dynamoToEsTable);
|
|
39
|
+
container.bind(_symbols.ElasticsearchClientSymbol).toConstantValue(elasticsearchClient);
|
|
40
|
+
const timeLimiter = config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);
|
|
41
|
+
container.bind(_symbols.ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);
|
|
42
|
+
if (repository) {
|
|
43
|
+
// Repository implementation provided by the user.
|
|
44
|
+
container.bind(_symbols.MigrationRepositorySymbol).toConstantValue(repository);
|
|
45
|
+
} else {
|
|
46
|
+
// Default repository implementation.
|
|
47
|
+
container.bind(_symbols.MigrationRepositorySymbol).to(_migrations.MigrationRepositoryImpl);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Bind the provided migrations.
|
|
51
|
+
migrations.forEach(migration => container.bind(_symbols.MigrationSymbol).to(migration));
|
|
52
|
+
|
|
53
|
+
// If handler was invoked with a `pattern`, filter migrations that match the pattern only.
|
|
54
|
+
let patternMatcher;
|
|
55
|
+
if (payload.pattern) {
|
|
56
|
+
patternMatcher = (0, _createPatternMatcher.createPatternMatcher)(payload.pattern);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Inject dependencies and execute.
|
|
60
|
+
try {
|
|
61
|
+
const runner = await container.resolve(_MigrationRunner.MigrationRunner);
|
|
62
|
+
runner.setContext({
|
|
63
|
+
logGroupName: process.env.AWS_LAMBDA_LOG_GROUP_NAME,
|
|
64
|
+
logStreamName: process.env.AWS_LAMBDA_LOG_STREAM_NAME
|
|
65
|
+
});
|
|
66
|
+
if (payload.command === "execute") {
|
|
67
|
+
await runner.execute(projectVersion, patternMatcher || isMigrationApplicable, forceExecute);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
data: await runner.getStatus()
|
|
72
|
+
};
|
|
73
|
+
} catch (err) {
|
|
74
|
+
return {
|
|
75
|
+
error: {
|
|
76
|
+
message: err.message
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
exports.createDdbEsProjectMigration = createDdbEsProjectMigration;
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=createDdbEsProjectMigration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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","forceExecute","force","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 type { Client as ElasticsearchClient } from \"@elastic/elasticsearch\";\nimport type { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport type { Constructor } from \"@webiny/ioc\";\nimport { createContainer } from \"@webiny/ioc\";\nimport type {\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 type { IsMigrationApplicable } from \"~/MigrationRunner\";\nimport { 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 const forceExecute = payload.force === true;\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(\n projectVersion,\n patternMatcher || isMigrationApplicable,\n forceExecute\n );\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;AAEA,IAAAC,IAAA,GAAAD,OAAA;AA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dynamodb/toolbox";
|
|
2
|
+
import type { Constructor } from "@webiny/ioc";
|
|
3
|
+
import type { IsMigrationApplicable } from "../MigrationRunner";
|
|
4
|
+
import type { DataMigration, ExecutionTimeLimiter, MigrationEventHandlerResponse, MigrationEventPayload, MigrationRepository } from "../types";
|
|
5
|
+
interface CreateDdbDataMigrationConfig {
|
|
6
|
+
migrations: Constructor<DataMigration>[];
|
|
7
|
+
primaryTable: Table<string, string, string>;
|
|
8
|
+
repository?: MigrationRepository;
|
|
9
|
+
isMigrationApplicable?: IsMigrationApplicable;
|
|
10
|
+
timeLimiter?: ExecutionTimeLimiter;
|
|
11
|
+
}
|
|
12
|
+
export declare const createDdbProjectMigration: ({ migrations, primaryTable, isMigrationApplicable, repository, ...config }: CreateDdbDataMigrationConfig) => import("@webiny/handler-aws").RawEventHandler<MigrationEventPayload, any, MigrationEventHandlerResponse>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createDdbProjectMigration = void 0;
|
|
7
|
+
var _handlerAws = require("@webiny/handler-aws");
|
|
8
|
+
var _ioc = require("@webiny/ioc");
|
|
9
|
+
var _MigrationRunner = require("../MigrationRunner");
|
|
10
|
+
var _symbols = require("../symbols");
|
|
11
|
+
var _migrations = require("../repository/migrations.repository");
|
|
12
|
+
var _devVersionErrorResponse = require("./devVersionErrorResponse");
|
|
13
|
+
var _createPatternMatcher = require("./createPatternMatcher");
|
|
14
|
+
var _semver = require("semver");
|
|
15
|
+
const createDdbProjectMigration = ({
|
|
16
|
+
migrations,
|
|
17
|
+
primaryTable,
|
|
18
|
+
isMigrationApplicable = undefined,
|
|
19
|
+
repository = undefined,
|
|
20
|
+
...config
|
|
21
|
+
}) => {
|
|
22
|
+
return (0, _handlerAws.createRawEventHandler)(async ({
|
|
23
|
+
payload,
|
|
24
|
+
lambdaContext
|
|
25
|
+
}) => {
|
|
26
|
+
const projectVersion = String(payload?.version || process.env.WEBINY_VERSION);
|
|
27
|
+
const forceExecute = payload.force === true;
|
|
28
|
+
const version = (0, _semver.coerce)(projectVersion);
|
|
29
|
+
if (version?.version === "0.0.0") {
|
|
30
|
+
return (0, _devVersionErrorResponse.devVersionErrorResponse)();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// COMPOSITION ROOT
|
|
34
|
+
const container = (0, _ioc.createContainer)();
|
|
35
|
+
container.bind(_symbols.PrimaryDynamoTableSymbol).toConstantValue(primaryTable);
|
|
36
|
+
const timeLimiter = config.timeLimiter || lambdaContext?.getRemainingTimeInMillis || (() => 0);
|
|
37
|
+
container.bind(_symbols.ExecutionTimeLimiterSymbol).toConstantValue(timeLimiter);
|
|
38
|
+
if (repository) {
|
|
39
|
+
// Repository implementation provided by the user.
|
|
40
|
+
container.bind(_symbols.MigrationRepositorySymbol).toConstantValue(repository);
|
|
41
|
+
} else {
|
|
42
|
+
// Default repository implementation.
|
|
43
|
+
container.bind(_symbols.MigrationRepositorySymbol).to(_migrations.MigrationRepositoryImpl);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Bind the provided migrations.
|
|
47
|
+
migrations.forEach(migration => container.bind(_symbols.MigrationSymbol).to(migration));
|
|
48
|
+
|
|
49
|
+
// If handler was invoked with a `pattern`, filter migrations that match the pattern only.
|
|
50
|
+
let patternMatcher;
|
|
51
|
+
if (payload.pattern) {
|
|
52
|
+
patternMatcher = (0, _createPatternMatcher.createPatternMatcher)(payload.pattern);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Inject dependencies and execute.
|
|
56
|
+
try {
|
|
57
|
+
const runner = await container.resolve(_MigrationRunner.MigrationRunner);
|
|
58
|
+
runner.setContext({
|
|
59
|
+
logGroupName: process.env.AWS_LAMBDA_LOG_GROUP_NAME,
|
|
60
|
+
logStreamName: process.env.AWS_LAMBDA_LOG_STREAM_NAME
|
|
61
|
+
});
|
|
62
|
+
if (payload.command === "execute") {
|
|
63
|
+
await runner.execute(projectVersion, patternMatcher || isMigrationApplicable, forceExecute);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
data: await runner.getStatus()
|
|
68
|
+
};
|
|
69
|
+
} catch (err) {
|
|
70
|
+
return {
|
|
71
|
+
error: {
|
|
72
|
+
message: err.message
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
exports.createDdbProjectMigration = createDdbProjectMigration;
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=createDdbProjectMigration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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","forceExecute","force","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 type { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { createRawEventHandler } from \"@webiny/handler-aws\";\nimport type { Constructor } from \"@webiny/ioc\";\nimport { createContainer } from \"@webiny/ioc\";\nimport type { IsMigrationApplicable } from \"~/MigrationRunner\";\nimport { 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 type {\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 const forceExecute = payload.force === true;\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(\n projectVersion,\n patternMatcher || isMigrationApplicable,\n forceExecute\n );\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;AAEA,IAAAC,IAAA,GAAAD,OAAA;AAEA,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,GAAGC,SAAS;EACjCC,UAAU,GAAGD,SAAS;EACtB,GAAGE;AACuB,CAAC,KAAK;EAChC,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;IAC7E,MAAMC,YAAY,GAAGR,OAAO,CAACS,KAAK,KAAK,IAAI;IAE3C,MAAML,OAAO,GAAG,IAAAM,cAAY,EAACR,cAAc,CAAC;IAC5C,IAAIE,OAAO,EAAEA,OAAO,KAAK,OAAO,EAAE;MAC9B,OAAO,IAAAO,gDAAuB,EAAC,CAAC;IACpC;;IAEA;IACA,MAAMC,SAAS,GAAG,IAAAC,oBAAe,EAAC,CAAC;IACnCD,SAAS,CAACE,IAAI,CAACC,iCAAwB,CAAC,CAACC,eAAe,CAACtB,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C,OAAO,EAAEF,GAAG,CAACE;QAAQ;MAAE,CAAC;IAC9C;EACJ,CACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAApD,yBAAA,GAAAA,yBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createPatternMatcher = void 0;
|
|
8
|
+
var _minimatch = _interopRequireDefault(require("minimatch"));
|
|
9
|
+
const createPatternMatcher = pattern => {
|
|
10
|
+
return migration => {
|
|
11
|
+
if (pattern.includes("*")) {
|
|
12
|
+
return (0, _minimatch.default)(migration.getId(), pattern);
|
|
13
|
+
}
|
|
14
|
+
return migration.getId() === pattern;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
exports.createPatternMatcher = createPatternMatcher;
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=createPatternMatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_minimatch","_interopRequireDefault","require","createPatternMatcher","pattern","migration","includes","minimatch","getId","exports"],"sources":["createPatternMatcher.ts"],"sourcesContent":["import minimatch from \"minimatch\";\nimport type { IsMigrationApplicable } from \"~/MigrationRunner\";\n\nexport const createPatternMatcher = (pattern: string): IsMigrationApplicable => {\n return migration => {\n if (pattern.includes(\"*\")) {\n return minimatch(migration.getId(), pattern);\n }\n return migration.getId() === pattern;\n };\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAGO,MAAMC,oBAAoB,GAAIC,OAAe,IAA4B;EAC5E,OAAOC,SAAS,IAAI;IAChB,IAAID,OAAO,CAACE,QAAQ,CAAC,GAAG,CAAC,EAAE;MACvB,OAAO,IAAAC,kBAAS,EAACF,SAAS,CAACG,KAAK,CAAC,CAAC,EAAEJ,OAAO,CAAC;IAChD;IACA,OAAOC,SAAS,CAACG,KAAK,CAAC,CAAC,KAAKJ,OAAO;EACxC,CAAC;AACL,CAAC;AAACK,OAAA,CAAAN,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.devVersionErrorResponse = void 0;
|
|
7
|
+
const devVersionErrorResponse = () => {
|
|
8
|
+
return {
|
|
9
|
+
error: {
|
|
10
|
+
message: [`This project is using a development version 0.0.0!`, `Migrations cannot be executed using version 0.0.0, as that makes them all eligible for execution.`, `To trigger a particular set of migrations, set a WEBINY_VERSION variable in the .env file.`].join(" ")
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
exports.devVersionErrorResponse = devVersionErrorResponse;
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=devVersionErrorResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["devVersionErrorResponse","error","message","join","exports"],"sources":["devVersionErrorResponse.ts"],"sourcesContent":["export const devVersionErrorResponse = () => {\n return {\n error: {\n message: [\n `This project is using a development version 0.0.0!`,\n `Migrations cannot be executed using version 0.0.0, as that makes them all eligible for execution.`,\n `To trigger a particular set of migrations, set a WEBINY_VERSION variable in the .env file.`\n ].join(\" \")\n }\n };\n};\n"],"mappings":";;;;;;AAAO,MAAMA,uBAAuB,GAAGA,CAAA,KAAM;EACzC,OAAO;IACHC,KAAK,EAAE;MACHC,OAAO,EAAE,CACL,oDAAoD,EACpD,mGAAmG,EACnG,4FAA4F,CAC/F,CAACC,IAAI,CAAC,GAAG;IACd;EACJ,CAAC;AACL,CAAC;AAACC,OAAA,CAAAJ,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _createDdbProjectMigration = require("./handlers/createDdbProjectMigration");
|
|
7
|
+
Object.keys(_createDdbProjectMigration).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _createDdbProjectMigration[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _createDdbProjectMigration[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _createDdbEsProjectMigration = require("./handlers/createDdbEsProjectMigration");
|
|
18
|
+
Object.keys(_createDdbEsProjectMigration).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _createDdbEsProjectMigration[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _createDdbEsProjectMigration[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _types = require("./types");
|
|
29
|
+
Object.keys(_types).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _types[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _createTable = require("./createTable");
|
|
40
|
+
Object.keys(_createTable).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _createTable[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _createTable[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _createPinoLogger = require("./createPinoLogger");
|
|
51
|
+
Object.keys(_createPinoLogger).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _createPinoLogger[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _createPinoLogger[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_createDdbProjectMigration","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_createDdbEsProjectMigration","_types","_createTable","_createPinoLogger"],"sources":["index.ts"],"sourcesContent":["export * from \"./handlers/createDdbProjectMigration\";\nexport * from \"./handlers/createDdbEsProjectMigration\";\nexport * from \"./types\";\nexport * from \"./createTable\";\nexport * from \"./createPinoLogger\";\nexport * from \"./createPinoLogger\";\n"],"mappings":";;;;;AAAA,IAAAA,0BAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,0BAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,0BAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,0BAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,4BAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,4BAAA,E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;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAI,iBAAA,CAAAR,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/data-migration",
|
|
3
|
+
"version": "0.0.0-unstable.06b2ede40f",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"types": "types.ts",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
10
|
+
},
|
|
11
|
+
"description": "Tools to author and execute data migrations.",
|
|
12
|
+
"author": "Webiny Ltd.",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@elastic/elasticsearch": "7.12.0",
|
|
15
|
+
"@webiny/aws-sdk": "0.0.0-unstable.06b2ede40f",
|
|
16
|
+
"@webiny/cli": "0.0.0-unstable.06b2ede40f",
|
|
17
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.06b2ede40f",
|
|
18
|
+
"@webiny/handler-aws": "0.0.0-unstable.06b2ede40f",
|
|
19
|
+
"@webiny/ioc": "0.0.0-unstable.06b2ede40f",
|
|
20
|
+
"@webiny/logger": "0.0.0-unstable.06b2ede40f",
|
|
21
|
+
"@webiny/utils": "0.0.0-unstable.06b2ede40f",
|
|
22
|
+
"center-align": "1.0.1",
|
|
23
|
+
"chalk": "4.1.2",
|
|
24
|
+
"minimatch": "5.1.6",
|
|
25
|
+
"pino-pretty": "9.4.0",
|
|
26
|
+
"semver": "7.6.3"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/center-align": "1.0.0",
|
|
30
|
+
"@types/semver": "7.3.13",
|
|
31
|
+
"@webiny/project-utils": "0.0.0-unstable.06b2ede40f",
|
|
32
|
+
"jest": "29.7.0",
|
|
33
|
+
"jest-dynalite": "3.6.1",
|
|
34
|
+
"jest-mock-console": "2.0.0",
|
|
35
|
+
"rimraf": "6.0.1",
|
|
36
|
+
"typescript": "5.3.3"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"directory": "dist"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "node ../cli/bin.js run build",
|
|
44
|
+
"watch": "node ../cli/bin.js run watch"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "06b2ede40fc2212a70eeafd74afd50b56fb0ce82"
|
|
47
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Table } from "@webiny/db-dynamodb/toolbox";
|
|
2
|
+
import { Entity } from "@webiny/db-dynamodb/toolbox";
|
|
3
|
+
export declare const createStandardEntity: ({ table, name }: {
|
|
4
|
+
table: Table<string, string, string>;
|
|
5
|
+
name: string;
|
|
6
|
+
}) => 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, {
|
|
7
|
+
PK: {
|
|
8
|
+
partitionKey: true;
|
|
9
|
+
};
|
|
10
|
+
SK: {
|
|
11
|
+
sortKey: true;
|
|
12
|
+
};
|
|
13
|
+
GSI1_PK: {
|
|
14
|
+
type: "string";
|
|
15
|
+
};
|
|
16
|
+
GSI1_SK: {
|
|
17
|
+
type: "string";
|
|
18
|
+
};
|
|
19
|
+
TYPE: {
|
|
20
|
+
type: "string";
|
|
21
|
+
};
|
|
22
|
+
data: {
|
|
23
|
+
type: "map";
|
|
24
|
+
};
|
|
25
|
+
}, {
|
|
26
|
+
PK: {
|
|
27
|
+
partitionKey: true;
|
|
28
|
+
};
|
|
29
|
+
SK: {
|
|
30
|
+
sortKey: true;
|
|
31
|
+
};
|
|
32
|
+
GSI1_PK: {
|
|
33
|
+
type: "string";
|
|
34
|
+
};
|
|
35
|
+
GSI1_SK: {
|
|
36
|
+
type: "string";
|
|
37
|
+
};
|
|
38
|
+
TYPE: {
|
|
39
|
+
type: "string";
|
|
40
|
+
};
|
|
41
|
+
data: {
|
|
42
|
+
type: "map";
|
|
43
|
+
};
|
|
44
|
+
}, import("dynamodb-toolbox/dist/cjs/classes/Entity").ParsedAttributes<import("ts-toolbelt/out/Any/Key").Key>, any, {
|
|
45
|
+
[x: string]: any;
|
|
46
|
+
[x: number]: any;
|
|
47
|
+
[x: symbol]: any;
|
|
48
|
+
}, {
|
|
49
|
+
[x: string]: any;
|
|
50
|
+
[x: number]: any;
|
|
51
|
+
[x: symbol]: any;
|
|
52
|
+
}>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createStandardEntity = void 0;
|
|
7
|
+
var _toolbox = require("@webiny/db-dynamodb/toolbox");
|
|
8
|
+
const createStandardEntity = ({
|
|
9
|
+
table,
|
|
10
|
+
name
|
|
11
|
+
}) => {
|
|
12
|
+
return new _toolbox.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;
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=createStandardEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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 type { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { Entity } 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":";;;;;;AACA,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","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Table } from "@webiny/db-dynamodb/toolbox";
|
|
2
|
+
import type { MigrationItem, MigrationRepository, MigrationRun } from "../types";
|
|
3
|
+
export declare class MigrationRepositoryImpl implements MigrationRepository {
|
|
4
|
+
private readonly run;
|
|
5
|
+
private readonly migration;
|
|
6
|
+
private readonly checkpoint;
|
|
7
|
+
constructor(table: Table<string, string, string>);
|
|
8
|
+
getLastRun(): Promise<MigrationRun | null>;
|
|
9
|
+
saveRun(run: MigrationRun): Promise<void>;
|
|
10
|
+
listMigrations(params?: {
|
|
11
|
+
limit: number;
|
|
12
|
+
}): Promise<MigrationItem[]>;
|
|
13
|
+
logMigration(migration: MigrationItem): Promise<void>;
|
|
14
|
+
createCheckpoint(id: string, data: unknown): Promise<void>;
|
|
15
|
+
deleteCheckpoint(id: string): Promise<void>;
|
|
16
|
+
getCheckpoint(id: string): Promise<unknown | null>;
|
|
17
|
+
}
|