-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Reset TestPlanVersion
nextval
during import if IDs aren't used (…
…#1153) * Reset TestPlanVersion nextval during import if ids go unused * Fix migration * Update id * Update testPlanVersion test id
- Loading branch information
Showing
3 changed files
with
488 additions
and
439 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
server/migrations/20240715150459-resetTestPlanVersionIdToLatest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
const { sequelize } = require('../models'); | ||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
return queryInterface.sequelize.transaction(async transaction => { | ||
const [latestTestPlanVersion] = await queryInterface.sequelize.query( | ||
`select id | ||
from "TestPlanVersion" | ||
order by id desc | ||
limit 1`, | ||
{ | ||
type: Sequelize.QueryTypes.SELECT, | ||
transaction | ||
} | ||
); | ||
|
||
if (latestTestPlanVersion) { | ||
await sequelize.query( | ||
`SELECT setval(pg_get_serial_sequence('"TestPlanVersion"', 'id'), :currentSequenceValue)`, | ||
{ | ||
replacements: { currentSequenceValue: latestTestPlanVersion.id }, | ||
transaction | ||
} | ||
); | ||
} | ||
}); | ||
}, | ||
|
||
async down() {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.