From c585c7f8d521137e7a4e35abc39331e37bf29a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Maniaci?= Date: Sun, 22 Oct 2023 23:14:50 +0200 Subject: [PATCH] seeds: upsert the mefs --- db/seeds.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 7fdd34a62..04f96142f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -16,11 +16,7 @@ ministry: "MINISTERE" }.freeze -data.each do |entry| - code = entry[MAPPING[:code]] - - mef = Mef.find_or_initialize_by(code:) - +mefs = data.map do |entry| attributes = MAPPING.transform_values do |value| if value == "MINISTERE" Mef.ministries[entry[value].downcase] @@ -29,9 +25,11 @@ end end - mef.update!(attributes) + attributes end +Mef.upsert_all(mefs, unique_by: :code) # rubocop:disable Rails/SkipsModelValidations + logger.info "[seeds] done inserting MEF codes." logger.info "[seeds] inserting daily wages..."