@webiny/migrations 5.41.4-beta.3 → 5.41.4-beta.5

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.
@@ -136,8 +136,11 @@ class FileManager_5_35_0_001_FileData {
136
136
  });
137
137
  });
138
138
  const execute = () => {
139
- return Promise.all((0, _chunk.default)(items, 200).map(fileChunk => {
140
- return (0, _utils2.batchWriteAll)({
139
+ return Promise.all((0, _chunk.default)(items, 200).map(async fileChunk => {
140
+ /**
141
+ * Leave batch write for now.
142
+ */
143
+ return await (0, _utils2.batchWriteAll)({
141
144
  table: this.newFileEntity.table,
142
145
  items: fileChunk
143
146
  });
@@ -1 +1 @@
1
- {"version":3,"names":["_chunk","_interopRequireDefault","require","_utils","_utils2","_createFileEntity","_createLocaleEntity","_createTenantEntity","isGroupMigrationCompleted","status","FileManager_5_35_0_001_FileData","constructor","table","elasticsearchClient","newFileEntity","createStandardEntity","legacyAttributes","tenantEntity","createTenantEntity","localeEntity","createLocaleEntity","getId","getDescription","shouldExecute","logger","checkpoint","defaultLocale","queryOne","entity","partitionKey","options","eq","info","PK","code","newFile","gt","index","execute","context","tenants","queryAll","migrationStatus","tenant","locales","id","locale","groupId","batch","esQueryAllWithCallback","esGetIndexName","type","body","query","bool","filter","term","size","sort","search_after","callback","files","cursor","length","items","map","file","putBatch","SK","GSI1_PK","GSI1_SK","TYPE","getFileData","data","webinyVersion","process","env","WEBINY_VERSION","Promise","all","chunk","fileChunk","batchWriteAll","executeWithRetry","onFailedAttempt","error","attemptNumber","message","runningOutOfTime","createCheckpointAndExit","createCheckpoint","exports"],"sources":["FileDataMigration.ts"],"sourcesContent":["import chunk from \"lodash/chunk\";\nimport { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { PrimitiveValue } from \"@webiny/api-elasticsearch/types\";\nimport { executeWithRetry } from \"@webiny/utils\";\nimport { DataMigration, DataMigrationContext } from \"@webiny/data-migration\";\nimport {\n createStandardEntity,\n queryOne,\n queryAll,\n batchWriteAll,\n esQueryAllWithCallback,\n esGetIndexName\n} from \"~/utils\";\nimport { createFileEntity, getFileData, legacyAttributes } from \"../entities/createFileEntity\";\nimport { createLocaleEntity } from \"../entities/createLocaleEntity\";\nimport { createTenantEntity } from \"../entities/createTenantEntity\";\nimport { File } from \"../types\";\n\ntype FileMigrationCheckpoint = Record<string, PrimitiveValue[] | boolean | undefined>;\n\nconst isGroupMigrationCompleted = (\n status: PrimitiveValue[] | boolean | undefined\n): status is boolean => {\n return typeof status === \"boolean\";\n};\n\nexport class FileManager_5_35_0_001_FileData implements DataMigration<FileMigrationCheckpoint> {\n private readonly elasticsearchClient: Client;\n private readonly newFileEntity: ReturnType<typeof createFileEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n private readonly localeEntity: ReturnType<typeof createLocaleEntity>;\n\n constructor(table: Table<string, string, string>, elasticsearchClient: Client) {\n this.elasticsearchClient = elasticsearchClient;\n this.newFileEntity = createStandardEntity(table, \"File\", legacyAttributes);\n this.tenantEntity = createTenantEntity(table);\n this.localeEntity = createLocaleEntity(table);\n }\n\n getId() {\n return \"FileData\";\n }\n\n getDescription() {\n return \"\";\n }\n\n async shouldExecute({ logger, checkpoint }: DataMigrationContext): Promise<boolean> {\n if (checkpoint) {\n return true;\n }\n\n const defaultLocale = await queryOne<{ code: string }>({\n entity: this.localeEntity,\n partitionKey: `T#root#I18N#L#D`,\n options: {\n eq: \"default\"\n }\n });\n\n if (!defaultLocale) {\n logger.info(`Default locale not found; system is not yet installed.`);\n // The system is not yet installed, skip migration.\n return false;\n }\n\n // Check if there are files stored in the GSI1 index, which means files are already migrated.\n const PK = `T#root#L#${defaultLocale.code}#FM#FILES`;\n const newFile = await queryOne<{ id: string }>({\n entity: this.newFileEntity,\n partitionKey: PK,\n options: { gt: \" \", index: \"GSI1\" }\n });\n\n if (newFile) {\n logger.info(`Looks like files have already been migrated. Skipping migration.`);\n return false;\n }\n\n return true;\n }\n\n async execute({\n logger,\n ...context\n }: DataMigrationContext<FileMigrationCheckpoint>): Promise<void> {\n const tenants = await queryAll<{ id: string }>({\n entity: this.tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n const migrationStatus: FileMigrationCheckpoint = context.checkpoint || {};\n\n for (const tenant of tenants) {\n const locales = await queryAll<{ code: string }>({\n entity: this.localeEntity,\n partitionKey: `T#${tenant.id}#I18N#L`,\n options: {\n gt: \" \"\n }\n });\n\n for (const locale of locales) {\n const groupId = `${tenant.id}:${locale.code}`;\n const status = migrationStatus[groupId];\n\n if (isGroupMigrationCompleted(status)) {\n continue;\n }\n\n let batch = 0;\n await esQueryAllWithCallback<File>({\n elasticsearchClient: this.elasticsearchClient,\n index: esGetIndexName({\n tenant: tenant.id,\n locale: locale.code,\n type: \"file-manager\"\n }),\n body: {\n query: {\n bool: {\n filter: [\n { term: { \"tenant.keyword\": tenant.id } },\n { term: { \"locale.keyword\": locale.code } }\n ]\n }\n },\n size: 10000,\n sort: [\n {\n \"id.keyword\": \"asc\"\n }\n ],\n search_after: status\n },\n callback: async (files, cursor) => {\n batch++;\n logger.info(\n `Processing batch #${batch} in group ${groupId} (${files.length} files).`\n );\n const items = files.map(file => {\n return this.newFileEntity.putBatch({\n PK: `T#${tenant.id}#L#${locale.code}#FM#F${file.id}`,\n SK: \"A\",\n GSI1_PK: `T#${tenant.id}#L#${locale.code}#FM#FILES`,\n GSI1_SK: file.id,\n TYPE: \"fm.file\",\n ...getFileData(file),\n data: {\n ...getFileData(file),\n webinyVersion: process.env.WEBINY_VERSION\n }\n });\n });\n\n const execute = () => {\n return Promise.all(\n chunk(items, 200).map(fileChunk => {\n return batchWriteAll({\n table: this.newFileEntity.table,\n items: fileChunk\n });\n })\n );\n };\n\n await executeWithRetry(execute, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll\" attempt #${error.attemptNumber} failed.`\n );\n logger.error(error.message);\n }\n });\n\n // Update checkpoint after every batch\n migrationStatus[groupId] = cursor;\n\n // Check if we should store checkpoint and exit.\n if (context.runningOutOfTime()) {\n await context.createCheckpointAndExit(migrationStatus);\n } else {\n await context.createCheckpoint(migrationStatus);\n }\n }\n });\n\n migrationStatus[groupId] = true;\n await context.createCheckpoint(migrationStatus);\n }\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AAQA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AACA,IAAAK,mBAAA,GAAAL,OAAA;AAKA,MAAMM,yBAAyB,GAC3BC,MAA8C,IAC1B;EACpB,OAAO,OAAOA,MAAM,KAAK,SAAS;AACtC,CAAC;AAEM,MAAMC,+BAA+B,CAAmD;EAM3FC,WAAWA,CAACC,KAAoC,EAAEC,mBAA2B,EAAE;IAC3E,IAAI,CAACA,mBAAmB,GAAGA,mBAAmB;IAC9C,IAAI,CAACC,aAAa,GAAG,IAAAC,4BAAoB,EAACH,KAAK,EAAE,MAAM,EAAEI,kCAAgB,CAAC;IAC1E,IAAI,CAACC,YAAY,GAAG,IAAAC,sCAAkB,EAACN,KAAK,CAAC;IAC7C,IAAI,CAACO,YAAY,GAAG,IAAAC,sCAAkB,EAACR,KAAK,CAAC;EACjD;EAEAS,KAAKA,CAAA,EAAG;IACJ,OAAO,UAAU;EACrB;EAEAC,cAAcA,CAAA,EAAG;IACb,OAAO,EAAE;EACb;EAEA,MAAMC,aAAaA,CAAC;IAAEC,MAAM;IAAEC;EAAiC,CAAC,EAAoB;IAChF,IAAIA,UAAU,EAAE;MACZ,OAAO,IAAI;IACf;IAEA,MAAMC,aAAa,GAAG,MAAM,IAAAC,gBAAQ,EAAmB;MACnDC,MAAM,EAAE,IAAI,CAACT,YAAY;MACzBU,YAAY,EAAG,iBAAgB;MAC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,OAAO,CAACmD,gBAAgB,CAAChD,eAAe,CAAC;MACnD;IACJ;EACJ;AACJ;AAACiD,OAAA,CAAAjF,+BAAA,GAAAA,+BAAA","ignoreList":[]}
1
+ {"version":3,"names":["_chunk","_interopRequireDefault","require","_utils","_utils2","_createFileEntity","_createLocaleEntity","_createTenantEntity","isGroupMigrationCompleted","status","FileManager_5_35_0_001_FileData","constructor","table","elasticsearchClient","newFileEntity","createStandardEntity","legacyAttributes","tenantEntity","createTenantEntity","localeEntity","createLocaleEntity","getId","getDescription","shouldExecute","logger","checkpoint","defaultLocale","queryOne","entity","partitionKey","options","eq","info","PK","code","newFile","gt","index","execute","context","tenants","queryAll","migrationStatus","tenant","locales","id","locale","groupId","batch","esQueryAllWithCallback","esGetIndexName","type","body","query","bool","filter","term","size","sort","search_after","callback","files","cursor","length","items","map","file","putBatch","SK","GSI1_PK","GSI1_SK","TYPE","getFileData","data","webinyVersion","process","env","WEBINY_VERSION","Promise","all","chunk","fileChunk","batchWriteAll","executeWithRetry","onFailedAttempt","error","attemptNumber","message","runningOutOfTime","createCheckpointAndExit","createCheckpoint","exports"],"sources":["FileDataMigration.ts"],"sourcesContent":["import chunk from \"lodash/chunk\";\nimport { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { PrimitiveValue } from \"@webiny/api-elasticsearch/types\";\nimport { executeWithRetry } from \"@webiny/utils\";\nimport { DataMigration, DataMigrationContext } from \"@webiny/data-migration\";\nimport {\n batchWriteAll,\n createStandardEntity,\n esGetIndexName,\n esQueryAllWithCallback,\n queryAll,\n queryOne\n} from \"~/utils\";\nimport { createFileEntity, getFileData, legacyAttributes } from \"../entities/createFileEntity\";\nimport { createLocaleEntity } from \"../entities/createLocaleEntity\";\nimport { createTenantEntity } from \"../entities/createTenantEntity\";\nimport { File } from \"../types\";\n\ntype FileMigrationCheckpoint = Record<string, PrimitiveValue[] | boolean | undefined>;\n\nconst isGroupMigrationCompleted = (\n status: PrimitiveValue[] | boolean | undefined\n): status is boolean => {\n return typeof status === \"boolean\";\n};\n\nexport class FileManager_5_35_0_001_FileData implements DataMigration<FileMigrationCheckpoint> {\n private readonly elasticsearchClient: Client;\n private readonly newFileEntity: ReturnType<typeof createFileEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n private readonly localeEntity: ReturnType<typeof createLocaleEntity>;\n\n constructor(table: Table<string, string, string>, elasticsearchClient: Client) {\n this.elasticsearchClient = elasticsearchClient;\n this.newFileEntity = createStandardEntity(table, \"File\", legacyAttributes);\n this.tenantEntity = createTenantEntity(table);\n this.localeEntity = createLocaleEntity(table);\n }\n\n getId() {\n return \"FileData\";\n }\n\n getDescription() {\n return \"\";\n }\n\n async shouldExecute({ logger, checkpoint }: DataMigrationContext): Promise<boolean> {\n if (checkpoint) {\n return true;\n }\n\n const defaultLocale = await queryOne<{ code: string }>({\n entity: this.localeEntity,\n partitionKey: `T#root#I18N#L#D`,\n options: {\n eq: \"default\"\n }\n });\n\n if (!defaultLocale) {\n logger.info(`Default locale not found; system is not yet installed.`);\n // The system is not yet installed, skip migration.\n return false;\n }\n\n // Check if there are files stored in the GSI1 index, which means files are already migrated.\n const PK = `T#root#L#${defaultLocale.code}#FM#FILES`;\n const newFile = await queryOne<{ id: string }>({\n entity: this.newFileEntity,\n partitionKey: PK,\n options: { gt: \" \", index: \"GSI1\" }\n });\n\n if (newFile) {\n logger.info(`Looks like files have already been migrated. Skipping migration.`);\n return false;\n }\n\n return true;\n }\n\n async execute({\n logger,\n ...context\n }: DataMigrationContext<FileMigrationCheckpoint>): Promise<void> {\n const tenants = await queryAll<{ id: string }>({\n entity: this.tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n const migrationStatus: FileMigrationCheckpoint = context.checkpoint || {};\n\n for (const tenant of tenants) {\n const locales = await queryAll<{ code: string }>({\n entity: this.localeEntity,\n partitionKey: `T#${tenant.id}#I18N#L`,\n options: {\n gt: \" \"\n }\n });\n\n for (const locale of locales) {\n const groupId = `${tenant.id}:${locale.code}`;\n const status = migrationStatus[groupId];\n\n if (isGroupMigrationCompleted(status)) {\n continue;\n }\n\n let batch = 0;\n await esQueryAllWithCallback<File>({\n elasticsearchClient: this.elasticsearchClient,\n index: esGetIndexName({\n tenant: tenant.id,\n locale: locale.code,\n type: \"file-manager\"\n }),\n body: {\n query: {\n bool: {\n filter: [\n { term: { \"tenant.keyword\": tenant.id } },\n { term: { \"locale.keyword\": locale.code } }\n ]\n }\n },\n size: 10000,\n sort: [\n {\n \"id.keyword\": \"asc\"\n }\n ],\n search_after: status\n },\n callback: async (files, cursor) => {\n batch++;\n logger.info(\n `Processing batch #${batch} in group ${groupId} (${files.length} files).`\n );\n const items = files.map(file => {\n return this.newFileEntity.putBatch({\n PK: `T#${tenant.id}#L#${locale.code}#FM#F${file.id}`,\n SK: \"A\",\n GSI1_PK: `T#${tenant.id}#L#${locale.code}#FM#FILES`,\n GSI1_SK: file.id,\n TYPE: \"fm.file\",\n ...getFileData(file),\n data: {\n ...getFileData(file),\n webinyVersion: process.env.WEBINY_VERSION\n }\n });\n });\n\n const execute = () => {\n return Promise.all(\n chunk(items, 200).map(async fileChunk => {\n /**\n * Leave batch write for now.\n */\n return await batchWriteAll({\n table: this.newFileEntity.table,\n items: fileChunk\n });\n })\n );\n };\n\n await executeWithRetry(execute, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll\" attempt #${error.attemptNumber} failed.`\n );\n logger.error(error.message);\n }\n });\n\n // Update checkpoint after every batch\n migrationStatus[groupId] = cursor;\n\n // Check if we should store checkpoint and exit.\n if (context.runningOutOfTime()) {\n await context.createCheckpointAndExit(migrationStatus);\n } else {\n await context.createCheckpoint(migrationStatus);\n }\n }\n });\n\n migrationStatus[groupId] = true;\n await context.createCheckpoint(migrationStatus);\n }\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;A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AACC,GAAG,CAACC;gBAC/B;cACJ,CAAC,CAAC;YACN,CAAC,CAAC;YAEF,MAAMvC,OAAO,GAAGA,CAAA,KAAM;cAClB,OAAOwC,OAAO,CAACC,GAAG,CACd,IAAAC,cAAK,EAAChB,KAAK,EAAE,GAAG,CAAC,CAACC,GAAG,CAAC,MAAMgB,SAAS,IAAI;gBACrC;AACpC;AACA;gBACoC,OAAO,MAAM,IAAAC,qBAAa,EAAC;kBACvBtE,KAAK,EAAE,IAAI,CAACE,aAAa,CAACF,KAAK;kBAC/BoD,KAAK,EAAEiB;gBACX,CAAC,CAAC;cACN,CAAC,CACL,CAAC;YACL,CAAC;YAED,MAAM,IAAAE,uBAAgB,EAAC7C,OAAO,EAAE;cAC5B8C,eAAe,EAAEC,KAAK,IAAI;gBACtB7D,MAAM,CAAC6D,KAAK,CACP,4BAA2BA,KAAK,CAACC,aAAc,UACpD,CAAC;gBACD9D,MAAM,CAAC6D,KAAK,CAACA,KAAK,CAACE,OAAO,CAAC;cAC/B;YACJ,CAAC,CAAC;;YAEF;YACA7C,eAAe,CAACK,OAAO,CAAC,GAAGe,MAAM;;YAEjC;YACA,IAAIvB,OAAO,CAACiD,gBAAgB,CAAC,CAAC,EAAE;cAC5B,MAAMjD,OAAO,CAACkD,uBAAuB,CAAC/C,eAAe,CAAC;YAC1D,CAAC,MAAM;cACH,MAAMH,OAAO,CAACmD,gBAAgB,CAAChD,eAAe,CAAC;YACnD;UACJ;QACJ,CAAC,CAAC;QAEFA,eAAe,CAACK,OAAO,CAAC,GAAG,IAAI;QAC/B,MAAMR,OAAO,CAACmD,gBAAgB,CAAChD,eAAe,CAAC;MACnD;IACJ;EACJ;AACJ;AAACiD,OAAA,CAAAjF,+BAAA,GAAAA,+BAAA","ignoreList":[]}
@@ -10,6 +10,7 @@ var _createTenantEntity = require("./createTenantEntity");
10
10
  var _createUserEntity = require("./createUserEntity");
11
11
  var _ioc = require("@webiny/ioc");
12
12
  var _utils2 = require("@webiny/utils");
13
+ var _dbDynamodb = require("@webiny/db-dynamodb");
13
14
  class AdminUsers_5_35_0_003 {
14
15
  constructor(table) {
15
16
  this.newUserEntity = (0, _createUserEntity.createUserEntity)(table);
@@ -67,22 +68,24 @@ class AdminUsers_5_35_0_003 {
67
68
  logger.info(`No users found on tenant "${tenant.id}".`);
68
69
  continue;
69
70
  }
70
- const newUsers = users.filter(user => !user.data).map(user => {
71
- return this.newUserEntity.putBatch({
72
- PK: `T#${tenant.id}#ADMIN_USER#${user.id}`,
73
- SK: "A",
74
- GSI1_PK: `T#${tenant.id}#ADMIN_USERS`,
75
- GSI1_SK: user.email,
76
- TYPE: "adminUsers.user",
77
- ...(0, _createUserEntity.getUserData)(user),
78
- // Move all data to a `data` envelope
79
- data: (0, _createUserEntity.getUserData)(user)
80
- });
71
+ const newUsersEntityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
72
+ entity: this.newUserEntity,
73
+ put: users.filter(user => !user.data).map(user => {
74
+ return {
75
+ PK: `T#${tenant.id}#ADMIN_USER#${user.id}`,
76
+ SK: "A",
77
+ GSI1_PK: `T#${tenant.id}#ADMIN_USERS`,
78
+ GSI1_SK: user.email,
79
+ TYPE: "adminUsers.user",
80
+ ...(0, _createUserEntity.getUserData)(user),
81
+ // Move all data to a `data` envelope
82
+ data: (0, _createUserEntity.getUserData)(user)
83
+ };
84
+ })
85
+ });
86
+ await (0, _utils2.executeWithRetry)(async () => {
87
+ return await newUsersEntityBatch.execute();
81
88
  });
82
- await (0, _utils2.executeWithRetry)(() => (0, _utils.batchWriteAll)({
83
- table: this.newUserEntity.table,
84
- items: newUsers
85
- }));
86
89
  }
87
90
  }
88
91
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_dataMigration","require","_utils","_createTenantEntity","_createUserEntity","_ioc","_utils2","AdminUsers_5_35_0_003","constructor","table","newUserEntity","createUserEntity","legacyUserEntity","createLegacyUserEntity","tenantEntity","createTenantEntity","getId","getDescription","shouldExecute","logger","user","queryOne","entity","partitionKey","options","index","gt","info","data","execute","tenants","queryAll","tenant","users","id","length","newUsers","filter","map","putBatch","PK","SK","GSI1_PK","GSI1_SK","email","TYPE","getUserData","executeWithRetry","batchWriteAll","items","exports","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["index.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { DataMigrationContext, PrimaryDynamoTableSymbol } from \"@webiny/data-migration\";\nimport { queryOne, queryAll, batchWriteAll } from \"~/utils\";\nimport { createTenantEntity } from \"./createTenantEntity\";\nimport { createLegacyUserEntity, createUserEntity, getUserData } from \"./createUserEntity\";\nimport { makeInjectable, inject } from \"@webiny/ioc\";\nimport { executeWithRetry } from \"@webiny/utils\";\n\nexport class AdminUsers_5_35_0_003 {\n private readonly newUserEntity: ReturnType<typeof createUserEntity>;\n private readonly legacyUserEntity: ReturnType<typeof createLegacyUserEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n\n constructor(table: Table<string, string, string>) {\n this.newUserEntity = createUserEntity(table);\n this.legacyUserEntity = createLegacyUserEntity(table);\n this.tenantEntity = createTenantEntity(table);\n }\n\n getId() {\n return \"5.35.0-003\";\n }\n\n getDescription() {\n return \"Move admin users attributes to a `data` envelope.\";\n }\n\n async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n const user = await queryOne<{ data: any }>({\n entity: this.newUserEntity,\n partitionKey: `T#root#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n if (!user) {\n logger.info(`No users were found; skipping migration.`);\n return false;\n }\n\n if (user.data) {\n logger.info(`User records seems to be in order; skipping migration.`);\n return false;\n }\n\n return true;\n }\n\n async execute({ logger }: DataMigrationContext): Promise<void> {\n const tenants = await queryAll<{ id: string; name: string }>({\n entity: this.tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n for (const tenant of tenants) {\n const users = await queryAll<{ id: string; email: string; data?: any }>({\n entity: this.legacyUserEntity,\n partitionKey: `T#${tenant.id}#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n if (users.length === 0) {\n logger.info(`No users found on tenant \"${tenant.id}\".`);\n continue;\n }\n\n const newUsers = users\n .filter(user => !user.data)\n .map(user => {\n return this.newUserEntity.putBatch({\n PK: `T#${tenant.id}#ADMIN_USER#${user.id}`,\n SK: \"A\",\n GSI1_PK: `T#${tenant.id}#ADMIN_USERS`,\n GSI1_SK: user.email,\n TYPE: \"adminUsers.user\",\n ...getUserData(user),\n // Move all data to a `data` envelope\n data: getUserData(user)\n });\n });\n\n await executeWithRetry(() =>\n batchWriteAll({ table: this.newUserEntity.table, items: newUsers })\n );\n }\n }\n}\n\nmakeInjectable(AdminUsers_5_35_0_003, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAEO,MAAMM,qBAAqB,CAAC;EAK/BC,WAAWA,CAACC,KAAoC,EAAE;IAC9C,IAAI,CAACC,aAAa,GAAG,IAAAC,kCAAgB,EAACF,KAAK,CAAC;IAC5C,IAAI,CAACG,gBAAgB,GAAG,IAAAC,wCAAsB,EAACJ,KAAK,CAAC;IACrD,IAAI,CAACK,YAAY,GAAG,IAAAC,sCAAkB,EAACN,KAAK,CAAC;EACjD;EAEAO,KAAKA,CAAA,EAAG;IACJ,OAAO,YAAY;EACvB;EAEAC,cAAcA,CAAA,EAAG;IACb,OAAO,mDAAmD;EAC9D;EAEA,MAAMC,aAAaA,CAAC;IAAEC;EAA6B,CAAC,EAAoB;IACpE,MAAMC,IAAI,GAAG,MAAM,IAAAC,eAAQ,EAAgB;MACvCC,MAAM,EAAE,IAAI,CAAC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CAACE,EAAG,eAAcd,IAAI,CAACc,EAAG,EAAC;UAC1CO,EAAE,EAAE,GAAG;UACPC,OAAO,EAAG,KAAIV,MAAM,CAACE,EAAG,cAAa;UACrCS,OAAO,EAAEvB,IAAI,CAACwB,KAAK;UACnBC,IAAI,EAAE,iBAAiB;UACvB,GAAG,IAAAC,6BAAW,EAAC1B,IAAI,CAAC;UACpB;UACAQ,IAAI,EAAE,IAAAkB,6BAAW,EAAC1B,IAAI;QAC1B,CAAC,CAAC;MACN,CAAC,CAAC;MAEN,MAAM,IAAA2B,wBAAgB,EAAC,MACnB,IAAAC,oBAAa,EAAC;QAAEvC,KAAK,EAAE,IAAI,CAACC,aAAa,CAACD,KAAK;QAAEwC,KAAK,EAAEb;MAAS,CAAC,CACtE,CAAC;IACL;EACJ;AACJ;AAACc,OAAA,CAAA3C,qBAAA,GAAAA,qBAAA;AAED,IAAA4C,mBAAc,EAAC5C,qBAAqB,EAAE,CAAC,IAAA6C,WAAM,EAACC,uCAAwB,CAAC,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_dataMigration","require","_utils","_createTenantEntity","_createUserEntity","_ioc","_utils2","_dbDynamodb","AdminUsers_5_35_0_003","constructor","table","newUserEntity","createUserEntity","legacyUserEntity","createLegacyUserEntity","tenantEntity","createTenantEntity","getId","getDescription","shouldExecute","logger","user","queryOne","entity","partitionKey","options","index","gt","info","data","execute","tenants","queryAll","tenant","users","id","length","newUsersEntityBatch","createEntityWriteBatch","put","filter","map","PK","SK","GSI1_PK","GSI1_SK","email","TYPE","getUserData","executeWithRetry","exports","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["index.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { DataMigrationContext, PrimaryDynamoTableSymbol } from \"@webiny/data-migration\";\nimport { queryAll, queryOne } from \"~/utils\";\nimport { createTenantEntity } from \"./createTenantEntity\";\nimport { createLegacyUserEntity, createUserEntity, getUserData } from \"./createUserEntity\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { executeWithRetry } from \"@webiny/utils\";\nimport { createEntityWriteBatch } from \"@webiny/db-dynamodb\";\n\nexport class AdminUsers_5_35_0_003 {\n private readonly newUserEntity: ReturnType<typeof createUserEntity>;\n private readonly legacyUserEntity: ReturnType<typeof createLegacyUserEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n\n constructor(table: Table<string, string, string>) {\n this.newUserEntity = createUserEntity(table);\n this.legacyUserEntity = createLegacyUserEntity(table);\n this.tenantEntity = createTenantEntity(table);\n }\n\n getId() {\n return \"5.35.0-003\";\n }\n\n getDescription() {\n return \"Move admin users attributes to a `data` envelope.\";\n }\n\n async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n const user = await queryOne<{ data: any }>({\n entity: this.newUserEntity,\n partitionKey: `T#root#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n if (!user) {\n logger.info(`No users were found; skipping migration.`);\n return false;\n }\n\n if (user.data) {\n logger.info(`User records seems to be in order; skipping migration.`);\n return false;\n }\n\n return true;\n }\n\n async execute({ logger }: DataMigrationContext): Promise<void> {\n const tenants = await queryAll<{ id: string; name: string }>({\n entity: this.tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n for (const tenant of tenants) {\n const users = await queryAll<{ id: string; email: string; data?: any }>({\n entity: this.legacyUserEntity,\n partitionKey: `T#${tenant.id}#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n if (users.length === 0) {\n logger.info(`No users found on tenant \"${tenant.id}\".`);\n continue;\n }\n\n const newUsersEntityBatch = createEntityWriteBatch({\n entity: this.newUserEntity,\n put: users\n .filter(user => !user.data)\n .map(user => {\n return {\n PK: `T#${tenant.id}#ADMIN_USER#${user.id}`,\n SK: \"A\",\n GSI1_PK: `T#${tenant.id}#ADMIN_USERS`,\n GSI1_SK: user.email,\n TYPE: \"adminUsers.user\",\n ...getUserData(user),\n // Move all data to a `data` envelope\n data: getUserData(user)\n };\n })\n });\n\n await executeWithRetry(async () => {\n return await newUsersEntityBatch.execute();\n });\n }\n }\n}\n\nmakeInjectable(AdminUsers_5_35_0_003, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAEO,MAAMO,qBAAqB,CAAC;EAK/BC,WAAWA,CAACC,KAAoC,EAAE;IAC9C,IAAI,CAACC,aAAa,GAAG,IAAAC,kCAAgB,EAACF,KAAK,CAAC;IAC5C,IAAI,CAACG,gBAAgB,GAAG,IAAAC,wCAAsB,EAACJ,KAAK,CAAC;IACrD,IAAI,CAACK,YAAY,GAAG,IAAAC,sCAAkB,EAACN,KAAK,CAAC;EACjD;EAEAO,KAAKA,CAAA,EAAG;IACJ,OAAO,YAAY;EACvB;EAEAC,cAAcA,CAAA,EAAG;IACb,OAAO,mDAAmD;EAC9D;EAEA,MAAMC,aAAaA,CAAC;IAAEC;EAA6B,CAAC,EAAoB;IACpE,MAAMC,IAAI,GAAG,MAAM,IAAAC,eAAQ,EAAgB;MACvCC,MAAM,EAAE,IAAI,CAACZ,aAAa;MAC1Ba,YAAY,EAAG,oBAAmB;MAClCC,OAAO,EAAE;QACLC,KAAK,EAAE,MAAM;QACbC,EAAE,EAAE;MACR;IACJ,CAAC,CAAC;IAEF,IAAI,CAACN,IAAI,EAAE;MACPD,MAAM,CAACQ,IAAI,CAAE,0CAAyC,CAAC;MACvD,OAAO,KAAK;IAChB;IAEA,IAAIP,IAAI,CAACQ,IAAI,EAAE;MACXT,MAAM,CAACQ,IAAI,CAAE,w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I,EAAE,IAAAmB,6BAAW,EAAC3B,IAAI;UAC1B,CAAC;QACL,CAAC;MACT,CAAC,CAAC;MAEF,MAAM,IAAA4B,wBAAgB,EAAC,YAAY;QAC/B,OAAO,MAAMZ,mBAAmB,CAACP,OAAO,CAAC,CAAC;MAC9C,CAAC,CAAC;IACN;EACJ;AACJ;AAACoB,OAAA,CAAA1C,qBAAA,GAAAA,qBAAA;AAED,IAAA2C,mBAAc,EAAC3C,qBAAqB,EAAE,CAAC,IAAA4C,WAAM,EAACC,uCAAwB,CAAC,CAAC,CAAC","ignoreList":[]}
@@ -14,6 +14,7 @@ var _createLocaleEntity = require("./createLocaleEntity");
14
14
  var _pluralize = _interopRequireDefault(require("pluralize"));
15
15
  var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
16
16
  var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
17
+ var _dbDynamodb = require("@webiny/db-dynamodb");
17
18
  const createSingularApiName = model => {
18
19
  return (0, _upperFirst.default)((0, _camelCase.default)(model.modelId));
19
20
  };
@@ -87,21 +88,21 @@ class CmsModels_5_35_0_005 {
87
88
  logger.info(`No models to be updated; skipping migration.`);
88
89
  return;
89
90
  }
90
- const items = models.map(model => {
91
- return this.modelEntity.putBatch({
92
- ...model,
93
- /**
94
- * Add singular and plural API names.
95
- */
96
- singularApiName: createSingularApiName(model),
97
- pluralApiName: createPluralApiName(model)
98
- });
99
- });
100
- logger.info(`Updating total of ${items.length} models.`);
101
- await (0, _utils.batchWriteAll)({
102
- table: this.modelEntity.table,
103
- items
91
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
92
+ entity: this.modelEntity,
93
+ put: models.map(model => {
94
+ return {
95
+ ...model,
96
+ /**
97
+ * Add singular and plural API names.
98
+ */
99
+ singularApiName: createSingularApiName(model),
100
+ pluralApiName: createPluralApiName(model)
101
+ };
102
+ })
104
103
  });
104
+ logger.info(`Updating total of ${entityBatch.total} models.`);
105
+ await entityBatch.execute();
105
106
  logger.info("Updated all the models.");
106
107
  }
107
108
  async listTenants() {
@@ -1 +1 @@
1
- {"version":3,"names":["_ioc","require","_dataMigration","_utils","_createModelEntity","_createTenantEntity","_createLocaleEntity","_pluralize","_interopRequireDefault","_upperFirst","_camelCase","createSingularApiName","model","upperFirst","camelCase","modelId","createPluralApiName","pluralize","CmsModels_5_35_0_005","constructor","table","modelEntity","createModelEntity","tenantEntity","createTenantEntity","localeEntity","createLocaleEntity","getId","getDescription","shouldExecute","logger","tenants","listTenants","length","info","tenant","locales","listLocales","data","id","locale","models","listModels","filter","singularApiName","pluralApiName","code","execute","items","push","map","putBatch","batchWriteAll","queryAll","entity","partitionKey","options","index","gte","exports","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["index.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { makeInjectable, inject } from \"@webiny/ioc\";\nimport { DataMigrationContext, PrimaryDynamoTableSymbol } from \"@webiny/data-migration\";\nimport { queryAll, batchWriteAll } from \"~/utils\";\nimport { createModelEntity } from \"./createModelEntity\";\nimport { createTenantEntity } from \"./createTenantEntity\";\nimport { createLocaleEntity } from \"./createLocaleEntity\";\nimport { Tenant, I18NLocale, CmsModel } from \"./types\";\nimport pluralize from \"pluralize\";\nimport upperFirst from \"lodash/upperFirst\";\nimport camelCase from \"lodash/camelCase\";\n\nconst createSingularApiName = (model: CmsModel) => {\n return upperFirst(camelCase(model.modelId));\n};\n\nconst createPluralApiName = (model: CmsModel) => {\n return pluralize(createSingularApiName(model));\n};\n\ninterface ListLocalesParams {\n tenant: Tenant;\n}\n\ninterface ListModelsParams {\n tenant: Tenant;\n locale: I18NLocale;\n}\n\nexport class CmsModels_5_35_0_005 {\n private readonly modelEntity: ReturnType<typeof createModelEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n private readonly localeEntity: ReturnType<typeof createLocaleEntity>;\n\n public constructor(table: Table<string, string, string>) {\n this.modelEntity = createModelEntity(table);\n this.tenantEntity = createTenantEntity(table);\n this.localeEntity = createLocaleEntity(table);\n }\n\n public getId() {\n return \"5.35.0-005\";\n }\n\n public getDescription() {\n return \"Add singular and plural API names to the CMS Model entity\";\n }\n\n public async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n const tenants = await this.listTenants();\n if (tenants.length === 0) {\n logger.info(`No tenants found in the system; skipping migration.`);\n return false;\n }\n for (const tenant of tenants) {\n const locales = await this.listLocales({ tenant });\n if (locales.length === 0) {\n logger.info(`No locales found in tenant \"${tenant.data.id}\".`);\n continue;\n }\n for (const locale of locales) {\n const models = (await this.listModels({ tenant, locale })).filter(model => {\n return !model.singularApiName || !model.pluralApiName;\n });\n if (models.length === 0) {\n logger.info(\n `No models, to be updated, found in tenant \"${tenant.data.id}\" and locale \"${locale.code}\".`\n );\n continue;\n }\n return true;\n }\n }\n return false;\n }\n\n public async execute({ logger }: DataMigrationContext): Promise<void> {\n const models: CmsModel[] = [];\n const tenants = await this.listTenants();\n for (const tenant of tenants) {\n const locales = await this.listLocales({ tenant });\n for (const locale of locales) {\n const items = (await this.listModels({ tenant, locale })).filter(model => {\n return !model.singularApiName || !model.pluralApiName;\n });\n models.push(...items);\n }\n }\n if (models.length === 0) {\n logger.info(`No models to be updated; skipping migration.`);\n return;\n }\n\n const items = models.map(model => {\n return this.modelEntity.putBatch({\n ...model,\n /**\n * Add singular and plural API names.\n */\n singularApiName: createSingularApiName(model),\n pluralApiName: createPluralApiName(model)\n });\n });\n logger.info(`Updating total of ${items.length} models.`);\n\n await batchWriteAll({\n table: this.modelEntity.table,\n items\n });\n logger.info(\"Updated all the models.\");\n }\n\n private async listTenants(): Promise<Tenant[]> {\n return await queryAll<Tenant>({\n entity: this.tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n });\n }\n\n private async listLocales({ tenant }: ListLocalesParams): Promise<I18NLocale[]> {\n return await queryAll<I18NLocale>({\n entity: this.localeEntity,\n partitionKey: `T#${tenant.data.id}#I18N#L`,\n options: {\n gte: \" \"\n }\n });\n }\n\n private async listModels({ tenant, locale }: ListModelsParams): Promise<CmsModel[]> {\n return await queryAll<CmsModel>({\n entity: this.modelEntity,\n partitionKey: `T#${tenant.data.id}#L#${locale.code}#CMS#CM`,\n options: {\n gte: \" \"\n }\n });\n }\n}\n\nmakeInjectable(CmsModels_5_35_0_005, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":";;;;;;;AACA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AACA,IAAAK,mBAAA,GAAAL,OAAA;AAEA,IAAAM,UAAA,GAAAC,sBAAA,CAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAD,sBAAA,CAAAP,OAAA;AACA,IAAAS,UAAA,GAAAF,sBAAA,CAAAP,OAAA;AAEA,MAAMU,qBAAqB,GAAIC,KAAe,IAAK;EAC/C,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACF,KAAK,CAACG,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED,MAAMC,mBAAmB,GAAIJ,KAAe,IAAK;EAC7C,OAAO,IAAAK,kBAAS,EAACN,qBAAqB,CAACC,KAAK,CAAC,CAAC;AAClD,CAAC;AAWM,MAAMM,oBAAoB,CAAC;EAKvBC,WAAWA,CAACC,KAAoC,EAAE;IACrD,IAAI,CAACC,WAAW,GAAG,IAAAC,oCAAiB,EAACF,KAAK,CAAC;IAC3C,IAAI,CAACG,YAAY,GAAG,IAAAC,sCAAkB,EAACJ,KAAK,CAAC;IAC7C,IAAI,CAACK,YAAY,GAAG,IAAAC,sCAAkB,EAACN,KAAK,CAAC;EACjD;EAEOO,KAAKA,CAAA,EAAG;IACX,OAAO,YAAY;EACvB;EAEOC,cAAcA,CAAA,EAAG;IACpB,OAAO,2DAA2D;EACtE;EAEA,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MAAcrB,WAAWA,CAAC;IAAEF;EAA0B,CAAC,EAAyB;IAC5E,OAAO,MAAM,IAAAkB,eAAQ,EAAa;MAC9BC,MAAM,EAAE,IAAI,CAAC7B,YAAY;MACzB8B,YAAY,EAAG,KAAIpB,MAAM,CAACG,IAAI,CAACC,EAAG,SAAQ;MAC1CiB,OAAO,EAAE;QACLE,GAAG,EAAE;MACT;IACJ,CAAC,CAAC;EACN;EAEA,MAAchB,UAAUA,CAAC;IAAEP,MAAM;IAAEK;EAAyB,CAAC,EAAuB;IAChF,OAAO,MAAM,IAAAa,eAAQ,EAAW;MAC5BC,MAAM,EAAE,IAAI,CAACjC,WAAW;MACxBkC,YAAY,EAAG,KAAIpB,MAAM,CAACG,IAAI,CAACC,EAAG,MAAKC,MAAM,CAACM,IAAK,SAAQ;MAC3DU,OAAO,EAAE;QACLE,GAAG,EAAE;MACT;IACJ,CAAC,CAAC;EACN;AACJ;AAACC,OAAA,CAAAzC,oBAAA,GAAAA,oBAAA;AAED,IAAA0C,mBAAc,EAAC1C,oBAAoB,EAAE,CAAC,IAAA2C,WAAM,EAACC,uCAAwB,CAAC,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_ioc","require","_dataMigration","_utils","_createModelEntity","_createTenantEntity","_createLocaleEntity","_pluralize","_interopRequireDefault","_upperFirst","_camelCase","_dbDynamodb","createSingularApiName","model","upperFirst","camelCase","modelId","createPluralApiName","pluralize","CmsModels_5_35_0_005","constructor","table","modelEntity","createModelEntity","tenantEntity","createTenantEntity","localeEntity","createLocaleEntity","getId","getDescription","shouldExecute","logger","tenants","listTenants","length","info","tenant","locales","listLocales","data","id","locale","models","listModels","filter","singularApiName","pluralApiName","code","execute","items","push","entityBatch","createEntityWriteBatch","entity","put","map","total","queryAll","partitionKey","options","index","gte","exports","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["index.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { DataMigrationContext, PrimaryDynamoTableSymbol } from \"@webiny/data-migration\";\nimport { queryAll } from \"~/utils\";\nimport { createModelEntity } from \"./createModelEntity\";\nimport { createTenantEntity } from \"./createTenantEntity\";\nimport { createLocaleEntity } from \"./createLocaleEntity\";\nimport { CmsModel, I18NLocale, Tenant } from \"./types\";\nimport pluralize from \"pluralize\";\nimport upperFirst from \"lodash/upperFirst\";\nimport camelCase from \"lodash/camelCase\";\nimport { createEntityWriteBatch } from \"@webiny/db-dynamodb\";\n\nconst createSingularApiName = (model: CmsModel) => {\n return upperFirst(camelCase(model.modelId));\n};\n\nconst createPluralApiName = (model: CmsModel) => {\n return pluralize(createSingularApiName(model));\n};\n\ninterface ListLocalesParams {\n tenant: Tenant;\n}\n\ninterface ListModelsParams {\n tenant: Tenant;\n locale: I18NLocale;\n}\n\nexport class CmsModels_5_35_0_005 {\n private readonly modelEntity: ReturnType<typeof createModelEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n private readonly localeEntity: ReturnType<typeof createLocaleEntity>;\n\n public constructor(table: Table<string, string, string>) {\n this.modelEntity = createModelEntity(table);\n this.tenantEntity = createTenantEntity(table);\n this.localeEntity = createLocaleEntity(table);\n }\n\n public getId() {\n return \"5.35.0-005\";\n }\n\n public getDescription() {\n return \"Add singular and plural API names to the CMS Model entity\";\n }\n\n public async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n const tenants = await this.listTenants();\n if (tenants.length === 0) {\n logger.info(`No tenants found in the system; skipping migration.`);\n return false;\n }\n for (const tenant of tenants) {\n const locales = await this.listLocales({ tenant });\n if (locales.length === 0) {\n logger.info(`No locales found in tenant \"${tenant.data.id}\".`);\n continue;\n }\n for (const locale of locales) {\n const models = (await this.listModels({ tenant, locale })).filter(model => {\n return !model.singularApiName || !model.pluralApiName;\n });\n if (models.length === 0) {\n logger.info(\n `No models, to be updated, found in tenant \"${tenant.data.id}\" and locale \"${locale.code}\".`\n );\n continue;\n }\n return true;\n }\n }\n return false;\n }\n\n public async execute({ logger }: DataMigrationContext): Promise<void> {\n const models: CmsModel[] = [];\n const tenants = await this.listTenants();\n for (const tenant of tenants) {\n const locales = await this.listLocales({ tenant });\n for (const locale of locales) {\n const items = (await this.listModels({ tenant, locale })).filter(model => {\n return !model.singularApiName || !model.pluralApiName;\n });\n models.push(...items);\n }\n }\n if (models.length === 0) {\n logger.info(`No models to be updated; skipping migration.`);\n return;\n }\n\n const entityBatch = createEntityWriteBatch({\n entity: this.modelEntity,\n put: models.map(model => {\n return {\n ...model,\n /**\n * Add singular and plural API names.\n */\n singularApiName: createSingularApiName(model),\n pluralApiName: createPluralApiName(model)\n };\n })\n });\n\n logger.info(`Updating total of ${entityBatch.total} models.`);\n\n await entityBatch.execute();\n logger.info(\"Updated all the models.\");\n }\n\n private async listTenants(): Promise<Tenant[]> {\n return await queryAll<Tenant>({\n entity: this.tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n });\n }\n\n private async listLocales({ tenant }: ListLocalesParams): Promise<I18NLocale[]> {\n return await queryAll<I18NLocale>({\n entity: this.localeEntity,\n partitionKey: `T#${tenant.data.id}#I18N#L`,\n options: {\n gte: \" \"\n }\n });\n }\n\n private async listModels({ tenant, locale }: ListModelsParams): Promise<CmsModel[]> {\n return await queryAll<CmsModel>({\n entity: this.modelEntity,\n partitionKey: `T#${tenant.data.id}#L#${locale.code}#CMS#CM`,\n options: {\n gte: \" \"\n }\n });\n }\n}\n\nmakeInjectable(CmsModels_5_35_0_005, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":";;;;;;;AACA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AACA,IAAAI,mBAAA,GAAAJ,OAAA;AACA,IAAAK,mBAAA,GAAAL,OAAA;AAEA,IAAAM,UAAA,GAAAC,sB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,MAAM,CAACM,IAAK,SAAQ;MAC3DY,OAAO,EAAE;QACLE,GAAG,EAAE;MACT;IACJ,CAAC,CAAC;EACN;AACJ;AAACC,OAAA,CAAA3C,oBAAA,GAAAA,oBAAA;AAED,IAAA4C,mBAAc,EAAC5C,oBAAoB,EAAE,CAAC,IAAA6C,WAAM,EAACC,uCAAwB,CAAC,CAAC,CAAC","ignoreList":[]}
@@ -182,14 +182,14 @@ class CmsEntriesRootFolder_5_37_0_002 {
182
182
  modified
183
183
  }));
184
184
  }
185
- const execute = () => {
186
- return (0, _dbDynamodb.batchWriteAll)({
185
+ const execute = async () => {
186
+ return await (0, _dbDynamodb.batchWriteAll)({
187
187
  table: this.ddbEntryEntity.table,
188
188
  items: ddbItems
189
189
  });
190
190
  };
191
- const executeDdbEs = () => {
192
- return (0, _dbDynamodb.batchWriteAll)({
191
+ const executeDdbEs = async () => {
192
+ return await (0, _dbDynamodb.batchWriteAll)({
193
193
  table: this.ddbEsEntryEntity.table,
194
194
  items: ddbEsItems
195
195
  });
@@ -1 +1 @@
1
- {"version":3,"names":["_dataMigration","require","_createEntryEntity","_createLocaleEntity","_createTenantEntity","_dbDynamodb","_utils","_utils2","_getDecompressedData","_getCompressedData","_ioc","CmsEntriesRootFolder_5_37_0_002","constructor","table","esTable","elasticsearchClient","ddbEntryEntity","createDdbEntryEntity","ddbEsEntryEntity","createDdbEsEntryEntity","localeEntity","createLocaleEntity","tenantEntity","createTenantEntity","getId","getDescription","shouldExecute","logger","result","scan","entity","options","filters","attr","contains","limit","items","length","info","error","Error","item","data","getDecompressedData","location","folderId","execute","context","migrationStatus","checkpoint","lastEvaluatedKey","restoreOriginalElasticsearchSettings","usingKey","JSON","stringify","debug","ddbScanWithCallback","beginsWith","startKey","undefined","ddbItems","ddbEsItems","ddbEsGetItems","index","esGetIndexName","tenant","locale","type","modelId","isHeadlessCmsModel","indexes","settings","fetchOriginalElasticsearchSettings","disableElasticsearchIndexing","push","putBatch","entryId","getBatch","PK","SK","status","locked","esRecords","batchReadAll","Object","values","esRecord","decompressedData","trace","forceExecute","compressedData","getCompressedData","modified","Date","toISOString","batchWriteAll","executeDdbEs","executeWithRetry","onFailedAttempt","attemptNumber","message","runningOutOfTime","createCheckpointAndExit","createCheckpoint","params","esGetIndexSettings","fields","number_of_replicas","refresh_interval","ex","code","esPutIndexSettings","exports","makeInjectable","inject","PrimaryDynamoTableSymbol","ElasticsearchDynamoTableSymbol","ElasticsearchClientSymbol"],"sources":["index.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport {\n DataMigration,\n DataMigrationContext,\n ElasticsearchClientSymbol,\n ElasticsearchDynamoTableSymbol,\n Logger,\n PrimaryDynamoTableSymbol\n} from \"@webiny/data-migration\";\nimport { createDdbEntryEntity, createDdbEsEntryEntity } from \"../entities/createEntryEntity\";\nimport { createLocaleEntity } from \"../entities/createLocaleEntity\";\nimport { createTenantEntity } from \"../entities/createTenantEntity\";\nimport {\n batchReadAll,\n BatchReadItem,\n batchWriteAll,\n BatchWriteItem,\n scan\n} from \"@webiny/db-dynamodb\";\nimport { CmsEntry } from \"../types\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport {\n ddbScanWithCallback,\n esGetIndexName,\n esGetIndexSettings,\n esPutIndexSettings\n} from \"~/utils\";\nimport { executeWithRetry } from \"@webiny/utils\";\nimport { getDecompressedData } from \"~/migrations/5.37.0/002/utils/getDecompressedData\";\nimport { getCompressedData } from \"~/migrations/5.37.0/002/utils/getCompressedData\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\n\ninterface LastEvaluatedKey {\n PK: string;\n SK: string;\n GSI1_PK: string;\n GSI1_SK: string;\n}\n\ninterface IndexSettings {\n number_of_replicas: number;\n refresh_interval: `${number}s`;\n}\n\ninterface CmsEntriesRootFolderDataMigrationCheckpoint {\n lastEvaluatedKey?: LastEvaluatedKey | boolean;\n indexes: {\n [index: string]: IndexSettings | null;\n };\n}\n\ninterface FetchOriginalElasticsearchSettingsParams {\n index: string;\n logger: Logger;\n}\n\ninterface RestoreOriginalElasticsearchSettingsParams {\n migrationStatus: CmsEntriesRootFolderDataMigrationCheckpoint;\n logger: Logger;\n}\n\ninterface DisableElasticsearchIndexingParams {\n index: string;\n logger: Logger;\n}\n\ninterface DynamoDbElasticsearchRecord {\n PK: string;\n SK: string;\n data: string;\n}\n\nexport class CmsEntriesRootFolder_5_37_0_002\n implements DataMigration<CmsEntriesRootFolderDataMigrationCheckpoint>\n{\n private readonly elasticsearchClient: Client;\n private readonly ddbEntryEntity: ReturnType<typeof createDdbEntryEntity>;\n private readonly ddbEsEntryEntity: ReturnType<typeof createDdbEsEntryEntity>;\n private readonly localeEntity: ReturnType<typeof createLocaleEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n\n public constructor(\n table: Table<string, string, string>,\n esTable: Table<string, string, string>,\n elasticsearchClient: Client\n ) {\n this.elasticsearchClient = elasticsearchClient;\n this.ddbEntryEntity = createDdbEntryEntity(table);\n this.ddbEsEntryEntity = createDdbEsEntryEntity(esTable);\n this.localeEntity = createLocaleEntity(table);\n this.tenantEntity = createTenantEntity(table);\n }\n\n getId() {\n return \"5.37.0-002\";\n }\n\n getDescription() {\n return \"Add default folderId to all CMS records.\";\n }\n\n async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n /**\n * We will load a few CMS entryes\n */\n const result = await scan<DynamoDbElasticsearchRecord>({\n entity: this.ddbEsEntryEntity,\n options: {\n filters: [\n {\n attr: \"PK\",\n contains: \"#CMS#CME#\"\n }\n ],\n limit: 100\n }\n });\n\n if (result.items.length === 0) {\n logger.info(`No CMS entries found in the system; skipping migration.`);\n return false;\n } else if (result.error) {\n logger.error(result.error);\n throw new Error(result.error);\n }\n\n for (const item of result.items) {\n const data = await getDecompressedData<CmsEntry>(item.data);\n if (!data) {\n continue;\n }\n /**\n * If no location.folderId was set, we need to push the upgrade.\n */\n if (!data.location?.folderId) {\n return true;\n }\n }\n logger.info(`CMS entries already upgraded. skipping...`);\n return false;\n }\n\n async execute({\n logger,\n ...context\n }: DataMigrationContext<CmsEntriesRootFolderDataMigrationCheckpoint>): Promise<void> {\n const migrationStatus =\n context.checkpoint || ({} as CmsEntriesRootFolderDataMigrationCheckpoint);\n\n if (migrationStatus.lastEvaluatedKey === true) {\n await this.restoreOriginalElasticsearchSettings({\n migrationStatus,\n logger\n });\n logger.info(`Migration completed, no need to start again.`);\n return;\n }\n let usingKey = \"\";\n if (migrationStatus?.lastEvaluatedKey) {\n usingKey = JSON.stringify(migrationStatus.lastEvaluatedKey);\n }\n logger.debug(`Scanning DynamoDB Elasticsearch table... ${usingKey}`);\n await ddbScanWithCallback<CmsEntry>(\n {\n entity: this.ddbEntryEntity,\n options: {\n filters: [\n {\n attr: \"TYPE\",\n beginsWith: \"cms.entry\"\n }\n ],\n startKey: migrationStatus.lastEvaluatedKey || undefined,\n limit: 500\n }\n },\n async result => {\n logger.debug(`Processing ${result.items.length} items...`);\n const ddbItems: BatchWriteItem[] = [];\n const ddbEsItems: BatchWriteItem[] = [];\n\n const ddbEsGetItems: Record<string, BatchReadItem> = {};\n /**\n * Update the DynamoDB part of the records.\n */\n for (const item of result.items) {\n const index = esGetIndexName({\n tenant: item.tenant,\n locale: item.locale,\n type: item.modelId,\n isHeadlessCmsModel: true\n });\n // Check for the elasticsearch index settings\n if (!migrationStatus.indexes || migrationStatus.indexes[index] === undefined) {\n // We need to fetch the index settings first\n const settings = await this.fetchOriginalElasticsearchSettings({\n index,\n logger\n });\n // ... add it to the checkpoint...\n migrationStatus.indexes = {\n ...migrationStatus.indexes,\n [index]: settings\n };\n // and then set not to index\n await this.disableElasticsearchIndexing({\n index,\n logger\n });\n }\n //\n ddbItems.push(\n this.ddbEntryEntity.putBatch({\n ...item,\n location: {\n ...item.location,\n folderId: item.location?.folderId || \"root\"\n }\n })\n );\n /**\n * Prepare the loading of DynamoDB Elasticsearch part of the records.\n */\n if (ddbEsGetItems[`${item.entryId}:L`]) {\n continue;\n }\n ddbEsGetItems[`${item.entryId}:L`] = this.ddbEsEntryEntity.getBatch({\n PK: item.PK,\n SK: \"L\"\n });\n if (item.status === \"published\" || !!item.locked) {\n ddbEsGetItems[`${item.entryId}:P`] = this.ddbEsEntryEntity.getBatch({\n PK: item.PK,\n SK: \"P\"\n });\n }\n }\n /**\n * Get all the records from DynamoDB Elasticsearch.\n */\n const esRecords = await batchReadAll<DynamoDbElasticsearchRecord>({\n table: this.ddbEsEntryEntity.table,\n items: Object.values(ddbEsGetItems)\n });\n for (const esRecord of esRecords) {\n const decompressedData = await getDecompressedData<CmsEntry>(esRecord.data);\n if (!decompressedData) {\n logger.trace(\n `Skipping record \"${esRecord.PK}\" as it is not a valid CMS entry...`\n );\n continue;\n } else if (!context.forceExecute && decompressedData.location?.folderId) {\n logger.trace(\n `Skipping record \"${decompressedData.entryId}\" as it already has folderId defined...`\n );\n continue;\n }\n const compressedData = await getCompressedData({\n ...decompressedData,\n location: {\n ...decompressedData.location,\n folderId: \"root\"\n }\n });\n const modified = new Date().toISOString();\n ddbEsItems.push(\n this.ddbEsEntryEntity.putBatch({\n ...esRecord,\n data: compressedData,\n modified\n })\n );\n }\n\n const execute = () => {\n return batchWriteAll({\n table: this.ddbEntryEntity.table,\n items: ddbItems\n });\n };\n\n const executeDdbEs = () => {\n return batchWriteAll({\n table: this.ddbEsEntryEntity.table,\n items: ddbEsItems\n });\n };\n\n logger.trace(\"Storing the DynamoDB records...\");\n await executeWithRetry(execute, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll\" attempt #${error.attemptNumber} failed: ${error.message}`\n );\n }\n });\n logger.trace(\"...stored.\");\n\n logger.trace(\"Storing the DynamoDB Elasticsearch records...\");\n await executeWithRetry(executeDdbEs, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll ddb + es\" attempt #${error.attemptNumber} failed: ${error.message}`\n );\n }\n });\n logger.trace(\"...stored.\");\n\n // Update checkpoint after every batch\n migrationStatus.lastEvaluatedKey = result.lastEvaluatedKey?.PK\n ? (result.lastEvaluatedKey as unknown as LastEvaluatedKey)\n : true;\n\n // Check if we should store checkpoint and exit.\n if (context.runningOutOfTime()) {\n await context.createCheckpointAndExit(migrationStatus);\n } else {\n await context.createCheckpoint(migrationStatus);\n }\n }\n );\n /**\n * This is the end of the migration.\n */\n await this.restoreOriginalElasticsearchSettings({\n migrationStatus,\n logger\n });\n migrationStatus.lastEvaluatedKey = true;\n migrationStatus.indexes = {};\n context.createCheckpoint(migrationStatus);\n }\n\n private async fetchOriginalElasticsearchSettings(\n params: FetchOriginalElasticsearchSettingsParams\n ): Promise<IndexSettings | null> {\n const { index, logger } = params;\n try {\n const settings = await esGetIndexSettings({\n elasticsearchClient: this.elasticsearchClient,\n index,\n fields: [\"number_of_replicas\", \"refresh_interval\"]\n });\n return {\n number_of_replicas: settings.number_of_replicas || 1,\n refresh_interval: settings.refresh_interval || \"1s\"\n };\n } catch (ex) {\n logger.error(`Failed to fetch original Elasticsearch settings for index \"${index}\".`);\n logger.error({\n ...ex,\n message: ex.message,\n code: ex.code,\n data: ex.data\n });\n }\n return null;\n }\n\n private async restoreOriginalElasticsearchSettings(\n params: RestoreOriginalElasticsearchSettingsParams\n ): Promise<void> {\n const { migrationStatus, logger } = params;\n const indexes = migrationStatus.indexes;\n if (!indexes || typeof indexes !== \"object\") {\n return;\n }\n for (const index in indexes) {\n const settings = indexes[index];\n if (!settings || typeof settings !== \"object\") {\n continue;\n }\n try {\n await esPutIndexSettings({\n elasticsearchClient: this.elasticsearchClient,\n index,\n settings: {\n number_of_replicas: settings.number_of_replicas || 1,\n refresh_interval: settings.refresh_interval || `1s`\n }\n });\n } catch (ex) {\n logger.error(\n `Failed to restore original settings for index \"${index}\". Please do it manually.`\n );\n logger.error({\n ...ex,\n message: ex.message,\n code: ex.code,\n data: ex.data\n });\n }\n }\n }\n\n private async disableElasticsearchIndexing(\n params: DisableElasticsearchIndexingParams\n ): Promise<void> {\n const { index, logger } = params;\n\n try {\n await esPutIndexSettings({\n elasticsearchClient: this.elasticsearchClient,\n index,\n settings: {\n number_of_replicas: 0,\n refresh_interval: -1\n }\n });\n } catch (ex) {\n logger.error(`Failed to disable indexing for index \"${index}\".`);\n logger.error({\n ...ex,\n message: ex.message,\n code: ex.code,\n data: ex.data\n });\n }\n }\n}\n\nmakeInjectable(CmsEntriesRootFolder_5_37_0_002, [\n inject(PrimaryDynamoTableSymbol),\n inject(ElasticsearchDynamoTableSymbol),\n inject(ElasticsearchClientSymbol)\n]);\n"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AAQA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AASA,IAAAK,MAAA,GAAAL,OAAA;AAMA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,oBAAA,GAAAP,OAAA;AACA,IAAAQ,kBAAA,GAAAR,OAAA;AACA,IAAAS,IAAA,GAAAT,OAAA;AA0CO,MAAMU,+BAA+B,CAE5C;EAOWC,WAAWA,CACdC,KAAoC,EACpCC,OAAsC,EACtCC,mBAA2B,EAC7B;IACE,IAAI,CAACA,mBAAmB,GAAGA,mBAAmB;IAC9C,IAAI,CAACC,cAAc,GAAG,IAAAC,uCAAoB,EAACJ,KAAK,CAAC;IACjD,IAAI,CAACK,gBAAgB,GAAG,IAAAC,yCAAsB,EAACL,OAAO,CAAC;IACvD,IAAI,CAACM,YAAY,GAAG,IAAAC,sCAAkB,EAACR,KAAK,CAAC;IAC7C,IAAI,CAACS,YAAY,GAAG,IAAAC,sCAAkB,EAACV,KAAK,CAAC;EACjD;EAEAW,KAAKA,CAAA,EAAG;IACJ,OAAO,YAAY;EACvB;EAEAC,cAAcA,CAAA,EAAG;IACb,OAAO,0CAA0C;EACrD;EAEA,MAAMC,aAAaA,CAAC;IAAEC;EAA6B,CAAC,EAAoB;IACpE;AACR;AACA;IACQ,M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AAC,OAAOC,EAAE,EAAE;QACTlF,MAAM,CAACY,KAAK,CACP,kDAAiDwB,KAAM,2BAC5D,CAAC;QACDpC,MAAM,CAACY,KAAK,CAAC;UACT,GAAGsE,EAAE;UACLT,OAAO,EAAES,EAAE,CAACT,OAAO;UACnBU,IAAI,EAAED,EAAE,CAACC,IAAI;UACbpE,IAAI,EAAEmE,EAAE,CAACnE;QACb,CAAC,CAAC;MACN;IACJ;EACJ;EAEA,MAAc+B,4BAA4BA,CACtC+B,MAA0C,EAC7B;IACb,MAAM;MAAEzC,KAAK;MAAEpC;IAAO,CAAC,GAAG6E,MAAM;IAEhC,IAAI;MACA,MAAM,IAAAO,yBAAkB,EAAC;QACrBhG,mBAAmB,EAAE,IAAI,CAACA,mBAAmB;QAC7CgD,KAAK;QACLQ,QAAQ,EAAE;UACNoC,kBAAkB,EAAE,CAAC;UACrBC,gBAAgB,EAAE,CAAC;QACvB;MACJ,CAAC,CAAC;IACN,CAAC,CAAC,OAAOC,EAAE,EAAE;MACTlF,MAAM,CAACY,KAAK,CAAE,yCAAwCwB,KAAM,IAAG,CAAC;MAChEpC,MAAM,CAACY,KAAK,CAAC;QACT,GAAGsE,EAAE;QACLT,OAAO,EAAES,EAAE,CAACT,OAAO;QACnBU,IAAI,EAAED,EAAE,CAACC,IAAI;QACbpE,IAAI,EAAEmE,EAAE,CAACnE;MACb,CAAC,CAAC;IACN;EACJ;AACJ;AAACsE,OAAA,CAAArG,+BAAA,GAAAA,+BAAA;AAED,IAAAsG,mBAAc,EAACtG,+BAA+B,EAAE,CAC5C,IAAAuG,WAAM,EAACC,uCAAwB,CAAC,EAChC,IAAAD,WAAM,EAACE,6CAA8B,CAAC,EACtC,IAAAF,WAAM,EAACG,wCAAyB,CAAC,CACpC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_dataMigration","require","_createEntryEntity","_createLocaleEntity","_createTenantEntity","_dbDynamodb","_utils","_utils2","_getDecompressedData","_getCompressedData","_ioc","CmsEntriesRootFolder_5_37_0_002","constructor","table","esTable","elasticsearchClient","ddbEntryEntity","createDdbEntryEntity","ddbEsEntryEntity","createDdbEsEntryEntity","localeEntity","createLocaleEntity","tenantEntity","createTenantEntity","getId","getDescription","shouldExecute","logger","result","scan","entity","options","filters","attr","contains","limit","items","length","info","error","Error","item","data","getDecompressedData","location","folderId","execute","context","migrationStatus","checkpoint","lastEvaluatedKey","restoreOriginalElasticsearchSettings","usingKey","JSON","stringify","debug","ddbScanWithCallback","beginsWith","startKey","undefined","ddbItems","ddbEsItems","ddbEsGetItems","index","esGetIndexName","tenant","locale","type","modelId","isHeadlessCmsModel","indexes","settings","fetchOriginalElasticsearchSettings","disableElasticsearchIndexing","push","putBatch","entryId","getBatch","PK","SK","status","locked","esRecords","batchReadAll","Object","values","esRecord","decompressedData","trace","forceExecute","compressedData","getCompressedData","modified","Date","toISOString","batchWriteAll","executeDdbEs","executeWithRetry","onFailedAttempt","attemptNumber","message","runningOutOfTime","createCheckpointAndExit","createCheckpoint","params","esGetIndexSettings","fields","number_of_replicas","refresh_interval","ex","code","esPutIndexSettings","exports","makeInjectable","inject","PrimaryDynamoTableSymbol","ElasticsearchDynamoTableSymbol","ElasticsearchClientSymbol"],"sources":["index.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport {\n DataMigration,\n DataMigrationContext,\n ElasticsearchClientSymbol,\n ElasticsearchDynamoTableSymbol,\n Logger,\n PrimaryDynamoTableSymbol\n} from \"@webiny/data-migration\";\nimport { createDdbEntryEntity, createDdbEsEntryEntity } from \"../entities/createEntryEntity\";\nimport { createLocaleEntity } from \"../entities/createLocaleEntity\";\nimport { createTenantEntity } from \"../entities/createTenantEntity\";\nimport {\n batchReadAll,\n BatchReadItem,\n batchWriteAll,\n BatchWriteItem,\n scan\n} from \"@webiny/db-dynamodb\";\nimport { CmsEntry } from \"../types\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport {\n ddbScanWithCallback,\n esGetIndexName,\n esGetIndexSettings,\n esPutIndexSettings\n} from \"~/utils\";\nimport { executeWithRetry } from \"@webiny/utils\";\nimport { getDecompressedData } from \"~/migrations/5.37.0/002/utils/getDecompressedData\";\nimport { getCompressedData } from \"~/migrations/5.37.0/002/utils/getCompressedData\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\n\ninterface LastEvaluatedKey {\n PK: string;\n SK: string;\n GSI1_PK: string;\n GSI1_SK: string;\n}\n\ninterface IndexSettings {\n number_of_replicas: number;\n refresh_interval: `${number}s`;\n}\n\ninterface CmsEntriesRootFolderDataMigrationCheckpoint {\n lastEvaluatedKey?: LastEvaluatedKey | boolean;\n indexes: {\n [index: string]: IndexSettings | null;\n };\n}\n\ninterface FetchOriginalElasticsearchSettingsParams {\n index: string;\n logger: Logger;\n}\n\ninterface RestoreOriginalElasticsearchSettingsParams {\n migrationStatus: CmsEntriesRootFolderDataMigrationCheckpoint;\n logger: Logger;\n}\n\ninterface DisableElasticsearchIndexingParams {\n index: string;\n logger: Logger;\n}\n\ninterface DynamoDbElasticsearchRecord {\n PK: string;\n SK: string;\n data: string;\n}\n\nexport class CmsEntriesRootFolder_5_37_0_002\n implements DataMigration<CmsEntriesRootFolderDataMigrationCheckpoint>\n{\n private readonly elasticsearchClient: Client;\n private readonly ddbEntryEntity: ReturnType<typeof createDdbEntryEntity>;\n private readonly ddbEsEntryEntity: ReturnType<typeof createDdbEsEntryEntity>;\n private readonly localeEntity: ReturnType<typeof createLocaleEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n\n public constructor(\n table: Table<string, string, string>,\n esTable: Table<string, string, string>,\n elasticsearchClient: Client\n ) {\n this.elasticsearchClient = elasticsearchClient;\n this.ddbEntryEntity = createDdbEntryEntity(table);\n this.ddbEsEntryEntity = createDdbEsEntryEntity(esTable);\n this.localeEntity = createLocaleEntity(table);\n this.tenantEntity = createTenantEntity(table);\n }\n\n getId() {\n return \"5.37.0-002\";\n }\n\n getDescription() {\n return \"Add default folderId to all CMS records.\";\n }\n\n async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n /**\n * We will load a few CMS entryes\n */\n const result = await scan<DynamoDbElasticsearchRecord>({\n entity: this.ddbEsEntryEntity,\n options: {\n filters: [\n {\n attr: \"PK\",\n contains: \"#CMS#CME#\"\n }\n ],\n limit: 100\n }\n });\n\n if (result.items.length === 0) {\n logger.info(`No CMS entries found in the system; skipping migration.`);\n return false;\n } else if (result.error) {\n logger.error(result.error);\n throw new Error(result.error);\n }\n\n for (const item of result.items) {\n const data = await getDecompressedData<CmsEntry>(item.data);\n if (!data) {\n continue;\n }\n /**\n * If no location.folderId was set, we need to push the upgrade.\n */\n if (!data.location?.folderId) {\n return true;\n }\n }\n logger.info(`CMS entries already upgraded. skipping...`);\n return false;\n }\n\n async execute({\n logger,\n ...context\n }: DataMigrationContext<CmsEntriesRootFolderDataMigrationCheckpoint>): Promise<void> {\n const migrationStatus =\n context.checkpoint || ({} as CmsEntriesRootFolderDataMigrationCheckpoint);\n\n if (migrationStatus.lastEvaluatedKey === true) {\n await this.restoreOriginalElasticsearchSettings({\n migrationStatus,\n logger\n });\n logger.info(`Migration completed, no need to start again.`);\n return;\n }\n let usingKey = \"\";\n if (migrationStatus?.lastEvaluatedKey) {\n usingKey = JSON.stringify(migrationStatus.lastEvaluatedKey);\n }\n logger.debug(`Scanning DynamoDB Elasticsearch table... ${usingKey}`);\n await ddbScanWithCallback<CmsEntry>(\n {\n entity: this.ddbEntryEntity,\n options: {\n filters: [\n {\n attr: \"TYPE\",\n beginsWith: \"cms.entry\"\n }\n ],\n startKey: migrationStatus.lastEvaluatedKey || undefined,\n limit: 500\n }\n },\n async result => {\n logger.debug(`Processing ${result.items.length} items...`);\n const ddbItems: BatchWriteItem[] = [];\n const ddbEsItems: BatchWriteItem[] = [];\n\n const ddbEsGetItems: Record<string, BatchReadItem> = {};\n /**\n * Update the DynamoDB part of the records.\n */\n for (const item of result.items) {\n const index = esGetIndexName({\n tenant: item.tenant,\n locale: item.locale,\n type: item.modelId,\n isHeadlessCmsModel: true\n });\n // Check for the elasticsearch index settings\n if (!migrationStatus.indexes || migrationStatus.indexes[index] === undefined) {\n // We need to fetch the index settings first\n const settings = await this.fetchOriginalElasticsearchSettings({\n index,\n logger\n });\n // ... add it to the checkpoint...\n migrationStatus.indexes = {\n ...migrationStatus.indexes,\n [index]: settings\n };\n // and then set not to index\n await this.disableElasticsearchIndexing({\n index,\n logger\n });\n }\n //\n ddbItems.push(\n this.ddbEntryEntity.putBatch({\n ...item,\n location: {\n ...item.location,\n folderId: item.location?.folderId || \"root\"\n }\n })\n );\n /**\n * Prepare the loading of DynamoDB Elasticsearch part of the records.\n */\n if (ddbEsGetItems[`${item.entryId}:L`]) {\n continue;\n }\n ddbEsGetItems[`${item.entryId}:L`] = this.ddbEsEntryEntity.getBatch({\n PK: item.PK,\n SK: \"L\"\n });\n if (item.status === \"published\" || !!item.locked) {\n ddbEsGetItems[`${item.entryId}:P`] = this.ddbEsEntryEntity.getBatch({\n PK: item.PK,\n SK: \"P\"\n });\n }\n }\n /**\n * Get all the records from DynamoDB Elasticsearch.\n */\n const esRecords = await batchReadAll<DynamoDbElasticsearchRecord>({\n table: this.ddbEsEntryEntity.table,\n items: Object.values(ddbEsGetItems)\n });\n for (const esRecord of esRecords) {\n const decompressedData = await getDecompressedData<CmsEntry>(esRecord.data);\n if (!decompressedData) {\n logger.trace(\n `Skipping record \"${esRecord.PK}\" as it is not a valid CMS entry...`\n );\n continue;\n } else if (!context.forceExecute && decompressedData.location?.folderId) {\n logger.trace(\n `Skipping record \"${decompressedData.entryId}\" as it already has folderId defined...`\n );\n continue;\n }\n const compressedData = await getCompressedData({\n ...decompressedData,\n location: {\n ...decompressedData.location,\n folderId: \"root\"\n }\n });\n const modified = new Date().toISOString();\n ddbEsItems.push(\n this.ddbEsEntryEntity.putBatch({\n ...esRecord,\n data: compressedData,\n modified\n })\n );\n }\n\n const execute = async () => {\n return await batchWriteAll({\n table: this.ddbEntryEntity.table,\n items: ddbItems\n });\n };\n\n const executeDdbEs = async () => {\n return await batchWriteAll({\n table: this.ddbEsEntryEntity.table,\n items: ddbEsItems\n });\n };\n\n logger.trace(\"Storing the DynamoDB records...\");\n await executeWithRetry(execute, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll\" attempt #${error.attemptNumber} failed: ${error.message}`\n );\n }\n });\n logger.trace(\"...stored.\");\n\n logger.trace(\"Storing the DynamoDB Elasticsearch records...\");\n await executeWithRetry(executeDdbEs, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll ddb + es\" attempt #${error.attemptNumber} failed: ${error.message}`\n );\n }\n });\n logger.trace(\"...stored.\");\n\n // Update checkpoint after every batch\n migrationStatus.lastEvaluatedKey = result.lastEvaluatedKey?.PK\n ? (result.lastEvaluatedKey as unknown as LastEvaluatedKey)\n : true;\n\n // Check if we should store checkpoint and exit.\n if (context.runningOutOfTime()) {\n await context.createCheckpointAndExit(migrationStatus);\n } else {\n await context.createCheckpoint(migrationStatus);\n }\n }\n );\n /**\n * This is the end of the migration.\n */\n await this.restoreOriginalElasticsearchSettings({\n migrationStatus,\n logger\n });\n migrationStatus.lastEvaluatedKey = true;\n migrationStatus.indexes = {};\n context.createCheckpoint(migrationStatus);\n }\n\n private async fetchOriginalElasticsearchSettings(\n params: FetchOriginalElasticsearchSettingsParams\n ): Promise<IndexSettings | null> {\n const { index, logger } = params;\n try {\n const settings = await esGetIndexSettings({\n elasticsearchClient: this.elasticsearchClient,\n index,\n fields: [\"number_of_replicas\", \"refresh_interval\"]\n });\n return {\n number_of_replicas: settings.number_of_replicas || 1,\n refresh_interval: settings.refresh_interval || \"1s\"\n };\n } catch (ex) {\n logger.error(`Failed to fetch original Elasticsearch settings for index \"${index}\".`);\n logger.error({\n ...ex,\n message: ex.message,\n code: ex.code,\n data: ex.data\n });\n }\n return null;\n }\n\n private async restoreOriginalElasticsearchSettings(\n params: RestoreOriginalElasticsearchSettingsParams\n ): Promise<void> {\n const { migrationStatus, logger } = params;\n const indexes = migrationStatus.indexes;\n if (!indexes || typeof indexes !== \"object\") {\n return;\n }\n for (const index in indexes) {\n const settings = indexes[index];\n if (!settings || typeof settings !== \"object\") {\n continue;\n }\n try {\n await esPutIndexSettings({\n elasticsearchClient: this.elasticsearchClient,\n index,\n settings: {\n number_of_replicas: settings.number_of_replicas || 1,\n refresh_interval: settings.refresh_interval || `1s`\n }\n });\n } catch (ex) {\n logger.error(\n `Failed to restore original settings for index \"${index}\". Please do it manually.`\n );\n logger.error({\n ...ex,\n message: ex.message,\n code: ex.code,\n data: ex.data\n });\n }\n }\n }\n\n private async disableElasticsearchIndexing(\n params: DisableElasticsearchIndexingParams\n ): Promise<void> {\n const { index, logger } = params;\n\n try {\n await esPutIndexSettings({\n elasticsearchClient: this.elasticsearchClient,\n index,\n settings: {\n number_of_replicas: 0,\n refresh_interval: -1\n }\n });\n } catch (ex) {\n logger.error(`Failed to disable indexing for index \"${index}\".`);\n logger.error({\n ...ex,\n message: ex.message,\n code: ex.code,\n data: ex.data\n });\n }\n }\n}\n\nmakeInjectable(CmsEntriesRootFolder_5_37_0_002, [\n inject(PrimaryDynamoTableSymbol),\n inject(ElasticsearchDynamoTableSymbol),\n inject(ElasticsearchClientSymbol)\n]);\n"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AAQA,IAAAC,kBAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AASA,IAAAK,MAAA,GAAAL,OAAA;AAMA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,oBAAA,GAAAP,OAAA;AACA,IAAAQ,kBAAA,GAAAR,OAAA;AACA,IAAAS,IAAA,GAAAT,OAAA;AA0CO,MAAMU,+BAA+B,CAE5C;EAOWC,WAAWA,CACdC,KAAoC,EACpCC,OAAsC,EACtCC,mBAA2B,EAC7B;IACE,IAAI,CAACA,mBAAmB,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AAO,EAAES,EAAE,CAACT,OAAO;QACnBU,IAAI,EAAED,EAAE,CAACC,IAAI;QACbpE,IAAI,EAAEmE,EAAE,CAACnE;MACb,CAAC,CAAC;IACN;EACJ;AACJ;AAACsE,OAAA,CAAArG,+BAAA,GAAAA,+BAAA;AAED,IAAAsG,mBAAc,EAACtG,+BAA+B,EAAE,CAC5C,IAAAuG,WAAM,EAACC,uCAAwB,CAAC,EAChC,IAAAD,WAAM,EAACE,6CAA8B,CAAC,EACtC,IAAAF,WAAM,EAACG,wCAAyB,CAAC,CACpC,CAAC","ignoreList":[]}
@@ -12,6 +12,7 @@ var _utils2 = require("../../../../utils");
12
12
  var _constants = require("../constants");
13
13
  var _latestElasticsearchData = require("./latestElasticsearchData");
14
14
  var _getDecompressedData = require("../utils/getDecompressedData");
15
+ var _dbDynamodb = require("@webiny/db-dynamodb");
15
16
  const isGroupMigrationCompleted = status => {
16
17
  return typeof status === "boolean";
17
18
  };
@@ -180,8 +181,12 @@ class AcoRecords_5_37_0_003_AcoFolder {
180
181
  callback: async (folders, cursor) => {
181
182
  batch++;
182
183
  logger.info(`Processing batch #${batch} in group ${groupId} (${folders.length} folders).`);
183
- const ddbItems = [];
184
- const ddbEsItems = [];
184
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
185
+ entity: this.ddbEntryEntity
186
+ });
187
+ const elasticsearchEntityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
188
+ entity: this.ddbEsEntryEntity
189
+ });
185
190
  for (const folder of folders) {
186
191
  const folderPk = `T#${tenantId}#L#${localeCode}#CMS#CME#${folder.entryId}`;
187
192
  const ddbFolder = await (0, _utils2.get)({
@@ -215,7 +220,8 @@ class AcoRecords_5_37_0_003_AcoFolder {
215
220
  SK: "REV#0001",
216
221
  TYPE: "cms.entry"
217
222
  };
218
- ddbItems.push(this.ddbEntryEntity.putBatch(latestDdb), this.ddbEntryEntity.putBatch(revisionDdb));
223
+ entityBatch.put(latestDdb);
224
+ entityBatch.put(revisionDdb);
219
225
  const esLatestRecord = await (0, _utils2.get)({
220
226
  entity: this.ddbEsEntryEntity,
221
227
  keys: {
@@ -243,19 +249,13 @@ class AcoRecords_5_37_0_003_AcoFolder {
243
249
  data: esLatestData,
244
250
  index: foldersIndexName
245
251
  };
246
- ddbEsItems.push(this.ddbEsEntryEntity.putBatch(latestDdbEs));
252
+ elasticsearchEntityBatch.put(latestDdbEs);
247
253
  }
248
- const executeDdb = () => {
249
- return (0, _utils2.batchWriteAll)({
250
- table: this.ddbEntryEntity.table,
251
- items: ddbItems
252
- });
254
+ const executeDdb = async () => {
255
+ return entityBatch.execute();
253
256
  };
254
- const executeDdbEs = () => {
255
- return (0, _utils2.batchWriteAll)({
256
- table: this.ddbEsEntryEntity.table,
257
- items: ddbEsItems
258
- });
257
+ const executeDdbEs = async () => {
258
+ return elasticsearchEntityBatch.execute();
259
259
  };
260
260
  await (0, _utils.executeWithRetry)(executeDdb, {
261
261
  onFailedAttempt: error => {
@@ -1 +1 @@
1
- {"version":3,"names":["_utils","require","_createLocaleEntity","_createTenantEntity","_createEntryEntity","_utils2","_constants","_latestElasticsearchData","_getDecompressedData","isGroupMigrationCompleted","status","hasBuggedParent","folder","parentId","values","toLowerCase","ROOT_FOLDER","AcoRecords_5_37_0_003_AcoFolder","constructor","table","esTable","elasticsearchClient","ddbEntryEntity","createDdbEntryEntity","ddbEsEntryEntity","createDdbEsEntryEntity","localeEntity","createLocaleEntity","tenantEntity","createTenantEntity","getId","getDescription","createElasticsearchFolderBody","tenant","locale","query","bool","filter","term","should","UPPERCASE_ROOT_FOLDER","minimum_should_match","latest","sort","shouldExecute","logger","tenants","listTenants","length","info","locales","listLocales","data","id","indexExists","esGetIndexExist","code","type","ACO_FOLDER_MODEL_ID","isHeadlessCmsModel","body","esFindOne","index","esGetIndexName","undefined","execute","context","migrationStatus","checkpoint","tenantId","localeCode","groupId","batch","foldersIndexName","esQueryAllWithCallback","size","search_after","onError","error","x","JSON","stringify","includes","callback","folders","cursor","ddbItems","ddbEsItems","folderPk","entryId","ddbFolder","get","entity","keys","PK","SK","warn","latestDdb","TYPE","revisionDdb","push","putBatch","esLatestRecord","esRecord","getDecompressedData","esLatestData","getElasticsearchLatestEntryData","latestDdbEs","executeDdb","batchWriteAll","items","executeDdbEs","executeWithRetry","onFailedAttempt","attemptNumber","message","runningOutOfTime","createCheckpointAndExit","createCheckpoint","queryAll","partitionKey","options","gte","exports"],"sources":["AcoFolderMigration.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { PrimitiveValue, SearchBody } from \"@webiny/api-elasticsearch/types\";\nimport { DataMigration, DataMigrationContext } from \"@webiny/data-migration\";\nimport { executeWithRetry } from \"@webiny/utils\";\nimport { createLocaleEntity } from \"../entities/createLocaleEntity\";\nimport { createTenantEntity } from \"../entities/createTenantEntity\";\nimport { createDdbEntryEntity, createDdbEsEntryEntity } from \"../entities/createEntryEntity\";\nimport {\n batchWriteAll,\n BatchWriteItem,\n esFindOne,\n esGetIndexExist,\n esGetIndexName,\n esQueryAllWithCallback,\n get,\n queryAll\n} from \"~/utils\";\nimport { CmsEntryAcoFolder, I18NLocale, ListLocalesParams, Tenant } from \"../types\";\nimport { ACO_FOLDER_MODEL_ID, ROOT_FOLDER, UPPERCASE_ROOT_FOLDER } from \"../constants\";\nimport { getElasticsearchLatestEntryData } from \"./latestElasticsearchData\";\nimport { getDecompressedData } from \"~/migrations/5.37.0/003/utils/getDecompressedData\";\n\nconst isGroupMigrationCompleted = (\n status: PrimitiveValue[] | boolean | undefined\n): status is boolean => {\n return typeof status === \"boolean\";\n};\n\nconst hasBuggedParent = (folder: CmsEntryAcoFolder): boolean => {\n const parentId = (folder.values.parentId || \"\").toLowerCase();\n return parentId === ROOT_FOLDER;\n};\n\nexport type AcoFolderDataMigrationCheckpoint = Record<\n string,\n PrimitiveValue[] | boolean | undefined\n>;\n\ninterface CmsEntryAcoFolderElasticsearchRecord {\n PK: string;\n SK: string;\n index: string;\n data: any;\n}\n\nexport class AcoRecords_5_37_0_003_AcoFolder\n implements DataMigration<AcoFolderDataMigrationCheckpoint>\n{\n private readonly elasticsearchClient: Client;\n private readonly ddbEntryEntity: ReturnType<typeof createDdbEntryEntity>;\n private readonly ddbEsEntryEntity: ReturnType<typeof createDdbEsEntryEntity>;\n private readonly localeEntity: ReturnType<typeof createLocaleEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n\n constructor(\n table: Table<string, string, string>,\n esTable: Table<string, string, string>,\n elasticsearchClient: Client\n ) {\n this.elasticsearchClient = elasticsearchClient;\n this.ddbEntryEntity = createDdbEntryEntity(table);\n this.ddbEsEntryEntity = createDdbEsEntryEntity(esTable);\n this.localeEntity = createLocaleEntity(table);\n this.tenantEntity = createTenantEntity(table);\n }\n\n getId() {\n return \"AcoFolderParentId\";\n }\n\n getDescription() {\n return \"Fix the ACO Folders having set ROOT as parentId\";\n }\n\n private createElasticsearchFolderBody(tenant: string, locale: string): Partial<SearchBody> {\n return {\n query: {\n bool: {\n filter: [\n { term: { \"tenant.keyword\": tenant } },\n { term: { \"locale.keyword\": locale } },\n {\n bool: {\n should: [\n {\n term: {\n \"values.parentId.keyword\": ROOT_FOLDER\n }\n },\n {\n term: {\n \"values.parentId.keyword\": UPPERCASE_ROOT_FOLDER\n }\n }\n ],\n minimum_should_match: 1\n }\n },\n { term: { latest: true } }\n ]\n }\n },\n sort: [\n {\n \"id.keyword\": \"asc\"\n }\n ]\n };\n }\n\n async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n const tenants = await this.listTenants();\n if (tenants.length === 0) {\n logger.info(`No tenants found in the system; skipping migration.`);\n return false;\n }\n\n for (const tenant of tenants) {\n const locales = await this.listLocales({ tenant });\n if (locales.length === 0) {\n logger.info(`No locales found in tenant \"${tenant.data.id}\".`);\n continue;\n }\n\n for (const locale of locales) {\n // there is an index? NO -> skip\n const indexExists = await esGetIndexExist({\n elasticsearchClient: this.elasticsearchClient,\n tenant: tenant.data.id,\n locale: locale.code,\n type: ACO_FOLDER_MODEL_ID,\n isHeadlessCmsModel: true\n });\n\n if (!indexExists) {\n logger.info(\n `No Elasticsearch index found for folders in tenant \"${tenant.data.id}\" and locale \"${locale.code}\"; skipping.`\n );\n continue;\n }\n\n const body = this.createElasticsearchFolderBody(tenant.data.id, locale.code);\n const folder = await esFindOne<CmsEntryAcoFolder>({\n elasticsearchClient: this.elasticsearchClient,\n index: esGetIndexName({\n tenant: tenant.data.id,\n locale: locale.code,\n type: ACO_FOLDER_MODEL_ID,\n isHeadlessCmsModel: true\n }),\n body: {\n ...body,\n sort: undefined\n }\n });\n if (!folder) {\n logger.info(\n `No folder with wrong parentId found in tenant \"${tenant.data.id}\" and locale \"${locale.code}\"; skipping.`\n );\n continue;\n }\n\n return true;\n }\n }\n return false;\n }\n\n async execute({\n logger,\n ...context\n }: DataMigrationContext<AcoFolderDataMigrationCheckpoint>): Promise<void> {\n const tenants = await this.listTenants();\n\n const migrationStatus: AcoFolderDataMigrationCheckpoint = context.checkpoint || {};\n\n for (const tenant of tenants) {\n const locales = await this.listLocales({ tenant });\n\n const tenantId = tenant.data.id;\n\n for (const locale of locales) {\n const localeCode = locale.code;\n const groupId = `${tenantId}:${localeCode}`;\n\n const status = migrationStatus[groupId];\n\n if (isGroupMigrationCompleted(status)) {\n continue;\n }\n\n // there is an index? NO -> skip\n const indexExists = await esGetIndexExist({\n elasticsearchClient: this.elasticsearchClient,\n tenant: tenant.data.id,\n locale: locale.code,\n type: ACO_FOLDER_MODEL_ID,\n isHeadlessCmsModel: true\n });\n\n if (!indexExists) {\n /**\n * No need to do anything with this index as it doesn't exist - querying will produce error.\n */\n continue;\n }\n\n let batch = 0;\n\n const foldersIndexName = esGetIndexName({\n tenant: tenant.data.id,\n locale: locale.code,\n type: ACO_FOLDER_MODEL_ID,\n isHeadlessCmsModel: true\n });\n\n await esQueryAllWithCallback<CmsEntryAcoFolder>({\n elasticsearchClient: this.elasticsearchClient,\n index: foldersIndexName,\n body: {\n ...this.createElasticsearchFolderBody(tenantId, localeCode),\n size: 500,\n search_after: status\n },\n onError: error => {\n const x = JSON.stringify(error);\n if (x.includes(\"No mapping found\")) {\n return;\n }\n throw error;\n },\n callback: async (folders, cursor) => {\n batch++;\n logger.info(\n `Processing batch #${batch} in group ${groupId} (${folders.length} folders).`\n );\n\n const ddbItems: BatchWriteItem[] = [];\n const ddbEsItems: BatchWriteItem[] = [];\n\n for (const folder of folders) {\n const folderPk = `T#${tenantId}#L#${localeCode}#CMS#CME#${folder.entryId}`;\n const ddbFolder = await get<CmsEntryAcoFolder>({\n entity: this.ddbEntryEntity,\n keys: {\n PK: folderPk,\n SK: \"REV#0001\"\n }\n });\n if (!ddbFolder) {\n logger.warn(\n `Missing DDB item with PK \"${folderPk}\", SK \"REV#0001\"; skipping.`\n );\n continue;\n } else if (!hasBuggedParent(ddbFolder)) {\n continue;\n }\n\n const values = {\n ...ddbFolder.values,\n parentId: null\n };\n\n const latestDdb = {\n ...ddbFolder,\n values,\n PK: folderPk,\n SK: \"L\",\n TYPE: \"cms.entry.l\"\n };\n\n const revisionDdb = {\n ...ddbFolder,\n values,\n PK: folderPk,\n SK: \"REV#0001\",\n TYPE: \"cms.entry\"\n };\n\n ddbItems.push(\n this.ddbEntryEntity.putBatch(latestDdb),\n this.ddbEntryEntity.putBatch(revisionDdb)\n );\n\n const esLatestRecord = await get<CmsEntryAcoFolderElasticsearchRecord>({\n entity: this.ddbEsEntryEntity,\n keys: {\n PK: folderPk,\n SK: \"L\"\n }\n });\n if (!esLatestRecord) {\n continue;\n }\n\n const esRecord = await getDecompressedData<CmsEntryAcoFolder>(\n esLatestRecord.data\n );\n if (!esRecord) {\n continue;\n }\n\n const esLatestData = await getElasticsearchLatestEntryData({\n ...esRecord,\n values: {\n ...esRecord.values,\n parentId: null\n }\n });\n\n const latestDdbEs = {\n PK: folderPk,\n SK: \"L\",\n data: esLatestData,\n index: foldersIndexName\n };\n\n ddbEsItems.push(this.ddbEsEntryEntity.putBatch(latestDdbEs));\n }\n\n const executeDdb = () => {\n return batchWriteAll({\n table: this.ddbEntryEntity.table,\n items: ddbItems\n });\n };\n\n const executeDdbEs = () => {\n return batchWriteAll({\n table: this.ddbEsEntryEntity.table,\n items: ddbEsItems\n });\n };\n\n await executeWithRetry(executeDdb, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll ddb\" attempt #${error.attemptNumber} failed.`\n );\n logger.error(error.message);\n }\n });\n\n await executeWithRetry(executeDdbEs, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll ddb + es\" attempt #${error.attemptNumber} failed.`\n );\n logger.error(error.message);\n }\n });\n\n // Update checkpoint after every batch\n migrationStatus[groupId] = cursor;\n\n // Check if we should store checkpoint and exit.\n if (context.runningOutOfTime()) {\n await context.createCheckpointAndExit(migrationStatus);\n } else {\n await context.createCheckpoint(migrationStatus);\n }\n }\n });\n\n migrationStatus[groupId] = true;\n await context.createCheckpoint(migrationStatus);\n }\n }\n }\n\n private async listTenants(): Promise<Tenant[]> {\n return await queryAll<Tenant>({\n entity: this.tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n });\n }\n\n private async listLocales({ tenant }: ListLocalesParams): Promise<I18NLocale[]> {\n return await queryAll<I18NLocale>({\n entity: this.localeEntity,\n partitionKey: `T#${tenant.data.id}#I18N#L`,\n options: {\n gte: \" \"\n }\n });\n }\n}\n"],"mappings":";;;;;;AAIA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAWA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,wBAAA,GAAAN,OAAA;AACA,IAAAO,oBAAA,GAAAP,OAAA;AAEA,MAAMQ,yBAAyB,GAC3BC,MAA8C,IA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,uBAAgB,EAACD,YAAY,EAAE;cACjCE,eAAe,EAAEnC,KAAK,IAAI;gBACtBjC,MAAM,CAACiC,KAAK,CACP,qCAAoCA,KAAK,CAACoC,aAAc,UAC7D,CAAC;gBACDrE,MAAM,CAACiC,KAAK,CAACA,KAAK,CAACqC,OAAO,CAAC;cAC/B;YACJ,CAAC,CAAC;;YAEF;YACAhD,eAAe,CAACI,OAAO,CAAC,GAAGc,MAAM;;YAEjC;YACA,IAAInB,OAAO,CAACkD,gBAAgB,CAAC,CAAC,EAAE;cAC5B,MAAMlD,OAAO,CAACmD,uBAAuB,CAAClD,eAAe,CAAC;YAC1D,CAAC,MAAM;cACH,MAAMD,OAAO,CAACoD,gBAAgB,CAACnD,eAAe,CAAC;YACnD;UACJ;QACJ,CAAC,CAAC;QAEFA,eAAe,CAACI,OAAO,CAAC,GAAG,IAAI;QAC/B,MAAML,OAAO,CAACoD,gBAAgB,CAACnD,eAAe,CAAC;MACnD;IACJ;EACJ;EAEA,MAAcpB,WAAWA,CAAA,EAAsB;IAC3C,OAAO,MAAM,IAAAwE,gBAAQ,EAAS;MAC1B3B,MAAM,EAAE,IAAI,CAAChE,YAAY;MACzB4F,YAAY,EAAE,SAAS;MACvBC,OAAO,EAAE;QACL3D,KAAK,EAAE,MAAM;QACb4D,GAAG,EAAE;MACT;IACJ,CAAC,CAAC;EACN;EAEA,MAAcvE,WAAWA,CAAC;IAAElB;EAA0B,CAAC,EAAyB;IAC5E,OAAO,MAAM,IAAAsF,gBAAQ,EAAa;MAC9B3B,MAAM,EAAE,IAAI,CAAClE,YAAY;MACzB8F,YAAY,EAAG,KAAIvF,MAAM,CAACmB,IAAI,CAACC,EAAG,SAAQ;MAC1CoE,OAAO,EAAE;QACLC,GAAG,EAAE;MACT;IACJ,CAAC,CAAC;EACN;AACJ;AAACC,OAAA,CAAA1G,+BAAA,GAAAA,+BAAA","ignoreList":[]}
1
+ {"version":3,"names":["_utils","require","_createLocaleEntity","_createTenantEntity","_createEntryEntity","_utils2","_constants","_latestElasticsearchData","_getDecompressedData","_dbDynamodb","isGroupMigrationCompleted","status","hasBuggedParent","folder","parentId","values","toLowerCase","ROOT_FOLDER","AcoRecords_5_37_0_003_AcoFolder","constructor","table","esTable","elasticsearchClient","ddbEntryEntity","createDdbEntryEntity","ddbEsEntryEntity","createDdbEsEntryEntity","localeEntity","createLocaleEntity","tenantEntity","createTenantEntity","getId","getDescription","createElasticsearchFolderBody","tenant","locale","query","bool","filter","term","should","UPPERCASE_ROOT_FOLDER","minimum_should_match","latest","sort","shouldExecute","logger","tenants","listTenants","length","info","locales","listLocales","data","id","indexExists","esGetIndexExist","code","type","ACO_FOLDER_MODEL_ID","isHeadlessCmsModel","body","esFindOne","index","esGetIndexName","undefined","execute","context","migrationStatus","checkpoint","tenantId","localeCode","groupId","batch","foldersIndexName","esQueryAllWithCallback","size","search_after","onError","error","x","JSON","stringify","includes","callback","folders","cursor","entityBatch","createEntityWriteBatch","entity","elasticsearchEntityBatch","folderPk","entryId","ddbFolder","get","keys","PK","SK","warn","latestDdb","TYPE","revisionDdb","put","esLatestRecord","esRecord","getDecompressedData","esLatestData","getElasticsearchLatestEntryData","latestDdbEs","executeDdb","executeDdbEs","executeWithRetry","onFailedAttempt","attemptNumber","message","runningOutOfTime","createCheckpointAndExit","createCheckpoint","queryAll","partitionKey","options","gte","exports"],"sources":["AcoFolderMigration.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport { PrimitiveValue, SearchBody } from \"@webiny/api-elasticsearch/types\";\nimport { DataMigration, DataMigrationContext } from \"@webiny/data-migration\";\nimport { executeWithRetry } from \"@webiny/utils\";\nimport { createLocaleEntity } from \"../entities/createLocaleEntity\";\nimport { createTenantEntity } from \"../entities/createTenantEntity\";\nimport { createDdbEntryEntity, createDdbEsEntryEntity } from \"../entities/createEntryEntity\";\nimport {\n esFindOne,\n esGetIndexExist,\n esGetIndexName,\n esQueryAllWithCallback,\n get,\n queryAll\n} from \"~/utils\";\nimport { CmsEntryAcoFolder, I18NLocale, ListLocalesParams, Tenant } from \"../types\";\nimport { ACO_FOLDER_MODEL_ID, ROOT_FOLDER, UPPERCASE_ROOT_FOLDER } from \"../constants\";\nimport { getElasticsearchLatestEntryData } from \"./latestElasticsearchData\";\nimport { getDecompressedData } from \"~/migrations/5.37.0/003/utils/getDecompressedData\";\nimport { createEntityWriteBatch } from \"@webiny/db-dynamodb\";\n\nconst isGroupMigrationCompleted = (\n status: PrimitiveValue[] | boolean | undefined\n): status is boolean => {\n return typeof status === \"boolean\";\n};\n\nconst hasBuggedParent = (folder: CmsEntryAcoFolder): boolean => {\n const parentId = (folder.values.parentId || \"\").toLowerCase();\n return parentId === ROOT_FOLDER;\n};\n\nexport type AcoFolderDataMigrationCheckpoint = Record<\n string,\n PrimitiveValue[] | boolean | undefined\n>;\n\ninterface CmsEntryAcoFolderElasticsearchRecord {\n PK: string;\n SK: string;\n index: string;\n data: any;\n}\n\nexport class AcoRecords_5_37_0_003_AcoFolder\n implements DataMigration<AcoFolderDataMigrationCheckpoint>\n{\n private readonly elasticsearchClient: Client;\n private readonly ddbEntryEntity: ReturnType<typeof createDdbEntryEntity>;\n private readonly ddbEsEntryEntity: ReturnType<typeof createDdbEsEntryEntity>;\n private readonly localeEntity: ReturnType<typeof createLocaleEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n\n constructor(\n table: Table<string, string, string>,\n esTable: Table<string, string, string>,\n elasticsearchClient: Client\n ) {\n this.elasticsearchClient = elasticsearchClient;\n this.ddbEntryEntity = createDdbEntryEntity(table);\n this.ddbEsEntryEntity = createDdbEsEntryEntity(esTable);\n this.localeEntity = createLocaleEntity(table);\n this.tenantEntity = createTenantEntity(table);\n }\n\n getId() {\n return \"AcoFolderParentId\";\n }\n\n getDescription() {\n return \"Fix the ACO Folders having set ROOT as parentId\";\n }\n\n private createElasticsearchFolderBody(tenant: string, locale: string): Partial<SearchBody> {\n return {\n query: {\n bool: {\n filter: [\n { term: { \"tenant.keyword\": tenant } },\n { term: { \"locale.keyword\": locale } },\n {\n bool: {\n should: [\n {\n term: {\n \"values.parentId.keyword\": ROOT_FOLDER\n }\n },\n {\n term: {\n \"values.parentId.keyword\": UPPERCASE_ROOT_FOLDER\n }\n }\n ],\n minimum_should_match: 1\n }\n },\n { term: { latest: true } }\n ]\n }\n },\n sort: [\n {\n \"id.keyword\": \"asc\"\n }\n ]\n };\n }\n\n async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n const tenants = await this.listTenants();\n if (tenants.length === 0) {\n logger.info(`No tenants found in the system; skipping migration.`);\n return false;\n }\n\n for (const tenant of tenants) {\n const locales = await this.listLocales({ tenant });\n if (locales.length === 0) {\n logger.info(`No locales found in tenant \"${tenant.data.id}\".`);\n continue;\n }\n\n for (const locale of locales) {\n // there is an index? NO -> skip\n const indexExists = await esGetIndexExist({\n elasticsearchClient: this.elasticsearchClient,\n tenant: tenant.data.id,\n locale: locale.code,\n type: ACO_FOLDER_MODEL_ID,\n isHeadlessCmsModel: true\n });\n\n if (!indexExists) {\n logger.info(\n `No Elasticsearch index found for folders in tenant \"${tenant.data.id}\" and locale \"${locale.code}\"; skipping.`\n );\n continue;\n }\n\n const body = this.createElasticsearchFolderBody(tenant.data.id, locale.code);\n const folder = await esFindOne<CmsEntryAcoFolder>({\n elasticsearchClient: this.elasticsearchClient,\n index: esGetIndexName({\n tenant: tenant.data.id,\n locale: locale.code,\n type: ACO_FOLDER_MODEL_ID,\n isHeadlessCmsModel: true\n }),\n body: {\n ...body,\n sort: undefined\n }\n });\n if (!folder) {\n logger.info(\n `No folder with wrong parentId found in tenant \"${tenant.data.id}\" and locale \"${locale.code}\"; skipping.`\n );\n continue;\n }\n\n return true;\n }\n }\n return false;\n }\n\n async execute({\n logger,\n ...context\n }: DataMigrationContext<AcoFolderDataMigrationCheckpoint>): Promise<void> {\n const tenants = await this.listTenants();\n\n const migrationStatus: AcoFolderDataMigrationCheckpoint = context.checkpoint || {};\n\n for (const tenant of tenants) {\n const locales = await this.listLocales({ tenant });\n\n const tenantId = tenant.data.id;\n\n for (const locale of locales) {\n const localeCode = locale.code;\n const groupId = `${tenantId}:${localeCode}`;\n\n const status = migrationStatus[groupId];\n\n if (isGroupMigrationCompleted(status)) {\n continue;\n }\n\n // there is an index? NO -> skip\n const indexExists = await esGetIndexExist({\n elasticsearchClient: this.elasticsearchClient,\n tenant: tenant.data.id,\n locale: locale.code,\n type: ACO_FOLDER_MODEL_ID,\n isHeadlessCmsModel: true\n });\n\n if (!indexExists) {\n /**\n * No need to do anything with this index as it doesn't exist - querying will produce error.\n */\n continue;\n }\n\n let batch = 0;\n\n const foldersIndexName = esGetIndexName({\n tenant: tenant.data.id,\n locale: locale.code,\n type: ACO_FOLDER_MODEL_ID,\n isHeadlessCmsModel: true\n });\n\n await esQueryAllWithCallback<CmsEntryAcoFolder>({\n elasticsearchClient: this.elasticsearchClient,\n index: foldersIndexName,\n body: {\n ...this.createElasticsearchFolderBody(tenantId, localeCode),\n size: 500,\n search_after: status\n },\n onError: error => {\n const x = JSON.stringify(error);\n if (x.includes(\"No mapping found\")) {\n return;\n }\n throw error;\n },\n callback: async (folders, cursor) => {\n batch++;\n logger.info(\n `Processing batch #${batch} in group ${groupId} (${folders.length} folders).`\n );\n\n const entityBatch = createEntityWriteBatch({\n entity: this.ddbEntryEntity\n });\n const elasticsearchEntityBatch = createEntityWriteBatch({\n entity: this.ddbEsEntryEntity\n });\n\n for (const folder of folders) {\n const folderPk = `T#${tenantId}#L#${localeCode}#CMS#CME#${folder.entryId}`;\n const ddbFolder = await get<CmsEntryAcoFolder>({\n entity: this.ddbEntryEntity,\n keys: {\n PK: folderPk,\n SK: \"REV#0001\"\n }\n });\n if (!ddbFolder) {\n logger.warn(\n `Missing DDB item with PK \"${folderPk}\", SK \"REV#0001\"; skipping.`\n );\n continue;\n } else if (!hasBuggedParent(ddbFolder)) {\n continue;\n }\n\n const values = {\n ...ddbFolder.values,\n parentId: null\n };\n\n const latestDdb = {\n ...ddbFolder,\n values,\n PK: folderPk,\n SK: \"L\",\n TYPE: \"cms.entry.l\"\n };\n\n const revisionDdb = {\n ...ddbFolder,\n values,\n PK: folderPk,\n SK: \"REV#0001\",\n TYPE: \"cms.entry\"\n };\n\n entityBatch.put(latestDdb);\n entityBatch.put(revisionDdb);\n\n const esLatestRecord = await get<CmsEntryAcoFolderElasticsearchRecord>({\n entity: this.ddbEsEntryEntity,\n keys: {\n PK: folderPk,\n SK: \"L\"\n }\n });\n if (!esLatestRecord) {\n continue;\n }\n\n const esRecord = await getDecompressedData<CmsEntryAcoFolder>(\n esLatestRecord.data\n );\n if (!esRecord) {\n continue;\n }\n\n const esLatestData = await getElasticsearchLatestEntryData({\n ...esRecord,\n values: {\n ...esRecord.values,\n parentId: null\n }\n });\n\n const latestDdbEs = {\n PK: folderPk,\n SK: \"L\",\n data: esLatestData,\n index: foldersIndexName\n };\n\n elasticsearchEntityBatch.put(latestDdbEs);\n }\n\n const executeDdb = async () => {\n return entityBatch.execute();\n };\n\n const executeDdbEs = async () => {\n return elasticsearchEntityBatch.execute();\n };\n\n await executeWithRetry(executeDdb, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll ddb\" attempt #${error.attemptNumber} failed.`\n );\n logger.error(error.message);\n }\n });\n\n await executeWithRetry(executeDdbEs, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll ddb + es\" attempt #${error.attemptNumber} failed.`\n );\n logger.error(error.message);\n }\n });\n\n // Update checkpoint after every batch\n migrationStatus[groupId] = cursor;\n\n // Check if we should store checkpoint and exit.\n if (context.runningOutOfTime()) {\n await context.createCheckpointAndExit(migrationStatus);\n } else {\n await context.createCheckpoint(migrationStatus);\n }\n }\n });\n\n migrationStatus[groupId] = true;\n await context.createCheckpoint(migrationStatus);\n }\n }\n }\n\n private async listTenants(): Promise<Tenant[]> {\n return await queryAll<Tenant>({\n entity: this.tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n });\n }\n\n private async listLocales({ tenant }: ListLocalesParams): Promise<I18NLocale[]> {\n return await queryAll<I18NLocale>({\n entity: this.localeEntity,\n partitionKey: `T#${tenant.data.id}#I18N#L`,\n options: {\n gte: \" \"\n }\n });\n }\n}\n"],"mappings":";;;;;;AAIA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AASA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,wBAAA,GAAAN,OAAA;AACA,IAAAO,oBAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAR,OAAA;AAEA,MAAMS,yBAAyB,GAC3BC,MAA8C,IAC1B;EACpB,OAAO,OAAOA,MAAM,KAAK,SAAS;AACtC,CAAC;AAED,MAAMC,eAAe,GAAIC,MAAyB,IAAc;EAC5D,MAAMC,QAAQ,GAAG,CAACD,MAAM,CAACE,MAAM,CAACD,QAAQ,IAAI,EAAE,EAAEE,WAAW,CAAC,CAAC;EAC7D,OAAOF,QAAQ,KAAKG,sBAAW;AACnC,CAAC;AAcM,MAAMC,+BAA+B,CAE5C;EAOIC,WAAWA,CACPC,KAAoC,EACpCC,OAAsC,EACtCC,mBAA2B,EAC7B;IACE,IAAI,CAACA,mBAAmB,GAAGA,mBAAmB;IAC9C,IAAI,CAACC,cAAc,GAAG,IAAAC,uCAAoB,EAACJ,KAAK,CAAC;IACjD,IAAI,CAACK,gBAAgB,GAAG,IAAAC,yCAAsB,EAACL,OAAO,CAAC;IACvD,IAAI,CAACM,YAAY,GAAG,IAAAC,sCAAkB,EAACR,KAAK,CAAC;IAC7C,IAAI,CAACS,YAAY,GAAG,IAAAC,sCAAkB,EAACV,KAAK,CAAC;EACjD;EAEAW,KAAKA,CAAA,EAAG;IACJ,OAAO,m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D,GAAG,EAAE;MACT;IACJ,CAAC,CAAC;EACN;EAEA,MAAcrE,WAAWA,CAAC;IAAElB;EAA0B,CAAC,EAAyB;IAC5E,OAAO,MAAM,IAAAoF,gBAAQ,EAAa;MAC9B7B,MAAM,EAAE,IAAI,CAAC9D,YAAY;MACzB4F,YAAY,EAAG,KAAIrF,MAAM,CAACmB,IAAI,CAACC,EAAG,SAAQ;MAC1CkE,OAAO,EAAE;QACLC,GAAG,EAAE;MACT;IACJ,CAAC,CAAC;EACN;AACJ;AAACC,OAAA,CAAAxG,+BAAA,GAAAA,+BAAA","ignoreList":[]}
@@ -10,6 +10,7 @@ var _ioc = require("@webiny/ioc");
10
10
  var _utils2 = require("@webiny/utils");
11
11
  var _createBlockEntity = require("./createBlockEntity");
12
12
  var _compression = require("./compression");
13
+ var _dbDynamodb = require("@webiny/db-dynamodb");
13
14
  const isGroupMigrationCompleted = status => {
14
15
  return typeof status === "boolean";
15
16
  };
@@ -82,21 +83,23 @@ class PbUniqueBlockElementIds_5_40_0_001 {
82
83
  }, async blocks => {
83
84
  batch++;
84
85
  logger.info(`Processing batch #${batch} in group ${groupId} (${blocks.length} blocks).`);
86
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
87
+ entity: this.blockEntity
88
+ });
85
89
  const items = await Promise.all(blocks.map(async block => {
86
90
  const newContent = await this.generateElementIds(block);
87
91
  if (!newContent) {
88
92
  return null;
89
93
  }
90
- return this.blockEntity.putBatch({
94
+ const item = {
91
95
  ...block,
92
96
  content: newContent
93
- });
97
+ };
98
+ entityBatch.put(item);
99
+ return item;
94
100
  }));
95
- const execute = () => {
96
- return (0, _utils.batchWriteAll)({
97
- table: this.blockEntity.table,
98
- items: items.filter(Boolean)
99
- });
101
+ const execute = async () => {
102
+ return await entityBatch.execute();
100
103
  };
101
104
  await (0, _utils2.executeWithRetry)(execute, {
102
105
  onFailedAttempt: error => {
@@ -1 +1 @@
1
- {"version":3,"names":["_dataMigration","require","_utils","_ioc","_utils2","_createBlockEntity","_compression","isGroupMigrationCompleted","status","PbUniqueBlockElementIds_5_40_0_001","constructor","table","blockEntity","createBlockEntity","getId","getDescription","shouldExecute","logger","forEachTenantLocale","callback","tenantId","localeCode","blocksCount","count","entity","partitionKey","options","index","execute","context","migrationStatus","checkpoint","batch","groupId","ddbQueryAllWithCallback","gt","blocks","info","length","items","Promise","all","map","block","newContent","generateElementIds","putBatch","content","batchWriteAll","filter","Boolean","executeWithRetry","onFailedAttempt","error","attemptNumber","console","log","id","runningOutOfTime","createCheckpointAndExit","createCheckpoint","decompress","contentWithIds","ensureElementId","compress","element","data","variableId","generateAlphaNumericId","elements","exports","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["index.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport {\n DataMigration,\n DataMigrationContext,\n PrimaryDynamoTableSymbol\n} from \"@webiny/data-migration\";\nimport {\n batchWriteAll,\n BatchWriteItem,\n count,\n ddbQueryAllWithCallback,\n forEachTenantLocale\n} from \"~/utils\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { executeWithRetry, generateAlphaNumericId } from \"@webiny/utils\";\nimport { createBlockEntity } from \"~/migrations/5.40.0/001/ddb/createBlockEntity\";\nimport { ContentElement, PageBlock } from \"./types\";\nimport { compress, decompress } from \"./compression\";\n\nconst isGroupMigrationCompleted = (status: boolean | undefined): status is boolean => {\n return typeof status === \"boolean\";\n};\n\nexport class PbUniqueBlockElementIds_5_40_0_001 implements DataMigration {\n private readonly table: Table<string, string, string>;\n private readonly blockEntity: ReturnType<typeof createBlockEntity>;\n\n constructor(table: Table<string, string, string>) {\n this.table = table;\n this.blockEntity = createBlockEntity(table);\n }\n\n getId() {\n return \"5.40.0-001\";\n }\n\n getDescription() {\n return \"Generate unique element IDs in existing PB blocks.\";\n }\n\n async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n let shouldExecute = false;\n\n await forEachTenantLocale({\n table: this.table,\n logger,\n callback: async ({ tenantId, localeCode }) => {\n // We simply need to find out if there are any blocks stored in the system.\n const blocksCount = await count({\n entity: this.blockEntity,\n partitionKey: `T#${tenantId}#L#${localeCode}#PB#BLOCKS`,\n options: {\n index: \"GSI1\"\n }\n });\n\n if (blocksCount > 0) {\n shouldExecute = true;\n return false;\n }\n\n // Continue to the next locale.\n return true;\n }\n });\n\n return shouldExecute;\n }\n\n async execute({ logger, ...context }: DataMigrationContext): Promise<void> {\n const migrationStatus = context.checkpoint || {};\n\n let batch = 0;\n\n await forEachTenantLocale({\n table: this.table,\n logger,\n callback: async ({ tenantId, localeCode }) => {\n const groupId = `${tenantId}:${localeCode}`;\n const status = migrationStatus[groupId];\n\n if (isGroupMigrationCompleted(status)) {\n return true;\n }\n\n await ddbQueryAllWithCallback<PageBlock>(\n {\n entity: this.blockEntity,\n partitionKey: `T#${tenantId}#L#${localeCode}#PB#BLOCKS`,\n options: {\n index: \"GSI1\",\n gt: status || \" \"\n }\n },\n async blocks => {\n batch++;\n\n logger.info(\n `Processing batch #${batch} in group ${groupId} (${blocks.length} blocks).`\n );\n\n const items = await Promise.all(\n blocks.map(async block => {\n const newContent = await this.generateElementIds(block);\n if (!newContent) {\n return null;\n }\n\n return this.blockEntity.putBatch({\n ...block,\n content: newContent\n });\n })\n );\n\n const execute = () => {\n return batchWriteAll({\n table: this.blockEntity.table,\n items: items.filter(Boolean) as BatchWriteItem[]\n });\n };\n\n await executeWithRetry(execute, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll\" attempt #${error.attemptNumber} failed.`\n );\n console.log(items);\n console.log(error);\n }\n });\n\n // Update checkpoint after every batch\n migrationStatus[groupId] = blocks[blocks.length - 1]?.id;\n\n // Check if we should store checkpoint and exit.\n if (context.runningOutOfTime()) {\n await context.createCheckpointAndExit(migrationStatus);\n } else {\n await context.createCheckpoint(migrationStatus);\n }\n }\n );\n\n // Mark group as completed.\n migrationStatus[groupId] = true;\n\n // Store checkpoint.\n await context.createCheckpoint(migrationStatus);\n\n // Continue processing.\n return true;\n }\n });\n }\n\n private async generateElementIds(block: PageBlock) {\n const { content } = await decompress(block);\n\n // If block content already has an `id`, it means the block was already migrated.\n if (content.id) {\n return null;\n }\n\n const contentWithIds = this.ensureElementId(content);\n return compress(contentWithIds);\n }\n\n private ensureElementId(element: ContentElement): ContentElement {\n const id = element.id || element.data.variableId || generateAlphaNumericId(10);\n\n return {\n ...element,\n id,\n elements: element.elements.map(element => this.ensureElementId(element))\n };\n }\n}\n\nmakeInjectable(PbUniqueBlockElementIds_5_40_0_001, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AAKA,IAAAC,MAAA,GAAAD,OAAA;AAOA,IAAAE,IAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AAEA,MAAMM,yBAAyB,GAAIC,MAA2B,IAAwB;EAClF,OAAO,OAAOA,MAAM,KAAK,SAAS;AACtC,CAAC;AAEM,MAAMC,kCAAkC,CAA0B;EAIrEC,WAAWA,CAACC,KAAoC,EAAE;IAC9C,IAAI,CAACA,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,WAAW,GAAG,IAAAC,oCAAiB,EAACF,KAAK,CAAC;EAC/C;EAEAG,KAAKA,CAAA,EAAG;IACJ,OAAO,YAAY;EACvB;EAEAC,cAAcA,CAAA,EAAG;IACb,OAAO,oDAAoD;EAC/D;EAEA,MAAMC,aAAaA,CAAC;IAAEC;EAA6B,CAAC,EAAoB;IACpE,IAAID,aAAa,GAAG,KAAK;IAEzB,MAAM,IAAAE,0BAAmB,EAAC;MACtBP,KAAK,EAAE,IAAI,CAACA,KAAK;MACjBM,MAAM;MACNE,QAAQ,EAAE,MAAAA,CAAO;QAAEC,QAAQ;QAAEC;MAAW,CAAC,KAAK;QAC1C;QACA,MAAMC,WAAW,GAAG,MAAM,IAAA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C;QACA,OAAO,IAAI;MACf;IACJ,CAAC,CAAC;EACN;EAEA,MAAce,kBAAkBA,CAACF,KAAgB,EAAE;IAC/C,MAAM;MAAEI;IAAQ,CAAC,GAAG,MAAM,IAAAc,uBAAU,EAAClB,KAAK,CAAC;;IAE3C;IACA,IAAII,OAAO,CAACU,EAAE,EAAE;MACZ,OAAO,IAAI;IACf;IAEA,MAAMK,cAAc,GAAG,IAAI,CAACC,eAAe,CAAChB,OAAO,CAAC;IACpD,OAAO,IAAAiB,qBAAQ,EAACF,cAAc,CAAC;EACnC;EAEQC,eAAeA,CAACE,OAAuB,EAAkB;IAC7D,MAAMR,EAAE,GAAGQ,OAAO,CAACR,EAAE,IAAIQ,OAAO,CAACC,IAAI,CAACC,UAAU,IAAI,IAAAC,8BAAsB,EAAC,EAAE,CAAC;IAE9E,OAAO;MACH,GAAGH,OAAO;MACVR,EAAE;MACFY,QAAQ,EAAEJ,OAAO,CAACI,QAAQ,CAAC3B,GAAG,CAACuB,OAAO,IAAI,IAAI,CAACF,eAAe,CAACE,OAAO,CAAC;IAC3E,CAAC;EACL;AACJ;AAACK,OAAA,CAAA7D,kCAAA,GAAAA,kCAAA;AAED,IAAA8D,mBAAc,EAAC9D,kCAAkC,EAAE,CAAC,IAAA+D,WAAM,EAACC,uCAAwB,CAAC,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_dataMigration","require","_utils","_ioc","_utils2","_createBlockEntity","_compression","_dbDynamodb","isGroupMigrationCompleted","status","PbUniqueBlockElementIds_5_40_0_001","constructor","table","blockEntity","createBlockEntity","getId","getDescription","shouldExecute","logger","forEachTenantLocale","callback","tenantId","localeCode","blocksCount","count","entity","partitionKey","options","index","execute","context","migrationStatus","checkpoint","batch","groupId","ddbQueryAllWithCallback","gt","blocks","info","length","entityBatch","createEntityWriteBatch","items","Promise","all","map","block","newContent","generateElementIds","item","content","put","executeWithRetry","onFailedAttempt","error","attemptNumber","console","log","id","runningOutOfTime","createCheckpointAndExit","createCheckpoint","decompress","contentWithIds","ensureElementId","compress","element","data","variableId","generateAlphaNumericId","elements","exports","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["index.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport {\n DataMigration,\n DataMigrationContext,\n PrimaryDynamoTableSymbol\n} from \"@webiny/data-migration\";\nimport { count, ddbQueryAllWithCallback, forEachTenantLocale } from \"~/utils\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { executeWithRetry, generateAlphaNumericId } from \"@webiny/utils\";\nimport { createBlockEntity } from \"~/migrations/5.40.0/001/ddb/createBlockEntity\";\nimport { ContentElement, PageBlock } from \"./types\";\nimport { compress, decompress } from \"./compression\";\nimport { createEntityWriteBatch } from \"@webiny/db-dynamodb\";\n\nconst isGroupMigrationCompleted = (status: boolean | undefined): status is boolean => {\n return typeof status === \"boolean\";\n};\n\nexport class PbUniqueBlockElementIds_5_40_0_001 implements DataMigration {\n private readonly table: Table<string, string, string>;\n private readonly blockEntity: ReturnType<typeof createBlockEntity>;\n\n constructor(table: Table<string, string, string>) {\n this.table = table;\n this.blockEntity = createBlockEntity(table);\n }\n\n getId() {\n return \"5.40.0-001\";\n }\n\n getDescription() {\n return \"Generate unique element IDs in existing PB blocks.\";\n }\n\n async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n let shouldExecute = false;\n\n await forEachTenantLocale({\n table: this.table,\n logger,\n callback: async ({ tenantId, localeCode }) => {\n // We simply need to find out if there are any blocks stored in the system.\n const blocksCount = await count({\n entity: this.blockEntity,\n partitionKey: `T#${tenantId}#L#${localeCode}#PB#BLOCKS`,\n options: {\n index: \"GSI1\"\n }\n });\n\n if (blocksCount > 0) {\n shouldExecute = true;\n return false;\n }\n\n // Continue to the next locale.\n return true;\n }\n });\n\n return shouldExecute;\n }\n\n async execute({ logger, ...context }: DataMigrationContext): Promise<void> {\n const migrationStatus = context.checkpoint || {};\n\n let batch = 0;\n\n await forEachTenantLocale({\n table: this.table,\n logger,\n callback: async ({ tenantId, localeCode }) => {\n const groupId = `${tenantId}:${localeCode}`;\n const status = migrationStatus[groupId];\n\n if (isGroupMigrationCompleted(status)) {\n return true;\n }\n\n await ddbQueryAllWithCallback<PageBlock>(\n {\n entity: this.blockEntity,\n partitionKey: `T#${tenantId}#L#${localeCode}#PB#BLOCKS`,\n options: {\n index: \"GSI1\",\n gt: status || \" \"\n }\n },\n async blocks => {\n batch++;\n\n logger.info(\n `Processing batch #${batch} in group ${groupId} (${blocks.length} blocks).`\n );\n\n const entityBatch = createEntityWriteBatch({\n entity: this.blockEntity\n });\n\n const items = await Promise.all(\n blocks.map(async block => {\n const newContent = await this.generateElementIds(block);\n if (!newContent) {\n return null;\n }\n\n const item = {\n ...block,\n content: newContent\n };\n entityBatch.put(item);\n return item;\n })\n );\n\n const execute = async () => {\n return await entityBatch.execute();\n };\n\n await executeWithRetry(execute, {\n onFailedAttempt: error => {\n logger.error(\n `\"batchWriteAll\" attempt #${error.attemptNumber} failed.`\n );\n console.log(items);\n console.log(error);\n }\n });\n\n // Update checkpoint after every batch\n migrationStatus[groupId] = blocks[blocks.length - 1]?.id;\n\n // Check if we should store checkpoint and exit.\n if (context.runningOutOfTime()) {\n await context.createCheckpointAndExit(migrationStatus);\n } else {\n await context.createCheckpoint(migrationStatus);\n }\n }\n );\n\n // Mark group as completed.\n migrationStatus[groupId] = true;\n\n // Store checkpoint.\n await context.createCheckpoint(migrationStatus);\n\n // Continue processing.\n return true;\n }\n });\n }\n\n private async generateElementIds(block: PageBlock) {\n const { content } = await decompress(block);\n\n // If block content already has an `id`, it means the block was already migrated.\n if (content.id) {\n return null;\n }\n\n const contentWithIds = this.ensureElementId(content);\n return compress(contentWithIds);\n }\n\n private ensureElementId(element: ContentElement): ContentElement {\n const id = element.id || element.data.variableId || generateAlphaNumericId(10);\n\n return {\n ...element,\n id,\n elements: element.elements.map(element => this.ensureElementId(element))\n };\n }\n}\n\nmakeInjectable(PbUniqueBlockElementIds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Ae,CAACd,OAAO,CAAC;IACpD,OAAO,IAAAe,qBAAQ,EAACF,cAAc,CAAC;EACnC;EAEQC,eAAeA,CAACE,OAAuB,EAAkB;IAC7D,MAAMR,EAAE,GAAGQ,OAAO,CAACR,EAAE,IAAIQ,OAAO,CAACC,IAAI,CAACC,UAAU,IAAI,IAAAC,8BAAsB,EAAC,EAAE,CAAC;IAE9E,OAAO;MACH,GAAGH,OAAO;MACVR,EAAE;MACFY,QAAQ,EAAEJ,OAAO,CAACI,QAAQ,CAACzB,GAAG,CAACqB,OAAO,IAAI,IAAI,CAACF,eAAe,CAACE,OAAO,CAAC;IAC3E,CAAC;EACL;AACJ;AAACK,OAAA,CAAA7D,kCAAA,GAAAA,kCAAA;AAED,IAAA8D,mBAAc,EAAC9D,kCAAkC,EAAE,CAAC,IAAA+D,WAAM,EAACC,uCAAwB,CAAC,CAAC,CAAC","ignoreList":[]}
@@ -10,6 +10,7 @@ var _createTenantEntity = require("./createTenantEntity");
10
10
  var _createUserEntity = require("./createUserEntity");
11
11
  var _ioc = require("@webiny/ioc");
12
12
  var _utils2 = require("@webiny/utils");
13
+ var _dbDynamodb = require("@webiny/db-dynamodb");
13
14
  class AdminUsers_5_41_0_001 {
14
15
  constructor(table) {
15
16
  this.newUserEntity = (0, _createUserEntity.createUserEntity)(table);
@@ -66,20 +67,22 @@ class AdminUsers_5_41_0_001 {
66
67
  logger.info(`No users found on tenant "${tenant.data.id}".`);
67
68
  continue;
68
69
  }
69
- const newUsers = users.filter(user => !Array.isArray(user.data.groups)).map(user => {
70
- return this.newUserEntity.putBatch({
71
- ...user,
72
- data: {
73
- ...user.data,
74
- groups: [user.data.group].filter(Boolean),
75
- teams: [user.data.team].filter(Boolean)
76
- }
77
- });
70
+ const newUsersEntityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
71
+ entity: this.newUserEntity,
72
+ put: users.filter(user => !Array.isArray(user.data.groups)).map(user => {
73
+ return {
74
+ ...user,
75
+ data: {
76
+ ...user.data,
77
+ groups: [user.data.group].filter(Boolean),
78
+ teams: [user.data.team].filter(Boolean)
79
+ }
80
+ };
81
+ })
82
+ });
83
+ await (0, _utils2.executeWithRetry)(async () => {
84
+ return await newUsersEntityBatch.execute();
78
85
  });
79
- await (0, _utils2.executeWithRetry)(() => (0, _utils.batchWriteAll)({
80
- table: this.newUserEntity.table,
81
- items: newUsers
82
- }));
83
86
  }
84
87
  }
85
88
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_dataMigration","require","_utils","_createTenantEntity","_createUserEntity","_ioc","_utils2","AdminUsers_5_41_0_001","constructor","table","newUserEntity","createUserEntity","tenantEntity","createTenantEntity","getId","getDescription","shouldExecute","logger","user","queryOne","entity","partitionKey","options","index","gt","info","Array","isArray","data","groups","execute","tenants","queryAll","tenant","users","id","length","newUsers","filter","map","putBatch","group","Boolean","teams","team","executeWithRetry","batchWriteAll","items","exports","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["index.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { DataMigrationContext, PrimaryDynamoTableSymbol } from \"@webiny/data-migration\";\nimport { queryOne, queryAll, batchWriteAll } from \"~/utils\";\nimport { createTenantEntity } from \"./createTenantEntity\";\nimport { createUserEntity } from \"./createUserEntity\";\nimport { makeInjectable, inject } from \"@webiny/ioc\";\nimport { executeWithRetry } from \"@webiny/utils\";\n\nexport class AdminUsers_5_41_0_001 {\n private readonly newUserEntity: ReturnType<typeof createUserEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n\n constructor(table: Table<string, string, string>) {\n this.newUserEntity = createUserEntity(table);\n this.tenantEntity = createTenantEntity(table);\n }\n\n getId() {\n return \"5.41.0-001\";\n }\n\n getDescription() {\n return \"Introduce 'groups' and 'teams` properties (old 'group' and 'team' are no longer in use)\";\n }\n\n async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n const user = await queryOne<{ data: any }>({\n entity: this.newUserEntity,\n partitionKey: `T#root#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n if (!user) {\n logger.info(`No users were found; skipping migration.`);\n return false;\n }\n\n if (Array.isArray(user.data.groups)) {\n logger.info(`User records seems to be in order; skipping migration.`);\n return false;\n }\n\n return true;\n }\n\n async execute({ logger }: DataMigrationContext): Promise<void> {\n const tenants = await queryAll<{ data: { id: string; name: string } }>({\n entity: this.tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n for (const tenant of tenants) {\n const users = await queryAll<{ id: string; email: string; data?: any }>({\n entity: this.newUserEntity,\n partitionKey: `T#${tenant.data.id}#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n if (users.length === 0) {\n logger.info(`No users found on tenant \"${tenant.data.id}\".`);\n continue;\n }\n\n const newUsers = users\n .filter(user => !Array.isArray(user.data.groups))\n .map(user => {\n return this.newUserEntity.putBatch({\n ...user,\n data: {\n ...user.data,\n groups: [user.data.group].filter(Boolean),\n teams: [user.data.team].filter(Boolean)\n }\n });\n });\n\n await executeWithRetry(() =>\n batchWriteAll({ table: this.newUserEntity.table, items: newUsers })\n );\n }\n }\n}\n\nmakeInjectable(AdminUsers_5_41_0_001, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAEO,MAAMM,qBAAqB,CAAC;EAI/BC,WAAWA,CAACC,KAAoC,EAAE;IAC9C,IAAI,CAACC,aAAa,GAAG,IAAAC,kCAAgB,EAACF,KAAK,CAAC;IAC5C,IAAI,CAACG,YAAY,GAAG,IAAAC,sCAAkB,EAACJ,KAAK,CAAC;EACjD;EAEAK,KAAK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ACQ,IAAI,CAAE,6BAA4BQ,MAAM,CAACL,IAAI,CAACO,EAAG,IAAG,CAAC;QAC5D;MACJ;MAEA,MAAME,QAAQ,GAAGH,KAAK,CACjBI,MAAM,CAACpB,IAAI,IAAI,CAACQ,KAAK,CAACC,OAAO,CAACT,IAAI,CAACU,IAAI,CAACC,MAAM,CAAC,CAAC,CAChDU,GAAG,CAACrB,IAAI,IAAI;QACT,OAAO,IAAI,CAACR,aAAa,CAAC8B,QAAQ,CAAC;UAC/B,GAAGtB,IAAI;UACPU,IAAI,EAAE;YACF,GAAGV,IAAI,CAACU,IAAI;YACZC,MAAM,EAAE,CAACX,IAAI,CAACU,IAAI,CAACa,KAAK,CAAC,CAACH,MAAM,CAACI,OAAO,CAAC;YACzCC,KAAK,EAAE,CAACzB,IAAI,CAACU,IAAI,CAACgB,IAAI,CAAC,CAACN,MAAM,CAACI,OAAO;UAC1C;QACJ,CAAC,CAAC;MACN,CAAC,CAAC;MAEN,MAAM,IAAAG,wBAAgB,EAAC,MACnB,IAAAC,oBAAa,EAAC;QAAErC,KAAK,EAAE,IAAI,CAACC,aAAa,CAACD,KAAK;QAAEsC,KAAK,EAAEV;MAAS,CAAC,CACtE,CAAC;IACL;EACJ;AACJ;AAACW,OAAA,CAAAzC,qBAAA,GAAAA,qBAAA;AAED,IAAA0C,mBAAc,EAAC1C,qBAAqB,EAAE,CAAC,IAAA2C,WAAM,EAACC,uCAAwB,CAAC,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_dataMigration","require","_utils","_createTenantEntity","_createUserEntity","_ioc","_utils2","_dbDynamodb","AdminUsers_5_41_0_001","constructor","table","newUserEntity","createUserEntity","tenantEntity","createTenantEntity","getId","getDescription","shouldExecute","logger","user","queryOne","entity","partitionKey","options","index","gt","info","Array","isArray","data","groups","execute","tenants","queryAll","tenant","users","id","length","newUsersEntityBatch","createEntityWriteBatch","put","filter","map","group","Boolean","teams","team","executeWithRetry","exports","makeInjectable","inject","PrimaryDynamoTableSymbol"],"sources":["index.ts"],"sourcesContent":["import { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { DataMigrationContext, PrimaryDynamoTableSymbol } from \"@webiny/data-migration\";\nimport { queryAll, queryOne } from \"~/utils\";\nimport { createTenantEntity } from \"./createTenantEntity\";\nimport { createUserEntity } from \"./createUserEntity\";\nimport { inject, makeInjectable } from \"@webiny/ioc\";\nimport { executeWithRetry } from \"@webiny/utils\";\nimport { createEntityWriteBatch } from \"@webiny/db-dynamodb\";\n\nexport class AdminUsers_5_41_0_001 {\n private readonly newUserEntity: ReturnType<typeof createUserEntity>;\n private readonly tenantEntity: ReturnType<typeof createTenantEntity>;\n\n constructor(table: Table<string, string, string>) {\n this.newUserEntity = createUserEntity(table);\n this.tenantEntity = createTenantEntity(table);\n }\n\n getId() {\n return \"5.41.0-001\";\n }\n\n getDescription() {\n return \"Introduce 'groups' and 'teams` properties (old 'group' and 'team' are no longer in use)\";\n }\n\n async shouldExecute({ logger }: DataMigrationContext): Promise<boolean> {\n const user = await queryOne<{ data: any }>({\n entity: this.newUserEntity,\n partitionKey: `T#root#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n if (!user) {\n logger.info(`No users were found; skipping migration.`);\n return false;\n }\n\n if (Array.isArray(user.data.groups)) {\n logger.info(`User records seems to be in order; skipping migration.`);\n return false;\n }\n\n return true;\n }\n\n async execute({ logger }: DataMigrationContext): Promise<void> {\n const tenants = await queryAll<{ data: { id: string; name: string } }>({\n entity: this.tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n for (const tenant of tenants) {\n const users = await queryAll<{ id: string; email: string; data?: any }>({\n entity: this.newUserEntity,\n partitionKey: `T#${tenant.data.id}#ADMIN_USERS`,\n options: {\n index: \"GSI1\",\n gt: \" \"\n }\n });\n\n if (users.length === 0) {\n logger.info(`No users found on tenant \"${tenant.data.id}\".`);\n continue;\n }\n\n const newUsersEntityBatch = createEntityWriteBatch({\n entity: this.newUserEntity,\n put: users\n .filter(user => !Array.isArray(user.data.groups))\n .map(user => {\n return {\n ...user,\n data: {\n ...user.data,\n groups: [user.data.group].filter(Boolean),\n teams: [user.data.team].filter(Boolean)\n }\n };\n })\n });\n\n await executeWithRetry(async () => {\n return await newUsersEntityBatch.execute();\n });\n }\n }\n}\n\nmakeInjectable(AdminUsers_5_41_0_001, [inject(PrimaryDynamoTableSymbol)]);\n"],"mappings":";;;;;;AACA,IAAAA,cAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AAEO,MAAMO,qBAAqB,CAAC;EAI/BC,WAAWA,CAACC,KAAoC,EAAE;IAC9C,IAAI,CAACC,aAAa,GAAG,IAAAC,kCAAgB,EAACF,KAAK,CAAC;IAC5C,IAAI,CAACG,YAAY,GAAG,IAAAC,sCAAkB,EAACJ,KAAK,CAAC;EACjD;EAEAK,KAAKA,CAAA,EAAG;IACJ,OAAO,YAAY;EACvB;EAEAC,cAAcA,CAAA,EAAG;IACb,OAAO,yFAAyF;EACpG;EAEA,MAAMC,aAAaA,CAAC;IAAEC;EAA6B,CAAC,EAAoB;IACpE,MAAMC,IAAI,GAAG,MAAM,IAAAC,eAAQ,EAAgB;MACvCC,MAAM,EAAE,IAAI,CAACV,aAAa;MAC1BW,YAAY,EAAG,oBAAmB;MAClCC,OAAO,EAAE;QACLC,KAAK,EAAE,MAAM;QACbC,EAAE,EAAE;MACR;IACJ,CAAC,CAAC;IAEF,IAAI,CAACN,IAAI,EAAE;MACPD,MAAM,CAACQ,IAAI,CAAE,0CAAyC,CAAC;MACvD,OAAO,KAAK;IAChB;IAEA,IAAIC,KAAK,CAACC,OAAO,CAACT,IAAI,CAACU,I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CAAC;cACzCC,KAAK,EAAE,CAAC1B,IAAI,CAACU,IAAI,CAACiB,IAAI,CAAC,CAACL,MAAM,CAACG,OAAO;YAC1C;UACJ,CAAC;QACL,CAAC;MACT,CAAC,CAAC;MAEF,MAAM,IAAAG,wBAAgB,EAAC,YAAY;QAC/B,OAAO,MAAMT,mBAAmB,CAACP,OAAO,CAAC,CAAC;MAC9C,CAAC,CAAC;IACN;EACJ;AACJ;AAACiB,OAAA,CAAAxC,qBAAA,GAAAA,qBAAA;AAED,IAAAyC,mBAAc,EAACzC,qBAAqB,EAAE,CAAC,IAAA0C,WAAM,EAACC,uCAAwB,CAAC,CAAC,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@webiny/migrations",
3
- "version": "5.41.4-beta.3",
3
+ "version": "5.41.4-beta.5",
4
4
  "scripts": {
5
5
  "build": "yarn webiny run build",
6
6
  "watch": "yarn webiny run watch"
7
7
  },
8
8
  "dependencies": {
9
9
  "@elastic/elasticsearch": "7.12.0",
10
- "@webiny/api-elasticsearch": "5.41.4-beta.3",
11
- "@webiny/aws-sdk": "5.41.4-beta.3",
12
- "@webiny/cli-plugin-deploy-pulumi": "5.41.4-beta.3",
13
- "@webiny/data-migration": "5.41.4-beta.3",
14
- "@webiny/db-dynamodb": "5.41.4-beta.3",
15
- "@webiny/error": "5.41.4-beta.3",
16
- "@webiny/ioc": "5.41.4-beta.3",
17
- "@webiny/logger": "5.41.4-beta.3",
18
- "@webiny/utils": "5.41.4-beta.3",
10
+ "@webiny/api-elasticsearch": "5.41.4-beta.5",
11
+ "@webiny/aws-sdk": "5.41.4-beta.5",
12
+ "@webiny/cli-plugin-deploy-pulumi": "5.41.4-beta.5",
13
+ "@webiny/data-migration": "5.41.4-beta.5",
14
+ "@webiny/db-dynamodb": "5.41.4-beta.5",
15
+ "@webiny/error": "5.41.4-beta.5",
16
+ "@webiny/ioc": "5.41.4-beta.5",
17
+ "@webiny/logger": "5.41.4-beta.5",
18
+ "@webiny/utils": "5.41.4-beta.5",
19
19
  "execa": "5.1.1",
20
20
  "fast-glob": "3.2.12",
21
21
  "jsonpack": "1.1.5",
@@ -30,16 +30,16 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/execa": "2.0.0",
33
- "@webiny/api-headless-cms": "5.41.4-beta.3",
34
- "@webiny/api-headless-cms-ddb-es": "5.41.4-beta.3",
35
- "@webiny/cli": "5.41.4-beta.3",
36
- "@webiny/handler-aws": "5.41.4-beta.3",
37
- "@webiny/plugins": "5.41.4-beta.3",
38
- "@webiny/project-utils": "5.41.4-beta.3",
33
+ "@webiny/api-headless-cms": "5.41.4-beta.5",
34
+ "@webiny/api-headless-cms-ddb-es": "5.41.4-beta.5",
35
+ "@webiny/cli": "5.41.4-beta.5",
36
+ "@webiny/handler-aws": "5.41.4-beta.5",
37
+ "@webiny/plugins": "5.41.4-beta.5",
38
+ "@webiny/project-utils": "5.41.4-beta.5",
39
39
  "elastic-ts": "0.8.0",
40
40
  "jest-dynalite": "3.6.1",
41
41
  "ttypescript": "1.5.15",
42
42
  "typescript": "4.9.5"
43
43
  },
44
- "gitHead": "1be3b755403a5151fd830e72ec31c6b83f49e292"
44
+ "gitHead": "e3f273ea63f0c426c2ddde0794d303bc8ffaa6c4"
45
45
  }
@@ -1,5 +1,14 @@
1
1
  import { Table } from "@webiny/db-dynamodb/toolbox";
2
2
  import { Logger } from "@webiny/logger";
3
+ export interface Tenant {
4
+ data: {
5
+ id: string;
6
+ name: string;
7
+ };
8
+ }
9
+ export interface I18NLocale {
10
+ code: string;
11
+ }
3
12
  type ForEachTenantLocaleCallback = (params: {
4
13
  tenantId: string;
5
14
  localeCode: string;
@@ -1 +1 @@
1
- {"version":3,"names":["_","require","forEachTenantLocale","table","logger","callback","tenantEntity","createTenantEntity","tenants","queryAll","entity","partitionKey","options","index","gte","length","info","localeEntity","createLocaleEntity","tenant","locales","data","id","locale","result","tenantId","localeCode","code","exports"],"sources":["forEachTenantLocale.ts"],"sourcesContent":["import { createLocaleEntity, createTenantEntity, queryAll } from \"~/utils\";\nimport { I18NLocale, Tenant } from \"~/migrations/5.37.0/003/types\";\nimport { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { Logger } from \"@webiny/logger\";\n\ntype ForEachTenantLocaleCallback = (params: {\n tenantId: string;\n localeCode: string;\n}) => boolean | Promise<boolean>;\n\ninterface ForEachTenantLocaleParams {\n table: Table<string, string, string>;\n logger: Logger;\n callback: ForEachTenantLocaleCallback;\n}\n\nexport const forEachTenantLocale = async ({\n table,\n logger,\n callback\n}: ForEachTenantLocaleParams) => {\n const tenantEntity = createTenantEntity(table);\n const tenants = await queryAll<Tenant>({\n entity: tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n });\n\n if (tenants.length === 0) {\n logger.info(`No tenants found in the system.`);\n return;\n }\n\n const localeEntity = createLocaleEntity(table);\n\n for (const tenant of tenants) {\n const locales = await queryAll<I18NLocale>({\n entity: localeEntity,\n partitionKey: `T#${tenant.data.id}#I18N#L`,\n options: {\n gte: \" \"\n }\n });\n\n if (locales.length === 0) {\n logger.info(`No locales found in tenant \"${tenant.data.id}\".`);\n continue;\n }\n\n for (const locale of locales) {\n const result = await callback({ tenantId: tenant.data.id, localeCode: locale.code });\n // For now, we only check if the return value is `false`. If so, we stop\n // iterating over the locales and tenants completely. If needed, we could\n // add more control over the iteration process.\n if (result === false) {\n return;\n }\n }\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,OAAA;AAgBO,MAAMC,mBAAmB,GAAG,MAAAA,CAAO;EACtCC,KAAK;EACLC,MAAM;EACNC;AACuB,CAAC,KAAK;EAC7B,MAAMC,YAAY,GAAG,IAAAC,oBAAkB,EAACJ,KAAK,CAAC;EAC9C,MAAMK,OAAO,GAAG,MAAM,IAAAC,UAAQ,EAAS;IACnCC,MAAM,EAAEJ,YAAY;IACpBK,YAAY,EAAE,SAAS;IACvBC,OAAO,EAAE;MACLC,KAAK,EAAE,MAAM;MACbC,GAAG,EAAE;IACT;EACJ,CAAC,CAAC;EAEF,IAAIN,OAAO,CAACO,MAAM,KAAK,CAAC,EAAE;IACtBX,MAAM,CAACY,IAAI,CAAE,iCAAgC,CAAC;IAC9C;EACJ;EAEA,MAAMC,YAAY,GAAG,IAAAC,oBAAkB,EAACf,KAAK,CAAC;EAE9C,KAAK,MAAMgB,MAAM,IAAIX,OAAO,EAAE;IAC1B,MAAMY,OAAO,GAAG,MAAM,IAAAX,UAAQ,EAAa;MACvCC,MAAM,EAAEO,YAAY;MACpBN,YAAY,EAAG,KAAIQ,MAAM,CAACE,IAAI,CAACC,EAAG,SAAQ;MAC1CV,OAAO,EAAE;QACLE,GAAG,EAAE;MACT;IACJ,CAAC,CAAC;IAEF,IAAIM,OAAO,CAACL,MAAM,KAAK,CAAC,EAAE;MACtBX,MAAM,CAACY,IAAI,CAAE,+BAA8BG,MAAM,CAACE,IAAI,CAACC,EAAG,IAAG,CAAC;MAC9D;IACJ;IAEA,KAAK,MAAMC,MAAM,IAAIH,OAAO,EAAE;MAC1B,MAAMI,MAAM,GAAG,MAAMnB,QAAQ,CAAC;QAAEoB,QAAQ,EAAEN,MAAM,CAACE,IAAI,CAACC,EAAE;QAAEI,UAAU,EAAEH,MAAM,CAACI;MAAK,CAAC,CAAC;MACpF;MACA;MACA;MACA,IAAIH,MAAM,KAAK,KAAK,EAAE;QAClB;MACJ;IACJ;EACJ;AACJ,CAAC;AAACI,OAAA,CAAA1B,mBAAA,GAAAA,mBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_","require","forEachTenantLocale","table","logger","callback","tenantEntity","createTenantEntity","tenants","queryAll","entity","partitionKey","options","index","gte","length","info","localeEntity","createLocaleEntity","tenant","locales","data","id","locale","result","tenantId","localeCode","code","exports"],"sources":["forEachTenantLocale.ts"],"sourcesContent":["import { createLocaleEntity, createTenantEntity, queryAll } from \"~/utils\";\nimport { Table } from \"@webiny/db-dynamodb/toolbox\";\nimport { Logger } from \"@webiny/logger\";\n\nexport interface Tenant {\n data: {\n id: string;\n name: string;\n };\n}\n\nexport interface I18NLocale {\n code: string;\n}\n\ntype ForEachTenantLocaleCallback = (params: {\n tenantId: string;\n localeCode: string;\n}) => boolean | Promise<boolean>;\n\ninterface ForEachTenantLocaleParams {\n table: Table<string, string, string>;\n logger: Logger;\n callback: ForEachTenantLocaleCallback;\n}\n\nexport const forEachTenantLocale = async ({\n table,\n logger,\n callback\n}: ForEachTenantLocaleParams) => {\n const tenantEntity = createTenantEntity(table);\n const tenants = await queryAll<Tenant>({\n entity: tenantEntity,\n partitionKey: \"TENANTS\",\n options: {\n index: \"GSI1\",\n gte: \" \"\n }\n });\n\n if (tenants.length === 0) {\n logger.info(`No tenants found in the system.`);\n return;\n }\n\n const localeEntity = createLocaleEntity(table);\n\n for (const tenant of tenants) {\n const locales = await queryAll<I18NLocale>({\n entity: localeEntity,\n partitionKey: `T#${tenant.data.id}#I18N#L`,\n options: {\n gte: \" \"\n }\n });\n\n if (locales.length === 0) {\n logger.info(`No locales found in tenant \"${tenant.data.id}\".`);\n continue;\n }\n\n for (const locale of locales) {\n const result = await callback({ tenantId: tenant.data.id, localeCode: locale.code });\n // For now, we only check if the return value is `false`. If so, we stop\n // iterating over the locales and tenants completely. If needed, we could\n // add more control over the iteration process.\n if (result === false) {\n return;\n }\n }\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,OAAA;AA0BO,MAAMC,mBAAmB,GAAG,MAAAA,CAAO;EACtCC,KAAK;EACLC,MAAM;EACNC;AACuB,CAAC,KAAK;EAC7B,MAAMC,YAAY,GAAG,IAAAC,oBAAkB,EAACJ,KAAK,CAAC;EAC9C,MAAMK,OAAO,GAAG,MAAM,IAAAC,UAAQ,EAAS;IACnCC,MAAM,EAAEJ,YAAY;IACpBK,YAAY,EAAE,SAAS;IACvBC,OAAO,EAAE;MACLC,KAAK,EAAE,MAAM;MACbC,GAAG,E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