From fa9dc6863c0619adf46e5170b6fac263c1858a8f Mon Sep 17 00:00:00 2001 From: Alan Cruikshanks Date: Thu, 10 Oct 2024 11:44:00 +0100 Subject: [PATCH] Fix error with return cycles seeder https://eaflood.atlassian.net/browse/WATER-4543 In [Create return cycle](https://github.com/DEFRA/water-abstraction-system/pull/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. --- db/seeds/16-return-cycles.seed.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/db/seeds/16-return-cycles.seed.js b/db/seeds/16-return-cycles.seed.js index faad5c0254..ddac1b6397 100644 --- a/db/seeds/16-return-cycles.seed.js +++ b/db/seeds/16-return-cycles.seed.js @@ -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 = {