diff options
author | Marius Peter <marius.peter@tutanota.com> | 2025-08-24 20:29:54 +0200 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2025-08-24 20:29:54 +0200 |
commit | 52b044d6a4278c229992404ad5801769c2d13363 (patch) | |
tree | b30b34da58f26117c035391d09366b190350b1e3 /db/seeds/6_fertilizer_products.rb |
First commit.
Vive le Castel Peter !
Diffstat (limited to 'db/seeds/6_fertilizer_products.rb')
-rw-r--r-- | db/seeds/6_fertilizer_products.rb | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/db/seeds/6_fertilizer_products.rb b/db/seeds/6_fertilizer_products.rb new file mode 100644 index 0000000..6769bde --- /dev/null +++ b/db/seeds/6_fertilizer_products.rb @@ -0,0 +1,143 @@ +FERTILIZER_RECIPES = [ + { + name: "Multi K Reci", + purity: 99.0, + composition: [ + { component: { + name: "Potassium nitrate", + formula: "KNO3", + nno3: 13.0, + k: 46.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Fixa Mn", + purity: 98.0, + composition: [ + { component: { + name: "Manganese sulfate", + formula: "MnSO4·H2O", + mn: 32.0, + s: 18.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Multi-Cal Haïfa", + purity: 99.0, + composition: [ + { component: { + name: "Calcium nitrate", + formula: "Ca(NO3)2·4H2O", + nno3: 15.5, + ca: 19.0 }, + percent_w: 100.0 } + ] + }, + { + name: "DAP 18/46/00", + purity: 100.0, + composition: [ + { component: { + name: "Diammonium phosphate", + formula: "(NH4)2HPO4", + nnh4: 18.0, + p: 20.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Patenkali", + purity: 100.0, + composition: [ + { component: { + name: "Potassium sulfate", + formula: "K2SO4", + k: 50.0, + s: 18.0 + }, percent_w: 100.0 } + ] + }, + { + name: "Eso Top", + purity: 100.0, + composition: [ + { component: { + name: "Magnesium sulfate", + formula: "MgSO4·7H2O", + mg: 9.8, + s: 13.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Ammonitrate 27", + purity: 100.0, + composition: [ + { component: { + name: "Ammonium nitrate", + formula: "NH4NO3", + nno3: 13.5, + nnh4: 13.5 }, + percent_w: 100.0 } + ] + }, + { + name: "Fer chélaté", + purity: 100.0, + composition: [ + { component: { + name: "Iron chelate (EDDHA)", + formula: "Fe-EDDHA", + fe: 6.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Carbonate de calcium", + purity: 100.0, + composition: [ + { component: { + name: "Calcium carbonate", + formula: "CaCO3", + ca: 40.0 }, + percent_w: 100.0 } + ] + }, + { + name: "Héliocuivre", + purity: 100.0, + composition: [ + { component: { + name: "Copper chelate (EDTA)", + formula: "Cu-EDTA", + cu: 14.0 }, + percent_w: 100.0 } + ] + } +] + +FERTILIZER_RECIPES.each do |recipe| + product = FertilizerProduct.find_or_create_by!(name: recipe[:name]) do |fp| + fp.purity = recipe[:purity] + end + + recipe[:composition].each do |c| + comp_attrs = c[:component] + component = FertilizerComponent.find_or_create_by!(name: comp_attrs[:name]) do |fc| + fc.formula = comp_attrs[:formula] + end + # update nutrient fields if missing + component.update!(comp_attrs.except(:name, :formula)) + + FertilizerComposition.find_or_create_by!( + fertilizer_product: product, + fertilizer_component: component + ) do |fc| + fc.percent_w = c[:percent_w] + end + end +end + +puts "FertilizerProducts: #{FertilizerProduct.count}" |