Skip to content

Commit

Permalink
Fix error with return cycles seeder
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4543

In [Create return cycle](#1353) we added a new seeder for return cycles.

They are part reference, part transactional records. When starting with a clean environment you would need to seed existing return cycles. Going forward, they are automatically created as part of creating returns logs. When we come to creating the first return log for a cycle, if the cycle record does not exist then we create it.

When we added the seeder though, the query we wrote was purely an insert. It should have been an `upsert` because seeders need to be written in such a way they can be run multiple times against the same environment (both test and 'real').

This fixes the query used to actually be an upsert.
  • Loading branch information
Cruikshanks committed Oct 10, 2024
1 parent 8cfb1b0 commit fa9dc68
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions db/seeds/16-return-cycles.seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ async function seed () {
async function _upsert (cycle) {
return ReturnCycleModel.query()
.insert({ ...cycle, createdAt: timestampForPostgres(), updatedAt: timestampForPostgres() })
.onConflict(['startDate', 'endDate', 'summer'])
.merge([
'dueDate',
'submittedInWrls',
'updatedAt'
])
}

module.exports = {
Expand Down

0 comments on commit fa9dc68

Please sign in to comment.