Skip to content

Commit

Permalink
fix(migrations): handle scenarios when no data exists for a given locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed May 24, 2023
1 parent d3f7b13 commit e4092ac
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
Expand Up @@ -63,5 +63,22 @@ export const testData = [
_ct: "2023-01-25T09:38:22.381Z",
_et: "Settings",
_md: "2023-01-25T09:38:22.381Z"
},
{
PK: "T#root#I18N#L",
SK: "de",
code: "de",
createdBy: {
displayName: "Pavel Denisjuk",
id: "e6ea2871-ba36-4494-87ac-afb73d4e7eb2",
type: "admin"
},
createdOn: "2023-01-25T09:38:22.029Z",
default: false,
tenant: "root",
webinyVersion: "0.0.0",
_ct: "2023-01-25T09:38:22.041Z",
_et: "I18NLocale",
_md: "2023-01-25T09:38:22.041Z"
}
];
Expand Up @@ -170,4 +170,20 @@ describe("5.35.0-001", () => {
expect(secondData.skipped.length).toBe(1);
expect(spy).toHaveBeenCalledTimes(0);
});

it("should not fail of there are no files in any given locale", async () => {
await insertDynamoDbTestData(table, testData);
await insertTestFiles(5);

const handler = createDdbMigrationHandler({ table, migrations: [FileManager_5_35_0_001] });

// Should run the migration
process.stdout.write("[First run]\n");
const firstRun = await handler();
assertNotError(firstRun.error);
const firstData = groupMigrations(firstRun.data.migrations);
expect(firstData.executed.length).toBe(1);
expect(firstData.errored.length).toBe(0);
expect(firstData.skipped.length).toBe(0);
});
});
Expand Up @@ -82,6 +82,16 @@ export const createLocalesData = () => {
tenant: "root",
webinyVersion: "0.0.0"
},
{
PK: `T#root#I18N#L`,
SK: "fr",
code: "fr",
default: false,
createdOn: "2023-01-25T09:37:58.220Z",
createdBy,
tenant: "root",
webinyVersion: "0.0.0"
},
{
PK: `T#otherTenant#I18N#L`,
SK: "fr-FR",
Expand Down
Expand Up @@ -37,6 +37,8 @@ describe("5.35.0-006", () => {
for (const tenant of tenants) {
const locales = testLocales
.filter(item => item.PK === `T#${tenant}#I18N#L`)
// We want to keep `fr` locale empty (without any pages)
.filter(item => item.code !== `fr`)
.map(locale => locale.code) as string[];

for (const locale of locales) {
Expand Down Expand Up @@ -278,4 +280,20 @@ describe("5.35.0-006", () => {
expect(grouped.notApplicable.length).toBe(0);
}
});

it("should not fail of there are no pages in any given locale", async () => {
await insertTestData(table, [...createTenantsData(), ...createLocalesData()]);
await insertTestPages(5);

const handler = createDdbMigrationHandler({ table, migrations: [AcoRecords_5_35_0_006] });

// Should run the migration
process.stdout.write("[First run]\n");
const firstRun = await handler();
assertNotError(firstRun.error);
const firstData = groupMigrations(firstRun.data.migrations);
expect(firstData.executed.length).toBe(1);
expect(firstData.errored.length).toBe(0);
expect(firstData.skipped.length).toBe(0);
});
});
Expand Up @@ -163,7 +163,7 @@ export class FileManager_5_35_0_001_FileData implements DataMigration<FileMigrat
}
});

const cursor = files[files.length - 1].id;
const cursor = files[files.length - 1]?.id;

// Update checkpoint after every batch
migrationStatus[groupId] = cursor;
Expand Down
Expand Up @@ -170,7 +170,7 @@ export class AcoRecords_5_35_0_006_PageData implements DataMigration<PageDataMig
}
});

const cursor = pages[pages.length - 1].id;
const cursor = pages[pages.length - 1]?.id;

// Update checkpoint after every batch
migrationStatus[groupId] = cursor;
Expand Down

0 comments on commit e4092ac

Please sign in to comment.