Skip to content

Commit

Permalink
Temp fix for conflicting migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
howard-e committed Jan 11, 2024
1 parent 04cf7fc commit 6f8dfb9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
30 changes: 23 additions & 7 deletions server/migrations/20231219212344-recalculateV2TestHashes.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
testPlanVersionCount / testPlanVersionBatchSize
);

const knownHashedTests = [];
for (let i = 0; i < iterationsNeeded; i += 1) {
const multipleOf100 = i % testPlanVersionBatchSize === 0;
if (multipleOf100)
Expand All @@ -53,13 +54,28 @@ module.exports = {
testPlanVersions.map(async testPlanVersion => {
const hashedTests = hashTests(testPlanVersion.tests);

await queryInterface.sequelize.query(
`UPDATE "TestPlanVersion" SET "hashedTests" = ? WHERE id = ?`,
{
replacements: [hashedTests, testPlanVersion.id],
transaction
}
);
if (!knownHashedTests.includes(hashedTests)) {
knownHashedTests.push(hashedTests);
await queryInterface.sequelize.query(
`UPDATE "TestPlanVersion" SET "hashedTests" = ? WHERE id = ?`,
{
replacements: [
hashedTests,
testPlanVersion.id
],
transaction
}
);
} else {
// Remove any accidentally created TestPlanVersion rows
await queryInterface.sequelize.query(
`DELETE FROM "TestPlanVersion" WHERE id = ?`,
{
replacements: [testPlanVersion.id],
transaction
}
);
}
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = {
testPlanVersionCount / testPlanVersionBatchSize
);

const knownHashedTests = [];
for (let i = 0; i < iterationsNeeded; i += 1) {
const multipleOf100 = i % testPlanVersionBatchSize === 0;
if (multipleOf100)
Expand All @@ -52,13 +53,28 @@ module.exports = {
testPlanVersions.map(async testPlanVersion => {
const hashedTests = hashTests(testPlanVersion.tests);

await queryInterface.sequelize.query(
`UPDATE "TestPlanVersion" SET "hashedTests" = ? WHERE id = ?`,
{
replacements: [hashedTests, testPlanVersion.id],
transaction
}
);
if (!knownHashedTests.includes(hashedTests)) {
knownHashedTests.push(hashedTests);
await queryInterface.sequelize.query(
`UPDATE "TestPlanVersion" SET "hashedTests" = ? WHERE id = ?`,
{
replacements: [
hashedTests,
testPlanVersion.id
],
transaction
}
);
} else {
// Remove any accidentally created TestPlanVersion rows
await queryInterface.sequelize.query(
`DELETE FROM "TestPlanVersion" WHERE id = ?`,
{
replacements: [testPlanVersion.id],
transaction
}
);
}
})
);
}
Expand Down

0 comments on commit 6f8dfb9

Please sign in to comment.