summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20250820175727_create_nutrients.rb2
-rw-r--r--db/migrate/20250823142743_create_beds.rb11
-rw-r--r--db/migrate/20250823142858_create_rafts.rb13
-rw-r--r--db/migrate/20250901112954_rename_crops_to_nutrient_profiles.rb4
-rw-r--r--db/schema.rb22
-rw-r--r--db/seeds.rb3
-rw-r--r--db/seeds/Nutrient.rb22
-rw-r--r--db/seeds/NutrientProfile.rb7
-rw-r--r--db/seeds/Target.rb2
9 files changed, 30 insertions, 56 deletions
diff --git a/db/migrate/20250820175727_create_nutrients.rb b/db/migrate/20250820175727_create_nutrients.rb
index d054375..503df3f 100644
--- a/db/migrate/20250820175727_create_nutrients.rb
+++ b/db/migrate/20250820175727_create_nutrients.rb
@@ -3,8 +3,6 @@ class CreateNutrients < ActiveRecord::Migration[8.0]
create_table :nutrients do |t|
t.string :formula
t.string :name
-
- t.timestamps
end
end
end
diff --git a/db/migrate/20250823142743_create_beds.rb b/db/migrate/20250823142743_create_beds.rb
deleted file mode 100644
index 3c23ad7..0000000
--- a/db/migrate/20250823142743_create_beds.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-class CreateBeds < ActiveRecord::Migration[8.0]
- def change
- create_table :beds do |t|
- t.integer :location, null: false
-
- t.timestamps
- end
-
- add_index :beds, :location, unique: true
- end
-end
diff --git a/db/migrate/20250823142858_create_rafts.rb b/db/migrate/20250823142858_create_rafts.rb
deleted file mode 100644
index 6b7f006..0000000
--- a/db/migrate/20250823142858_create_rafts.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-class CreateRafts < ActiveRecord::Migration[8.0]
- def change
- create_table :rafts do |t|
- t.references :bed, null: false, foreign_key: true
- t.integer :location, null: false
- t.references :crop, null: true, foreign_key: true
-
- t.timestamps
- end
-
- add_index :rafts, [ :bed_id, :location ], unique: true
- end
-end
diff --git a/db/migrate/20250901112954_rename_crops_to_nutrient_profiles.rb b/db/migrate/20250901112954_rename_crops_to_nutrient_profiles.rb
index 5b46df1..4273204 100644
--- a/db/migrate/20250901112954_rename_crops_to_nutrient_profiles.rb
+++ b/db/migrate/20250901112954_rename_crops_to_nutrient_profiles.rb
@@ -1,10 +1,6 @@
class RenameCropsToNutrientProfiles < ActiveRecord::Migration[8.0]
def change
rename_table :crops, :nutrient_profiles
-
- rename_column :rafts, :crop_id, :crop_nutrient_need_id
- add_index :rafts, :crop_nutrient_need_id unless index_exists?(:rafts, :crop_nutrient_need_id)
-
remove_column :nutrient_profiles, :crop_type
end
end
diff --git a/db/schema.rb b/db/schema.rb
index d201f5a..0fe55a6 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,13 +11,6 @@
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_09_08_181147) do
- create_table "beds", force: :cascade do |t|
- t.integer "location", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["location"], name: "index_beds_on_location", unique: true
- end
-
create_table "fertilizer_components", force: :cascade do |t|
t.string "name"
t.string "formula"
@@ -107,19 +100,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_08_181147) do
create_table "nutrients", force: :cascade do |t|
t.string "formula"
t.string "name"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- end
-
- create_table "rafts", force: :cascade do |t|
- t.integer "bed_id", null: false
- t.integer "location", null: false
- t.integer "crop_nutrient_need_id"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["bed_id", "location"], name: "index_rafts_on_bed_id_and_location", unique: true
- t.index ["bed_id"], name: "index_rafts_on_bed_id"
- t.index ["crop_nutrient_need_id"], name: "index_rafts_on_crop_nutrient_need_id"
end
create_table "target_allocations", force: :cascade do |t|
@@ -140,8 +120,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_09_08_181147) do
add_foreign_key "fertilizer_compositions", "fertilizer_components"
add_foreign_key "fertilizer_compositions", "fertilizer_products"
- add_foreign_key "rafts", "beds"
- add_foreign_key "rafts", "nutrient_profiles", column: "crop_nutrient_need_id"
add_foreign_key "target_allocations", "nutrient_profiles"
add_foreign_key "target_allocations", "targets"
end
diff --git a/db/seeds.rb b/db/seeds.rb
index d5f046d..78810e3 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -8,7 +8,8 @@
# MovieGenre.find_or_create_by!(name: genre_name)
# end
-MODELS = [ NutrientMeasurement,
+MODELS = [ Nutrient,
+ NutrientMeasurement,
NutrientProfile,
Target
].freeze
diff --git a/db/seeds/Nutrient.rb b/db/seeds/Nutrient.rb
new file mode 100644
index 0000000..0b29cab
--- /dev/null
+++ b/db/seeds/Nutrient.rb
@@ -0,0 +1,22 @@
+nutrients = [
+ { formula: "NNO3", name: "Nitrate" },
+ { formula: "NNH4", name: "Ammonium" },
+ { formula: "P", name: "Phosphorus" },
+ { formula: "K", name: "Potassium" },
+ { formula: "Ca", name: "Calcium" },
+ { formula: "Mg", name: "Magnesium" },
+ { formula: "S", name: "Sulfur" },
+ { formula: "Na", name: "Sodium" },
+ { formula: "Cl", name: "Chloride" },
+ { formula: "Si", name: "Silicon" },
+ { formula: "Fe", name: "Iron" },
+ { formula: "Zn", name: "Zinc" },
+ { formula: "B", name: "Boron" },
+ { formula: "Mn", name: "Manganese" },
+ { formula: "Cu", name: "Copper" },
+ { formula: "Mo", name: "Molybdenum" }
+]
+
+nutrients.each do |attrs|
+ Nutrient.find_or_create_by!(attrs)
+end
diff --git a/db/seeds/NutrientProfile.rb b/db/seeds/NutrientProfile.rb
index 0c3c152..c9d80b3 100644
--- a/db/seeds/NutrientProfile.rb
+++ b/db/seeds/NutrientProfile.rb
@@ -1,4 +1,5 @@
-[ { name: "formule moyenne générale",
+profiles = [
+ { name: "formule moyenne générale",
nno3: 160.00,
p: 30.00,
k: 230.00,
@@ -102,7 +103,9 @@
mn: 0.11,
cu: 0.03,
mo: 0.01 }
-].each do |profile|
+]
+
+profiles.each do |profile|
NutrientProfile.find_or_create_by!(name: profile[:name]) do |p|
p.attributes = profile
end
diff --git a/db/seeds/Target.rb b/db/seeds/Target.rb
index 790fef7..bce0290 100644
--- a/db/seeds/Target.rb
+++ b/db/seeds/Target.rb
@@ -10,7 +10,7 @@ Target.transaction do
missing = wanted.keys - profiles.keys
raise "Missing NutrientProfile(s): #{missing.join(', ')}" if missing.any?
- target = Target.find_or_create_by!(name: "Objectif par défaut")
+ target = Target.find_or_create_by!(name: "Cible par défaut")
target.target_allocations.destroy_all
wanted.each do |name, pct|
Copyright 2019--2026 Marius PETER