Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase migrator timeout #2025

Merged
merged 12 commits into from
Oct 31, 2023
33 changes: 19 additions & 14 deletions services/app-api/src/dataMigrations/dataMigrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,26 @@ export function newDBMigrator(dbConnString: string): MigratorType {
async runMigrations(migrations: DBMigrationType[]) {
for (const migration of migrations) {
try {
await prismaClient.$transaction(async (tx) => {
const res = await migration.module.migrate(tx)

if (!(res instanceof Error)) {
await tx.protoMigrationsTable.create({
data: {
migrationName: migration.name,
},
})
} else {
console.error('migrator error:', res)
// Since we're inside a transaction block, we throw to abort the transaction
throw res
await prismaClient.$transaction(
async (tx) => {
const res = await migration.module.migrate(tx)

if (!(res instanceof Error)) {
await tx.protoMigrationsTable.create({
data: {
migrationName: migration.name,
},
})
} else {
console.error('migrator error:', res)
// Since we're inside a transaction block, we throw to abort the transaction
throw res
}
},
{
timeout: 20000, // 20 second timeout
}
})
)
} catch (err) {
console.info('Error came from transaction', migration, err)
return new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export async function migrate(
for (const contract of contracts) {
const finalRates: RateSet[] = []
// look at every contract revision from old to new
console.info('REVS', contract.revisions.length)
// console.info('REVS', contract.revisions.length)
for (const contractRev of contract.revisions) {
console.info('Start: ', finalRates)
// console.info('Start: ', finalRates)

// First, get the rates associated with this contract revision.
// Different for submitted and non-submitted revs.
Expand All @@ -90,11 +90,11 @@ export async function migrate(
(rr) => rr.validAfter <= submittedAt
)

console.info(
'any rates from before? ',
contractRev.rateRevisions.map((rr) => rr.validAfter),
submittedAt
)
// console.info(
// 'any rates from before? ',
// contractRev.rateRevisions.map((rr) => rr.validAfter),
// submittedAt
// )

// because we have join table entries for removals, filter out removals.
if (
Expand All @@ -117,8 +117,8 @@ export async function migrate(
}

// Now we have the rateRevisions associated with this contractRevision
console.info('Matchign Rates: ', associatedRates.length)
console.info('Second Pass')
// console.info('Matchign Rates: ', associatedRates.length)
// console.info('Second Pass')

for (let idx = 0; idx < associatedRates.length; idx++) {
const rateRev = associatedRates[idx]
Expand Down Expand Up @@ -159,7 +159,7 @@ export async function migrate(
}
}

console.info('setting draft rates', draftRateIDs)
// console.info('setting draft rates', draftRateIDs)
// now set to the correct rates.
await client.contractRevisionTable.update({
where: {
Expand All @@ -175,7 +175,7 @@ export async function migrate(
})
}

console.info('Got Rate Set', finalRates)
// console.info('Got Rate Set', finalRates)

// draftRates are going to be deleted, and we have a bug where we weren't resetting the
// draftRates of old revisions. So let's reset the draftRates for all our contractRevisions
Expand Down
Loading