diff options
| author | Marius Peter <dev@marius-peter.com> | 2025-11-30 15:06:48 +0100 |
|---|---|---|
| committer | Marius Peter <dev@marius-peter.com> | 2025-11-30 15:06:48 +0100 |
| commit | 0411d731cf2018794b4f10154e3af8c875faa99c (patch) | |
| tree | f51bb2e335aa0285bfe5502969fb59d4df26f852 /db | |
| parent | a648653b1745474eef8274d72e633cf7e1d28be2 (diff) | |
Introduce crop rotations.
These will probably replace nutrient targets as the main entry point
for nutrient requirement calculations.
Diffstat (limited to 'db')
| -rw-r--r-- | db/migrations.rkt | 24 | ||||
| -rw-r--r-- | db/seed.rkt | 9 |
2 files changed, 33 insertions, 0 deletions
diff --git a/db/migrations.rkt b/db/migrations.rkt index dfb216e..86c9cce 100644 --- a/db/migrations.rkt +++ b/db/migrations.rkt @@ -143,6 +143,30 @@ #:constraints (primary-key id) (foreign-key crop_id #:references (crops id) #:on-delete #:cascade)))) +(define-migration "create table crop_rotations" + (list (create-table #:if-not-exists crop_rotations + #:columns [id integer #:not-null] + ;; ISO8601 date + [rotation_date text #:not-null] + [nutrient_measurement_id integer] + #:constraints (primary-key id) + (foreign-key nutrient_measurement_id + #:references (nutrient_measurements id) + #:on-delete + #:set-null) + (unique rotation_date)))) + +(define-migration + "create table crop_rotation_requirements" + (list (create-table + #:if-not-exists crop_rotation_requirements + #:columns [crop_rotation_id integer #:not-null] + [crop_requirement_id integer #:not-null] + [proportion_percent integer #:not-null] + #:constraints (primary-key crop_rotation_id crop_requirement_id) + (foreign-key crop_rotation_id #:references (crop_rotation id) #:on-delete #:cascade) + (foreign-key crop_requirement_id #:references (crop_requirement id) #:on-delete #:cascade)))) + ;;;;;;;;;;;;;; ;; FERTILIZERS ;;;;;;;;;;;;;; diff --git a/db/seed.rkt b/db/seed.rkt index d767d63..8d671ba 100644 --- a/db/seed.rkt +++ b/db/seed.rkt @@ -9,6 +9,7 @@ "../models/nutrient-measurement.rkt" "../models/crop.rkt" "../models/crop-requirement.rkt" + "../models/crop-rotation.rkt" "../models/fertilizer-product.rkt") (define (seed-database!) @@ -20,6 +21,7 @@ seed-historical-nutrient-measurements! seed-crops! seed-crop-requirements! + seed-initial-crop-rotation! seed-existing-fertilizer-products!)) (define (seed-nutrients!) @@ -90,6 +92,13 @@ [else (create-crop-requirement! profile nutrient-values)])) (with-tx (csv-for-each row->seed! next-row))) +(define (seed-initial-crop-rotation!) + (define nm (get-latest-nutrient-measurement)) + (define generic-requirement (get-crop-requirement #:profile "générique croissance")) + (create-crop-rotation! (nutrient-measurement-date nm) + (hash generic-requirement 100) + #:nutrient-measurement (nutrient-measurement-id nm))) + (define-runtime-path fertilizer-products-csv "data/dolibarr_fertilizer_compositions_percentage.csv") (define (seed-existing-fertilizer-products!) (define next-row (make-csv-reader (open-input-file fertilizer-products-csv))) |