@webiny/migrations 5.43.0-beta.0 → 5.43.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/ddb-es.d.ts +2 -2
- package/ddb-es.js +2 -2
- package/ddb-es.js.map +1 -1
- package/ddb.d.ts +2 -2
- package/ddb.js +2 -2
- package/ddb.js.map +1 -1
- package/migrations/5.43.0/001/constants.d.ts +2 -0
- package/migrations/5.43.0/001/constants.js +10 -0
- package/migrations/5.43.0/001/constants.js.map +1 -0
- package/migrations/{5.41.0/001 → 5.43.0/001/ddb}/index.d.ts +6 -4
- package/migrations/5.43.0/001/ddb/index.js +215 -0
- package/migrations/5.43.0/001/ddb/index.js.map +1 -0
- package/migrations/5.43.0/001/ddb-es/index.d.ts +16 -0
- package/migrations/5.43.0/001/ddb-es/index.js +257 -0
- package/migrations/5.43.0/001/ddb-es/index.js.map +1 -0
- package/migrations/5.43.0/001/entities/createEntryEntity.d.ts +89 -0
- package/migrations/5.43.0/001/entities/createEntryEntity.js +188 -0
- package/migrations/5.43.0/001/entities/createEntryEntity.js.map +1 -0
- package/migrations/5.43.0/001/types.d.ts +47 -0
- package/migrations/5.43.0/001/types.js +7 -0
- package/migrations/5.43.0/001/types.js.map +1 -0
- package/package.json +17 -17
- package/utils/getCompressedData.d.ts +4 -0
- package/utils/getCompressedData.js +19 -0
- package/utils/getCompressedData.js.map +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +11 -0
- package/utils/index.js.map +1 -1
- package/migrations/5.41.0/001/createTenantEntity.d.ts +0 -42
- package/migrations/5.41.0/001/createTenantEntity.js +0 -46
- package/migrations/5.41.0/001/createTenantEntity.js.map +0 -1
- package/migrations/5.41.0/001/createUserEntity.d.ts +0 -48
- package/migrations/5.41.0/001/createUserEntity.js +0 -54
- package/migrations/5.41.0/001/createUserEntity.js.map +0 -1
- package/migrations/5.41.0/001/index.js +0 -92
- package/migrations/5.41.0/001/index.js.map +0 -1
package/ddb-es.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const migrations: () => (typeof
|
|
1
|
+
import { Flp_5_43_0_001 } from "./migrations/5.43.0/001/ddb-es";
|
|
2
|
+
export declare const migrations: () => (typeof Flp_5_43_0_001)[];
|
package/ddb-es.js
CHANGED
|
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.migrations = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _ddbEs = require("./migrations/5.43.0/001/ddb-es");
|
|
8
8
|
// We only list current version migrations here. No need to have them all
|
|
9
9
|
// listed, as we only need the latest version migrations to be executed.
|
|
10
10
|
// This also helps with keeping the bundle size down / faster boot times.
|
|
11
11
|
|
|
12
12
|
const migrations = () => {
|
|
13
|
-
return [
|
|
13
|
+
return [_ddbEs.Flp_5_43_0_001];
|
|
14
14
|
};
|
|
15
15
|
exports.migrations = migrations;
|
|
16
16
|
|
package/ddb-es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_ddbEs","require","migrations","Flp_5_43_0_001","exports"],"sources":["ddb-es.ts"],"sourcesContent":["// We only list current version migrations here. No need to have them all\n// listed, as we only need the latest version migrations to be executed.\n// This also helps with keeping the bundle size down / faster boot times.\nimport { Flp_5_43_0_001 } from \"~/migrations/5.43.0/001/ddb-es/\";\n\nexport const migrations = () => {\n return [Flp_5_43_0_001];\n};\n"],"mappings":";;;;;;AAGA,IAAAA,MAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGO,MAAMC,UAAU,GAAGA,CAAA,KAAM;EAC5B,OAAO,CAACC,qBAAc,CAAC;AAC3B,CAAC;AAACC,OAAA,CAAAF,UAAA,GAAAA,UAAA","ignoreList":[]}
|
package/ddb.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const migrations: () => (typeof
|
|
1
|
+
import { Flp_5_43_0_001 } from "./migrations/5.43.0/001/ddb";
|
|
2
|
+
export declare const migrations: () => (typeof Flp_5_43_0_001)[];
|
package/ddb.js
CHANGED
|
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.migrations = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _ddb = require("./migrations/5.43.0/001/ddb");
|
|
8
8
|
// We only list current version migrations here. No need to have them all
|
|
9
9
|
// listed, as we only need the latest version migrations to be executed.
|
|
10
10
|
// This also helps with keeping the bundle size down / faster boot times.
|
|
11
11
|
|
|
12
12
|
const migrations = () => {
|
|
13
|
-
return [
|
|
13
|
+
return [_ddb.Flp_5_43_0_001];
|
|
14
14
|
};
|
|
15
15
|
exports.migrations = migrations;
|
|
16
16
|
|
package/ddb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_ddb","require","migrations","Flp_5_43_0_001","exports"],"sources":["ddb.ts"],"sourcesContent":["// We only list current version migrations here. No need to have them all\n// listed, as we only need the latest version migrations to be executed.\n// This also helps with keeping the bundle size down / faster boot times.\nimport { Flp_5_43_0_001 } from \"~/migrations/5.43.0/001/ddb\";\n\nexport const migrations = () => {\n return [Flp_5_43_0_001];\n};\n"],"mappings":";;;;;;AAGA,IAAAA,IAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGO,MAAMC,UAAU,GAAGA,CAAA,KAAM;EAC5B,OAAO,CAACC,mBAAc,CAAC;AAC3B,CAAC;AAACC,OAAA,CAAAF,UAAA,GAAAA,UAAA","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TASK_MODEL_ID = exports.ACO_FOLDER_MODEL_ID = void 0;
|
|
7
|
+
const ACO_FOLDER_MODEL_ID = exports.ACO_FOLDER_MODEL_ID = "acoFolder";
|
|
8
|
+
const TASK_MODEL_ID = exports.TASK_MODEL_ID = "webinyTask";
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ACO_FOLDER_MODEL_ID","exports","TASK_MODEL_ID"],"sources":["constants.ts"],"sourcesContent":["export const ACO_FOLDER_MODEL_ID = \"acoFolder\";\nexport const TASK_MODEL_ID = \"webinyTask\";\n"],"mappings":";;;;;;AAAO,MAAMA,mBAAmB,GAAAC,OAAA,CAAAD,mBAAA,GAAG,WAAW;AACvC,MAAME,aAAa,GAAAD,OAAA,CAAAC,aAAA,GAAG,YAAY","ignoreList":[]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Table } from "@webiny/db-dynamodb/toolbox";
|
|
2
|
-
import { DataMigrationContext } from "@webiny/data-migration";
|
|
3
|
-
export declare class
|
|
4
|
-
private readonly
|
|
5
|
-
private readonly
|
|
2
|
+
import { DataMigration, DataMigrationContext } from "@webiny/data-migration";
|
|
3
|
+
export declare class Flp_5_43_0_001 implements DataMigration {
|
|
4
|
+
private readonly table;
|
|
5
|
+
private readonly entryEntity;
|
|
6
6
|
constructor(table: Table<string, string, string>);
|
|
7
7
|
getId(): string;
|
|
8
8
|
getDescription(): string;
|
|
9
9
|
shouldExecute({ logger }: DataMigrationContext): Promise<boolean>;
|
|
10
10
|
execute({ logger }: DataMigrationContext): Promise<void>;
|
|
11
|
+
private storeTaskDdbEntry;
|
|
12
|
+
private createRevisionId;
|
|
11
13
|
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Flp_5_43_0_001 = void 0;
|
|
7
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
8
|
+
var _ioc = require("@webiny/ioc");
|
|
9
|
+
var _symbols = require("@webiny/data-migration/symbols");
|
|
10
|
+
var _StepFunctionServicePlugin = require("@webiny/tasks/service/StepFunctionServicePlugin");
|
|
11
|
+
var _createEntryEntity = require("../entities/createEntryEntity");
|
|
12
|
+
var _utils = require("../../../../utils");
|
|
13
|
+
var _constants = require("../constants");
|
|
14
|
+
var _utils2 = require("@webiny/utils");
|
|
15
|
+
class Flp_5_43_0_001 {
|
|
16
|
+
constructor(table) {
|
|
17
|
+
this.table = table;
|
|
18
|
+
this.entryEntity = (0, _createEntryEntity.createDdbEntryEntity)(table);
|
|
19
|
+
}
|
|
20
|
+
getId() {
|
|
21
|
+
return "5.43.0-001";
|
|
22
|
+
}
|
|
23
|
+
getDescription() {
|
|
24
|
+
return "Introduce 'flp' entities";
|
|
25
|
+
}
|
|
26
|
+
async shouldExecute({
|
|
27
|
+
logger
|
|
28
|
+
}) {
|
|
29
|
+
let shouldExecute = false;
|
|
30
|
+
await (0, _utils.forEachTenantLocale)({
|
|
31
|
+
table: this.table,
|
|
32
|
+
logger,
|
|
33
|
+
callback: async ({
|
|
34
|
+
tenantId,
|
|
35
|
+
localeCode
|
|
36
|
+
}) => {
|
|
37
|
+
shouldExecute = true;
|
|
38
|
+
|
|
39
|
+
// Let's find out if there are any folders stored in the system.
|
|
40
|
+
const foldersCount = await (0, _dbDynamodb.count)({
|
|
41
|
+
entity: this.entryEntity,
|
|
42
|
+
partitionKey: `T#${tenantId}#L#${localeCode}#CMS#CME#M#${_constants.ACO_FOLDER_MODEL_ID}#L`,
|
|
43
|
+
options: {
|
|
44
|
+
index: "GSI1"
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (foldersCount === 0) {
|
|
48
|
+
logger.info("No folders found: skipping migration!");
|
|
49
|
+
shouldExecute = false;
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Continue to the next locale.
|
|
54
|
+
return shouldExecute;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return shouldExecute;
|
|
58
|
+
}
|
|
59
|
+
async execute({
|
|
60
|
+
logger
|
|
61
|
+
}) {
|
|
62
|
+
await (0, _utils.forEachTenantLocale)({
|
|
63
|
+
table: this.table,
|
|
64
|
+
logger,
|
|
65
|
+
callback: async ({
|
|
66
|
+
tenantId,
|
|
67
|
+
localeCode
|
|
68
|
+
}) => {
|
|
69
|
+
logger.info(`Starting migration for tenant ${tenantId} / locale ${localeCode}`);
|
|
70
|
+
// Let's find out if there are any folders stored for the current tenant / locale.
|
|
71
|
+
const foldersCount = await (0, _dbDynamodb.count)({
|
|
72
|
+
entity: this.entryEntity,
|
|
73
|
+
partitionKey: `T#${tenantId}#L#${localeCode}#CMS#CME#M#${_constants.ACO_FOLDER_MODEL_ID}#L`,
|
|
74
|
+
options: {
|
|
75
|
+
index: "GSI1"
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (foldersCount === 0) {
|
|
79
|
+
logger.info("No folders found: skipping migration!");
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
const event = {
|
|
83
|
+
tenant: tenantId,
|
|
84
|
+
locale: localeCode,
|
|
85
|
+
id: `5_43_0_001_migration_${(0, _utils2.generateAlphaNumericId)()}`,
|
|
86
|
+
definitionId: "acoSyncFlp",
|
|
87
|
+
name: "5_43_0_001_migration",
|
|
88
|
+
input: {
|
|
89
|
+
type: "*"
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
await this.storeTaskDdbEntry(event);
|
|
93
|
+
const service = new _StepFunctionServicePlugin.StepFunctionService({
|
|
94
|
+
getTenant: () => tenantId,
|
|
95
|
+
getLocale: () => localeCode
|
|
96
|
+
});
|
|
97
|
+
const startTaskExecution = async () => {
|
|
98
|
+
const result = await service.send({
|
|
99
|
+
definitionId: event.definitionId,
|
|
100
|
+
id: event.id
|
|
101
|
+
}, 0);
|
|
102
|
+
if (!result) {
|
|
103
|
+
throw new Error(`Failed to trigger task for tenant ${tenantId} / locale ${localeCode}. Check the above log.`);
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
};
|
|
107
|
+
try {
|
|
108
|
+
await (0, _utils2.executeWithRetry)(startTaskExecution, {
|
|
109
|
+
onFailedAttempt: async error => {
|
|
110
|
+
logger.error(`Attempt #${error.attemptNumber} failed to trigger task for tenant ${tenantId} / locale ${localeCode}.`);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
logger.info(`Successfully triggered task for tenant ${tenantId} / locale ${localeCode}. FLP records will be synced via background task.`);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
logger.error(`Failed to trigger task for tenant ${tenantId} / locale ${localeCode}. Check the above logs for more info.`, e);
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
logger.info("Finished updating all FLP entities across all tenants and locales.");
|
|
121
|
+
}
|
|
122
|
+
async storeTaskDdbEntry(event) {
|
|
123
|
+
const {
|
|
124
|
+
tenant,
|
|
125
|
+
locale,
|
|
126
|
+
id: entryId,
|
|
127
|
+
definitionId,
|
|
128
|
+
name,
|
|
129
|
+
input
|
|
130
|
+
} = event;
|
|
131
|
+
try {
|
|
132
|
+
const values = {
|
|
133
|
+
"number@iterations": 0,
|
|
134
|
+
"text@taskStatus": "pending",
|
|
135
|
+
"text@definitionId": definitionId,
|
|
136
|
+
"text@name": name,
|
|
137
|
+
"object@input": input
|
|
138
|
+
};
|
|
139
|
+
const partitionKey = `T#${tenant}#L#${locale}#CMS#CME#CME#${entryId}`;
|
|
140
|
+
const items = [
|
|
141
|
+
// Exact entry revision
|
|
142
|
+
this.entryEntity.putBatch({
|
|
143
|
+
PK: partitionKey,
|
|
144
|
+
SK: "REV#0001",
|
|
145
|
+
GSI1_PK: `T#${tenant}#L#${locale}#CMS#CME#M#${_constants.TASK_MODEL_ID}#A`,
|
|
146
|
+
GSI1_SK: this.createRevisionId(entryId),
|
|
147
|
+
id: this.createRevisionId(entryId),
|
|
148
|
+
entryId,
|
|
149
|
+
locale,
|
|
150
|
+
location: {
|
|
151
|
+
folderId: "root"
|
|
152
|
+
},
|
|
153
|
+
locked: false,
|
|
154
|
+
modelId: _constants.TASK_MODEL_ID,
|
|
155
|
+
status: "draft",
|
|
156
|
+
tenant,
|
|
157
|
+
TYPE: "cms.entry",
|
|
158
|
+
version: 1,
|
|
159
|
+
modifiedOn: new Date().toISOString(),
|
|
160
|
+
revisionCreatedOn: new Date().toISOString(),
|
|
161
|
+
revisionModifiedOn: new Date().toISOString(),
|
|
162
|
+
revisionSavedOn: new Date().toISOString(),
|
|
163
|
+
savedOn: new Date().toISOString(),
|
|
164
|
+
createdOn: new Date().toISOString(),
|
|
165
|
+
webinyVersion: process.env.WEBINY_VERSION,
|
|
166
|
+
values
|
|
167
|
+
}),
|
|
168
|
+
// Latest entry revision
|
|
169
|
+
this.entryEntity.putBatch({
|
|
170
|
+
PK: partitionKey,
|
|
171
|
+
SK: "L",
|
|
172
|
+
GSI1_PK: `T#${tenant}#L#${locale}#CMS#CME#M#${_constants.TASK_MODEL_ID}#L`,
|
|
173
|
+
GSI1_SK: this.createRevisionId(entryId),
|
|
174
|
+
id: this.createRevisionId(entryId),
|
|
175
|
+
entryId,
|
|
176
|
+
locale,
|
|
177
|
+
location: {
|
|
178
|
+
folderId: "root"
|
|
179
|
+
},
|
|
180
|
+
locked: false,
|
|
181
|
+
meta: {},
|
|
182
|
+
modelId: _constants.TASK_MODEL_ID,
|
|
183
|
+
modifiedOn: new Date().toISOString(),
|
|
184
|
+
revisionCreatedOn: new Date().toISOString(),
|
|
185
|
+
revisionModifiedOn: new Date().toISOString(),
|
|
186
|
+
revisionSavedOn: new Date().toISOString(),
|
|
187
|
+
savedOn: new Date().toISOString(),
|
|
188
|
+
createdOn: new Date().toISOString(),
|
|
189
|
+
status: "draft",
|
|
190
|
+
tenant,
|
|
191
|
+
TYPE: "cms.entry.l",
|
|
192
|
+
version: 1,
|
|
193
|
+
webinyVersion: process.env.WEBINY_VERSION,
|
|
194
|
+
values
|
|
195
|
+
})];
|
|
196
|
+
await (0, _utils.batchWriteAll)({
|
|
197
|
+
items,
|
|
198
|
+
table: this.entryEntity.table
|
|
199
|
+
});
|
|
200
|
+
} catch (e) {
|
|
201
|
+
console.log("Error while storing task entry.", event);
|
|
202
|
+
console.error(e);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
createRevisionId(id) {
|
|
206
|
+
const {
|
|
207
|
+
id: entryId
|
|
208
|
+
} = (0, _utils2.parseIdentifier)(id);
|
|
209
|
+
return `${entryId}#0001`;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.Flp_5_43_0_001 = Flp_5_43_0_001;
|
|
213
|
+
(0, _ioc.makeInjectable)(Flp_5_43_0_001, [(0, _ioc.inject)(_symbols.PrimaryDynamoTableSymbol)]);
|
|
214
|
+
|
|
215
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_dbDynamodb","require","_ioc","_symbols","_StepFunctionServicePlugin","_createEntryEntity","_utils","_constants","_utils2","Flp_5_43_0_001","constructor","table","entryEntity","createDdbEntryEntity","getId","getDescription","shouldExecute","logger","forEachTenantLocale","callback","tenantId","localeCode","foldersCount","count","entity","partitionKey","ACO_FOLDER_MODEL_ID","options","index","info","execute","event","tenant","locale","id","generateAlphaNumericId","definitionId","name","input","type","storeTaskDdbEntry","service","StepFunctionService","getTenant","getLocale","startTaskExecution","result","send","Error","executeWithRetry","onFailedAttempt","error","attemptNumber","e","entryId","values","items","putBatch","PK","SK","GSI1_PK","TASK_MODEL_ID","GSI1_SK","createRevisionId","location","folderId","locked","modelId","status","TYPE","version","modifiedOn","Date","toISOString","revisionCreatedOn","revisionModifiedOn","revisionSavedOn","savedOn","createdOn","webinyVersion","process","env","WEBINY_VERSION","meta","batchWriteAll","console","log","parseIdentifier","exports","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["index.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { count } from \"@webiny/db-dynamodb\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { DataMigration, DataMigrationContext } from \"@webiny/data-migration\";\nimport { PrimaryDynamoTableSymbol } from \"@webiny/data-migration/symbols\";\nimport { StepFunctionService } from \"@webiny/tasks/service/StepFunctionServicePlugin\";\nimport { createDdbEntryEntity } from \"../entities/createEntryEntity\";\nimport { forEachTenantLocale, batchWriteAll } from \"~/utils\";\nimport { ACO_FOLDER_MODEL_ID, TASK_MODEL_ID } from \"../constants\";\nimport { generateAlphaNumericId, parseIdentifier, executeWithRetry } from \"@webiny/utils\";\nimport type { TaskEntryEventPayload } from \"../types\";\n\nexport class Flp_5_43_0_001 implements DataMigration {\n private readonly table: Table<string, string, string>;\n private readonly entryEntity: ReturnType<typeof createDdbEntryEntity>;\n\n constructor(table: Table<string, string, string>) {\n this.table = table;\n this.entryEntity = createDdbEntryEntity(table);\n }\n\n getId() {\n return \"5.43.0-001\";\n }\n\n getDescription() {\n return \"Introduce 'flp' entities\";\n }\n\n async shouldExecute({ logger }: DataMigrationContext) {\n let shouldExecute = false;\n\n await forEachTenantLocale({\n table: this.table,\n logger,\n callback: async ({ tenantId, localeCode }) => {\n shouldExecute = true;\n\n // Let's find out if there are any folders stored in the system.\n const foldersCount = await count({\n entity: this.entryEntity,\n partitionKey: `T#${tenantId}#L#${localeCode}#CMS#CME#M#${ACO_FOLDER_MODEL_ID}#L`,\n options: {\n index: \"GSI1\"\n }\n });\n\n if (foldersCount === 0) {\n logger.info(\"No folders found: skipping migration!\");\n shouldExecute = false;\n return false;\n }\n\n // Continue to the next locale.\n return shouldExecute;\n }\n });\n\n return shouldExecute;\n }\n\n async execute({ logger }: DataMigrationContext) {\n await forEachTenantLocale({\n table: this.table,\n logger,\n callback: async ({ tenantId, localeCode }) => {\n logger.info(`Starting migration for tenant ${tenantId} / locale ${localeCode}`);\n // Let's find out if there are any folders stored for the current tenant / locale.\n const foldersCount = await count({\n entity: this.entryEntity,\n partitionKey: `T#${tenantId}#L#${localeCode}#CMS#CME#M#${ACO_FOLDER_MODEL_ID}#L`,\n options: {\n index: \"GSI1\"\n }\n });\n\n if (foldersCount === 0) {\n logger.info(\"No folders found: skipping migration!\");\n return true;\n }\n\n const event: TaskEntryEventPayload = {\n tenant: tenantId,\n locale: localeCode,\n id: `5_43_0_001_migration_${generateAlphaNumericId()}`,\n definitionId: \"acoSyncFlp\",\n name: \"5_43_0_001_migration\",\n input: {\n type: \"*\"\n }\n };\n\n await this.storeTaskDdbEntry(event);\n\n const service = new StepFunctionService({\n getTenant: () => tenantId,\n getLocale: () => localeCode\n });\n\n const startTaskExecution = async () => {\n const result = await service.send(\n {\n definitionId: event.definitionId,\n id: event.id\n },\n 0\n );\n\n if (!result) {\n throw new Error(\n `Failed to trigger task for tenant ${tenantId} / locale ${localeCode}. Check the above log.`\n );\n }\n\n return result;\n };\n\n try {\n await executeWithRetry(startTaskExecution, {\n onFailedAttempt: async error => {\n logger.error(\n `Attempt #${error.attemptNumber} failed to trigger task for tenant ${tenantId} / locale ${localeCode}.`\n );\n }\n });\n\n logger.info(\n `Successfully triggered task for tenant ${tenantId} / locale ${localeCode}. FLP records will be synced via background task.`\n );\n } catch (e) {\n logger.error(\n `Failed to trigger task for tenant ${tenantId} / locale ${localeCode}. Check the above logs for more info.`,\n e\n );\n }\n\n return true;\n }\n });\n\n logger.info(\"Finished updating all FLP entities across all tenants and locales.\");\n }\n\n private async storeTaskDdbEntry(event: TaskEntryEventPayload): Promise<void> {\n const { tenant, locale, id: entryId, definitionId, name, input } = event;\n\n try {\n const values = {\n \"number@iterations\": 0,\n \"text@taskStatus\": \"pending\",\n \"text@definitionId\": definitionId,\n \"text@name\": name,\n \"object@input\": input\n };\n\n const partitionKey = `T#${tenant}#L#${locale}#CMS#CME#CME#${entryId}`;\n\n const items = [\n // Exact entry revision\n this.entryEntity.putBatch({\n PK: partitionKey,\n SK: \"REV#0001\",\n GSI1_PK: `T#${tenant}#L#${locale}#CMS#CME#M#${TASK_MODEL_ID}#A`,\n GSI1_SK: this.createRevisionId(entryId),\n id: this.createRevisionId(entryId),\n entryId,\n locale,\n location: {\n folderId: \"root\"\n },\n locked: false,\n modelId: TASK_MODEL_ID,\n status: \"draft\",\n tenant,\n TYPE: \"cms.entry\",\n version: 1,\n modifiedOn: new Date().toISOString(),\n revisionCreatedOn: new Date().toISOString(),\n revisionModifiedOn: new Date().toISOString(),\n revisionSavedOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdOn: new Date().toISOString(),\n webinyVersion: process.env.WEBINY_VERSION,\n values\n }),\n // Latest entry revision\n this.entryEntity.putBatch({\n PK: partitionKey,\n SK: \"L\",\n GSI1_PK: `T#${tenant}#L#${locale}#CMS#CME#M#${TASK_MODEL_ID}#L`,\n GSI1_SK: this.createRevisionId(entryId),\n id: this.createRevisionId(entryId),\n entryId,\n locale,\n location: {\n folderId: \"root\"\n },\n locked: false,\n meta: {},\n modelId: TASK_MODEL_ID,\n modifiedOn: new Date().toISOString(),\n revisionCreatedOn: new Date().toISOString(),\n revisionModifiedOn: new Date().toISOString(),\n revisionSavedOn: new Date().toISOString(),\n savedOn: new Date().toISOString(),\n createdOn: new Date().toISOString(),\n status: \"draft\",\n tenant,\n TYPE: \"cms.entry.l\",\n version: 1,\n webinyVersion: process.env.WEBINY_VERSION,\n values\n })\n ];\n\n await batchWriteAll({\n items,\n table: this.entryEntity.table\n });\n } catch (e) {\n console.log(\"Error while storing task entry.\", event);\n console.error(e);\n }\n }\n\n private createRevisionId(id: string) {\n const { id: entryId } = parseIdentifier(id);\n return `${entryId}#0001`;\n }\n}\n\nmakeInjectable(Flp_5_43_0_001, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":";;;;;;AACA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAE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reList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Table } from "@webiny/db-dynamodb/toolbox";
|
|
2
|
+
import { Client } from "@elastic/elasticsearch";
|
|
3
|
+
import { DataMigration, DataMigrationContext } from "@webiny/data-migration";
|
|
4
|
+
export declare class Flp_5_43_0_001 implements DataMigration {
|
|
5
|
+
private readonly table;
|
|
6
|
+
private readonly elasticsearchClient;
|
|
7
|
+
private readonly ddbEntryEntity;
|
|
8
|
+
private readonly ddbEsEntryEntity;
|
|
9
|
+
constructor(table: Table<string, string, string>, esTable: Table<string, string, string>, elasticsearchClient: Client);
|
|
10
|
+
getId(): string;
|
|
11
|
+
getDescription(): string;
|
|
12
|
+
shouldExecute({ logger }: DataMigrationContext): Promise<boolean>;
|
|
13
|
+
execute({ logger }: DataMigrationContext): Promise<void>;
|
|
14
|
+
private storeTaskDdbEntry;
|
|
15
|
+
private createRevisionId;
|
|
16
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Flp_5_43_0_001 = void 0;
|
|
7
|
+
var _ioc = require("@webiny/ioc");
|
|
8
|
+
var _symbols = require("@webiny/data-migration/symbols");
|
|
9
|
+
var _utils = require("../../../../utils");
|
|
10
|
+
var _createEntryEntity = require("../entities/createEntryEntity");
|
|
11
|
+
var _constants = require("../constants");
|
|
12
|
+
var _utils2 = require("@webiny/utils");
|
|
13
|
+
var _StepFunctionServicePlugin = require("@webiny/tasks/service/StepFunctionServicePlugin");
|
|
14
|
+
class Flp_5_43_0_001 {
|
|
15
|
+
constructor(table, esTable, elasticsearchClient) {
|
|
16
|
+
this.table = table;
|
|
17
|
+
this.elasticsearchClient = elasticsearchClient;
|
|
18
|
+
this.ddbEntryEntity = (0, _createEntryEntity.createDdbEntryEntity)(table);
|
|
19
|
+
this.ddbEsEntryEntity = (0, _createEntryEntity.createDdbEsEntryEntity)(esTable);
|
|
20
|
+
}
|
|
21
|
+
getId() {
|
|
22
|
+
return "5.43.0-001";
|
|
23
|
+
}
|
|
24
|
+
getDescription() {
|
|
25
|
+
return "Introduce 'flp' entities";
|
|
26
|
+
}
|
|
27
|
+
async shouldExecute({
|
|
28
|
+
logger
|
|
29
|
+
}) {
|
|
30
|
+
let shouldExecute = false;
|
|
31
|
+
await (0, _utils.forEachTenantLocale)({
|
|
32
|
+
table: this.table,
|
|
33
|
+
logger,
|
|
34
|
+
callback: async ({
|
|
35
|
+
tenantId,
|
|
36
|
+
localeCode
|
|
37
|
+
}) => {
|
|
38
|
+
shouldExecute = true;
|
|
39
|
+
const indexExists = await (0, _utils.esGetIndexExist)({
|
|
40
|
+
elasticsearchClient: this.elasticsearchClient,
|
|
41
|
+
tenant: tenantId,
|
|
42
|
+
locale: localeCode,
|
|
43
|
+
type: _constants.ACO_FOLDER_MODEL_ID,
|
|
44
|
+
isHeadlessCmsModel: true
|
|
45
|
+
});
|
|
46
|
+
if (!indexExists) {
|
|
47
|
+
logger.info(`No Elasticsearch index found for folders in tenant "${tenantId}" and locale "${localeCode}"; skipping.`);
|
|
48
|
+
shouldExecute = false;
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Continue to the next locale.
|
|
53
|
+
return shouldExecute;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return shouldExecute;
|
|
57
|
+
}
|
|
58
|
+
async execute({
|
|
59
|
+
logger
|
|
60
|
+
}) {
|
|
61
|
+
await (0, _utils.forEachTenantLocale)({
|
|
62
|
+
table: this.table,
|
|
63
|
+
logger,
|
|
64
|
+
callback: async ({
|
|
65
|
+
tenantId,
|
|
66
|
+
localeCode
|
|
67
|
+
}) => {
|
|
68
|
+
logger.info(`Starting migration for tenant ${tenantId} / locale ${localeCode}`);
|
|
69
|
+
const indexExists = await (0, _utils.esGetIndexExist)({
|
|
70
|
+
elasticsearchClient: this.elasticsearchClient,
|
|
71
|
+
tenant: tenantId,
|
|
72
|
+
locale: localeCode,
|
|
73
|
+
type: _constants.ACO_FOLDER_MODEL_ID,
|
|
74
|
+
isHeadlessCmsModel: true
|
|
75
|
+
});
|
|
76
|
+
if (!indexExists) {
|
|
77
|
+
logger.info(`No Elasticsearch index found for folders in tenant "${tenantId}" and locale "${localeCode}"; skipping.`);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
const event = {
|
|
81
|
+
tenant: tenantId,
|
|
82
|
+
locale: localeCode,
|
|
83
|
+
id: `5_43_0_001_migration_${(0, _utils2.generateAlphaNumericId)()}`,
|
|
84
|
+
definitionId: "acoSyncFlp",
|
|
85
|
+
name: "5_43_0_001_migration",
|
|
86
|
+
input: {
|
|
87
|
+
type: "*"
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
await this.storeTaskDdbEntry(event);
|
|
91
|
+
const service = new _StepFunctionServicePlugin.StepFunctionService({
|
|
92
|
+
getTenant: () => tenantId,
|
|
93
|
+
getLocale: () => localeCode
|
|
94
|
+
});
|
|
95
|
+
const startTaskExecution = async () => {
|
|
96
|
+
const result = await service.send({
|
|
97
|
+
definitionId: event.definitionId,
|
|
98
|
+
id: event.id
|
|
99
|
+
}, 0);
|
|
100
|
+
if (!result) {
|
|
101
|
+
throw new Error(`Failed to trigger task for tenant ${tenantId} / locale ${localeCode}. Check the above log.`);
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
};
|
|
105
|
+
try {
|
|
106
|
+
await (0, _utils2.executeWithRetry)(startTaskExecution, {
|
|
107
|
+
onFailedAttempt: async error => {
|
|
108
|
+
logger.error(`Attempt #${error.attemptNumber} failed to trigger task for tenant ${tenantId} / locale ${localeCode}.`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
logger.info(`Successfully triggered task for tenant ${tenantId} / locale ${localeCode}. FLP records will be synced via background task.`);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
logger.error(`Failed to trigger task for tenant ${tenantId} / locale ${localeCode}. Check the above logs for more info.`, e);
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
logger.info("Finished updating all FLP entities across all tenants and locales.");
|
|
119
|
+
}
|
|
120
|
+
async storeTaskDdbEntry(event) {
|
|
121
|
+
const {
|
|
122
|
+
tenant,
|
|
123
|
+
locale,
|
|
124
|
+
id: entryId,
|
|
125
|
+
definitionId,
|
|
126
|
+
name,
|
|
127
|
+
input
|
|
128
|
+
} = event;
|
|
129
|
+
try {
|
|
130
|
+
const values = {
|
|
131
|
+
"number@iterations": 0,
|
|
132
|
+
"text@taskStatus": "pending",
|
|
133
|
+
"text@definitionId": definitionId,
|
|
134
|
+
"text@name": name,
|
|
135
|
+
"object@input": input
|
|
136
|
+
};
|
|
137
|
+
const partitionKey = `T#${tenant}#L#${locale}#CMS#CME#${entryId}`;
|
|
138
|
+
const ddbItems = [
|
|
139
|
+
// Exact entry revision
|
|
140
|
+
this.ddbEntryEntity.putBatch({
|
|
141
|
+
PK: partitionKey,
|
|
142
|
+
SK: "REV#0001",
|
|
143
|
+
id: this.createRevisionId(entryId),
|
|
144
|
+
entryId,
|
|
145
|
+
locale,
|
|
146
|
+
location: {
|
|
147
|
+
folderId: "root"
|
|
148
|
+
},
|
|
149
|
+
locked: false,
|
|
150
|
+
meta: {},
|
|
151
|
+
modelId: _constants.TASK_MODEL_ID,
|
|
152
|
+
status: "draft",
|
|
153
|
+
tenant,
|
|
154
|
+
TYPE: "cms.entry",
|
|
155
|
+
version: 1,
|
|
156
|
+
webinyVersion: process.env.WEBINY_VERSION,
|
|
157
|
+
modifiedOn: new Date().toISOString(),
|
|
158
|
+
revisionCreatedOn: new Date().toISOString(),
|
|
159
|
+
revisionModifiedOn: new Date().toISOString(),
|
|
160
|
+
revisionSavedOn: new Date().toISOString(),
|
|
161
|
+
savedOn: new Date().toISOString(),
|
|
162
|
+
createdOn: new Date().toISOString(),
|
|
163
|
+
values
|
|
164
|
+
}),
|
|
165
|
+
// Latest entry revision
|
|
166
|
+
this.ddbEntryEntity.putBatch({
|
|
167
|
+
PK: partitionKey,
|
|
168
|
+
SK: "L",
|
|
169
|
+
id: this.createRevisionId(entryId),
|
|
170
|
+
entryId,
|
|
171
|
+
locale,
|
|
172
|
+
location: {
|
|
173
|
+
folderId: "root"
|
|
174
|
+
},
|
|
175
|
+
locked: false,
|
|
176
|
+
meta: {},
|
|
177
|
+
modelId: _constants.TASK_MODEL_ID,
|
|
178
|
+
status: "draft",
|
|
179
|
+
tenant,
|
|
180
|
+
TYPE: "cms.entry.l",
|
|
181
|
+
version: 1,
|
|
182
|
+
webinyVersion: process.env.WEBINY_VERSION,
|
|
183
|
+
modifiedOn: new Date().toISOString(),
|
|
184
|
+
revisionCreatedOn: new Date().toISOString(),
|
|
185
|
+
revisionModifiedOn: new Date().toISOString(),
|
|
186
|
+
revisionSavedOn: new Date().toISOString(),
|
|
187
|
+
savedOn: new Date().toISOString(),
|
|
188
|
+
createdOn: new Date().toISOString(),
|
|
189
|
+
values
|
|
190
|
+
})];
|
|
191
|
+
const rawDatas = {
|
|
192
|
+
modelId: _constants.TASK_MODEL_ID,
|
|
193
|
+
revisionCreatedOn: new Date().toISOString(),
|
|
194
|
+
revisionSavedOn: new Date().toString(),
|
|
195
|
+
revisionModifiedOn: new Date().toString(),
|
|
196
|
+
createdOn: new Date().toString(),
|
|
197
|
+
modifiedOn: new Date().toString(),
|
|
198
|
+
status: "draft",
|
|
199
|
+
meta: {},
|
|
200
|
+
entryId,
|
|
201
|
+
id: this.createRevisionId(entryId),
|
|
202
|
+
version: 1,
|
|
203
|
+
location: {
|
|
204
|
+
folderId: "root"
|
|
205
|
+
},
|
|
206
|
+
locale,
|
|
207
|
+
values: {
|
|
208
|
+
"number@iterations": 0,
|
|
209
|
+
"text@taskStatus": "pending",
|
|
210
|
+
"text@definitionId": definitionId,
|
|
211
|
+
"text@name": name
|
|
212
|
+
},
|
|
213
|
+
tenant,
|
|
214
|
+
locked: false,
|
|
215
|
+
webinyVersion: process.env.WEBINY_VERSION,
|
|
216
|
+
latest: true,
|
|
217
|
+
TYPE: "cms.entry.l",
|
|
218
|
+
__type: "cms.entry.l",
|
|
219
|
+
rawValues: {
|
|
220
|
+
"object@input": input
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
const ddbEsItems = [this.ddbEsEntryEntity.putBatch({
|
|
224
|
+
PK: partitionKey,
|
|
225
|
+
SK: "L",
|
|
226
|
+
data: await (0, _utils.getCompressedData)(rawDatas),
|
|
227
|
+
index: (0, _utils.esGetIndexName)({
|
|
228
|
+
tenant,
|
|
229
|
+
locale,
|
|
230
|
+
type: _constants.TASK_MODEL_ID,
|
|
231
|
+
isHeadlessCmsModel: true
|
|
232
|
+
})
|
|
233
|
+
})];
|
|
234
|
+
await (0, _utils.batchWriteAll)({
|
|
235
|
+
table: this.ddbEntryEntity.table,
|
|
236
|
+
items: ddbItems
|
|
237
|
+
});
|
|
238
|
+
await (0, _utils.batchWriteAll)({
|
|
239
|
+
table: this.ddbEsEntryEntity.table,
|
|
240
|
+
items: ddbEsItems
|
|
241
|
+
});
|
|
242
|
+
} catch (e) {
|
|
243
|
+
console.log("Error while storing task entry.", event);
|
|
244
|
+
console.error(e);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
createRevisionId(id) {
|
|
248
|
+
const {
|
|
249
|
+
id: entryId
|
|
250
|
+
} = (0, _utils2.parseIdentifier)(id);
|
|
251
|
+
return `${entryId}#0001`;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
exports.Flp_5_43_0_001 = Flp_5_43_0_001;
|
|
255
|
+
(0, _ioc.makeInjectable)(Flp_5_43_0_001, [(0, _ioc.inject)(_symbols.PrimaryDynamoTableSymbol), (0, _ioc.inject)(_symbols.ElasticsearchDynamoTableSymbol), (0, _ioc.inject)(_symbols.ElasticsearchClientSymbol)]);
|
|
256
|
+
|
|
257
|
+
//# sourceMappingURL=index.js.map
|