Skip to content

Commit

Permalink
fixed seed migration when duplicates are present
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Jun 12, 2024
1 parent 79288f1 commit c943991
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/db/migrations/20240612062819-seed-wasm-codes-from-config.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import { QueryInterface } from 'sequelize'
import { QueryInterface, Sequelize } from 'sequelize'

import { WasmCodeService } from '@/services/wasm-codes'

module.exports = {
async up(queryInterface: QueryInterface) {
async up(queryInterface: QueryInterface, sequelize: Sequelize) {
// loads from config automatically
const codes = (await WasmCodeService.setUpInstance()).getWasmCodes()

await queryInterface.bulkInsert(
'WasmCodeKeys',
codes.map(({ codeKey }) => ({ codeKey }))
)
await queryInterface.bulkInsert(
'WasmCodeKeyIds',
codes.flatMap(({ codeKey, codeIds }) =>
codeIds.map((codeKeyId) => ({
codeKey,
codeKeyId,
}))
)
await Promise.all(
codes.map(async ({ codeKey, codeIds }) => {
await queryInterface.upsert(
'WasmCodeKeys',
{ codeKey },
{ codeKey },
{ codeKey },
{
model: sequelize.models.WasmCodeKey,
}
)

await Promise.all(
codeIds.map((codeKeyId) =>
queryInterface.upsert(
'WasmCodeKeyIds',
{ codeKey, codeKeyId },
{ codeKey, codeKeyId },
{ codeKey, codeKeyId },
{
model: sequelize.models.WasmCodeKeyId,
}
)
)
)
})
)
},
async down(queryInterface: QueryInterface) {
Expand Down

0 comments on commit c943991

Please sign in to comment.