Skip to content

Commit

Permalink
Add as dataMigration
Browse files Browse the repository at this point in the history
  • Loading branch information
haworku committed Nov 3, 2023
1 parent 9996afc commit 1744498
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { PrismaTransactionType } from '../../postgres/prismaTypes'

export const migrateToDeleteContractOnlyRates = async (
client: PrismaTransactionType
): Promise<Error | void> => {
try {
// find those empty submitted rates by their revision
const badRateRevisions = await client.rateRevisionTable.findMany({
where: {
rateType: undefined,
submitInfo: {
isNot: null,
},
unlockInfo: {
is: null, // has to be submitted revision that is not yet unlocked
},
},
})
console.info(
`Found ${badRateRevisions.length} rate revisions to delete`
)

await client.rateRevisionTable.deleteMany({
where: {
id: {
in: badRateRevisions.map((rev) => rev.id),
},
},
})

// delete any empty rates
await client.rateTable.deleteMany({
where: {
revisions: {
none: {},
},
},
})
} catch (error) {
console.error(`Data migration ERROR: ${error}`)
}
}

0 comments on commit 1744498

Please sign in to comment.