backend/model/
entity.rs

1//! Contains all entities used in `PermaplanT`.
2//!
3//! The fill & error ratios in the file can be calculated and updated automatically
4//! via the script in /tools/update-fill-error-ratio/update-fill-error-ratio.py (usage in respective README)
5//!
6//! Latest script run was on 07.07.2026
7//! Git SHA of the scraper-data commit used: 4eeed7ea0fda9fa6f3a6771d4816ab8330bf81e8
8
9pub mod application_settings_impl;
10pub mod areas;
11pub mod areas_impl;
12pub mod base_layer_images;
13pub mod base_layer_images_impl;
14pub mod drawing_properties;
15pub mod drawing_properties_impl;
16pub mod drawings;
17pub mod drawings_impl;
18pub mod guided_tour_impl;
19pub mod layers;
20pub mod layers_impl;
21pub mod map_collaborator_impl;
22pub mod map_impl;
23pub mod plant_layer;
24pub mod plantings;
25pub mod plantings_impl;
26pub mod plants_impl;
27pub mod seed_impl;
28pub mod timeline;
29
30use chrono::NaiveDate;
31use chrono::NaiveDateTime;
32
33use diesel::AsChangeset;
34use diesel::QueryableByName;
35use diesel::{Identifiable, Insertable, Queryable};
36use postgis_diesel::types::Point;
37use postgis_diesel::types::Polygon;
38use uuid::Uuid;
39
40use crate::schema::{
41    application_settings, guided_tour_progress, guided_tour_states, map_collaborators, maps,
42    plants, seeds,
43};
44
45use super::r#enum::{
46    herbaceous_or_woody::HerbaceousOrWoody, life_cycle::LifeCycle,
47    light_requirement::LightRequirement, privacy_access_control::PrivacyAccessControl,
48    quality::Quality, quantity::Quantity, shade::Shade, soil_texture::SoilTextureEnum,
49    taxonomic_rank::TaxonomicRank, water_requirement::WaterRequirementEnum,
50};
51
52/// The `Plants` entity builds up an hierarchical structure, see `/doc/database/hierarchy.md`:
53///
54#[doc = include_str!("../../../doc/database/hierarchy.md")]
55///
56#[derive(Debug, Identifiable, Queryable, QueryableByName)]
57#[diesel(table_name = plants)]
58pub struct Plants {
59    /// *Used* at many places
60    /// - The internal id of the plant.
61    /// - *Database fill ratio:* 100.00%
62    pub id: i64,
63
64    /// *Used* at many places
65    /// - The unique name of the plant.
66    /// - The structure is described above (`doc/database/hierarchy.md`).
67    /// - *Database fill ratio:* 100.00%
68    /// - *Scraper fill ratio:* 100.00%
69    pub unique_name: String,
70
71    /// *Used* at many places
72    /// - The list of the common names of the plant in English.
73    /// - *Fetched from* `PracticalPlants` and Permapeople.
74    /// - *Database fill ratio:* 70.69%
75    /// - *Scraper fill ratio:* 71.34%
76    pub common_name_en: Option<Vec<Option<String>>>,
77
78    /// *Used* at many places
79    /// - The list of the common names of the plant in German.
80    /// - *Fetched from* Wikidata API if not present in any source datasets.
81    /// - *Database fill ratio:* 20.20%
82    /// - *Scraper fill ratio:* 20.37%
83    pub common_name_de: Option<Vec<Option<String>>>,
84
85    // /// - The edible use of the plant, answering: Which food type can be produced from this plant, e.g. oil?
86    // /// - Interesting for search functionality.
87    // /// - *Fetched from* Permapeople as `edible_uses` and merged with Reinsaat.
88    /// - *Not used*
89    /// - *Scraper fill ratio:* 5.12%
90    // pub edible_uses_en: Option<String>,
91
92    // /// - *Fetched from* PracticalPlants as `medicinal_uses` and merged with Permapeople.
93    /// - *Not used*
94    /// - *Scraper fill ratio:* 0.71%
95    //pub medicinal_uses: Option<String>,
96
97    // /// - Only for references.
98    // /// - *Fetched from* PracticalPlants)
99    /// - *Not used*
100    /// - *Scraper fill ratio:* 26.73%
101    // pub material_uses_and_functions: Option<String>,
102
103    // /// - Only for references.
104    // /// - *Fetched from* PracticalPlants)
105    /// - *Not used*
106    /// - *Scraper fill ratio:* 50.08%
107    // pub botanic: Option<String>,
108
109    // /// - Only informational.
110    // /// - *Fetched from* PracticalPlants
111    // /// - Plants are not only used for food but also for other uses, e.g. fiber to produce paper.
112    /// - *Not used*
113    /// - *Scraper fill ratio:* 0.57%
114    // pub material_uses: Option<String>,
115    //
116    /// - *Used* for search ranking (diversity) and to be displayed in plant attributes.
117    /// - ecological and environmental function of the plant, especially nitrogen fixer is relevant for `PermaplanT`.
118    /// - *Fetched from* `PracticalPlants`)
119    /// - *Database fill ratio:* 12.51%
120    /// - *Scraper fill ratio:* 12.46%
121    pub functions: Option<String>,
122
123    // /// - Use `hardiness_zone` instead.
124    // /// - indication of the heat range a plant endures.
125    // /// - *Fetched from* `PracticalPlants`.
126    /// - *Not used*
127    /// - *Scraper fill ratio:* 0.03%
128    // pub heat_zone: Option<i16>,
129    //
130    /// - Shade tolerance of the plant, to be used together with `light_requirement`.
131    /// - *Used* in shade layer.
132    /// - *For example* a plant that has "no shade", should get a warning if placed in a shade.
133    /// - No shade: full sun exposure
134    /// - Light shade: moderately shaded throughout the day
135    /// - Partial shade: about 3-6 hours of direct sunlight
136    /// - Permanent shade: less than 3 hours of direct sunlight
137    /// - Shade indicates the shade tolerance. Plants obviously grow better with better light conditions.
138    /// - Warnings should only show if a plant is moved into a too dark spot.
139    ///   No warning should be shown when moved into a lighter spot.
140    /// - *Fetched from* `PracticalPlants`.
141    /// - *Database fill ratio:* 58.42%
142    /// - *Scraper fill ratio:* 58.26%
143    pub shade: Option<Shade>,
144
145    // /// - Currently unused (maybe later used in pH layer).
146    // /// - *See* explanation in `/doc/architecture/context.md`
147    // /// - Soil PH can be tested by the user with simple means (e.g. litmus).
148    // /// - *Fetched from* `PracticalPlants` and Permapeople (merged between Permapeople and `PracticalPlants`).
149    /// - *Not used*
150    /// - *Scraper fill ratio:* 0.54%
151    // pub soil_ph: Option<Vec<Option<SoilPh>>>,
152    //
153    /// - *See* explanation in `/doc/architecture/context.md`
154    /// - *Used* in soil layer.
155    /// - *Fetched from* `PracticalPlants` and Permapeople (merged with `soil_type` of Permapeople).
156    /// - *Database fill ratio:* 77.81%
157    /// - *Scraper fill ratio:* 77.78%
158    pub soil_texture: Option<Vec<Option<SoilTextureEnum>>>,
159
160    // /// - *NOT used* in hydrology layer
161    // ///   as it has poor quality and no additional data compared to water_requirement
162    // /// - *Fetched from* PracticalPlants
163    // /// - wet = drowned, (often) flooded or in general very moist, e.g. swamp
164    // /// - moist = humid, can hold some water, e.g. flat bed with humus
165    // /// - well drained = dry, low capacity to hold water, e.g. sandhill.
166    /// - *Scraper fill ratio:* 29.83%
167    // pub soil_water_retention: Option<Vec<Option<SoilWaterRetention>>>,
168
169    // /// - Only informational.
170    // /// - *Fetched from* PracticalPlants
171    // /// - gives information about environmental conditions, such as drought or wind tolerance
172    /// - *Not used*
173    /// - *Scraper fill ratio:* 12.26%
174    //pub environmental_tolerances: Option<Vec<Option<String>>>,
175
176    // /// - *Fetched from* PracticalPlants
177    /// - *Not used*
178    /// - *Scraper fill ratio:* 0.18%
179    //pub native_geographical_range: Option<String>,
180
181    // /// - *Fetched from* `PracticalPlants`
182    /// - *Not used*
183    /// - *Scraper fill ratio:* 0.11%
184    //pub native_environment: Option<String>,
185
186    // /// - Interesting for search functionality.
187    // /// - *Fetched from* `PracticalPlants`
188    // /// - informs about the (vertical) layer, that the plant usually inhabits, e.g. soil surface or canopy
189    /// - *Not used*
190    /// - *Scraper fill ratio:* 12.70%
191    // pub ecosystem_niche: Option<String>,
192
193    // /// - Only informational.
194    // /// - deciduous = plants loose leaves in winter.
195    // /// - evergreen = Plants don't throw leaves (e.g. pine tree).
196    // /// - Not applicable for annual plants.
197    // /// - *Fetched from* `PracticalPlants` and merged with `leaves` of Permapeople.
198    /// - *Not used*
199    /// - *Scraper fill ratio:* 23.45%
200    // pub deciduous_or_evergreen: Option<DeciduousOrEvergreen>,
201
202    /// - *Used* Displayed in the plant attributes.
203    /// - Only informational.
204    /// - Fetched from `PracticalPlants`
205    /// - informs about the plant physiology
206    /// - woody = grows woody parts
207    /// - herbaceous = doesn't grow wood, shoots remain soft/green.
208    /// - *Database fill ratio:* 22.33%
209    /// - *Scraper fill ratio:* 22.47%
210    pub herbaceous_or_woody: Option<HerbaceousOrWoody>,
211
212    /// - *Used* in search and attribute
213    /// - Determines life span of the plant.
214    /// - *Fetched from* `PracticalPlants` and Permapeople (merged with `life_cycle` of Permapeople).
215    /// - *Database fill ratio:* 61.91%
216    /// - *Scraper fill ratio:* 61.75%
217    pub life_cycle: Option<Vec<Option<LifeCycle>>>,
218
219    // /// - Only informational.
220    // /// - *Fetched from* `PracticalPlants` and Permapeople (merged with `growth` of Permapeople).
221    /// - *Not used*
222    /// - *Scraper fill ratio:* 23.56%
223    // pub growth_rate: Option<Vec<Option<GrowthRate>>>,
224
225    /// - *Used only informational, is in rw attribute
226    /// - *Fetched from* `PracticalPlants` as `mature_size_height` and merged with Permapeople.
227    /// - informs about the maximum height that the plant gains in cm
228    /// - *Database fill ratio:* 71.95%
229    /// - *Scraper fill ratio:* 71.92%
230    pub height: Option<i32>,
231
232    // /// - Determines how large the plant can grow in diameter.
233    // /// - Other plants should get a warning if planted within this area.
234    // /// - *TODO:* replaced with spread, will keep this for now for information
235    // /// - *Fetched from* `PracticalPlants` as `mature_size_width` and merged with Permapeople.
236    /// - *Not used*
237    /// - *Scraper fill ratio:* 17.44%
238    //pub width: Option<String>,
239
240    // /// - Only informational.
241    // /// - *Fetched from* `PracticalPlants`
242    /// - *Not used*
243    /// - *Scraper fill ratio:* 14.32%
244    // pub fertility: Option<Vec<Option<Fertility>>>,
245
246    // /// - Only informational.
247    // /// - *Fetched from* PracticalPlants
248    /// - *Not used*
249    /// - *Scraper fill ratio:* 0.35%
250    //pub flower_colour: Option<String>,
251
252    // /// - Only informational.
253    // /// - *Fetched from* PracticalPlants
254    // /// - a plant can contain flowers of two different sexes, male or female (monoecious), a plant can contain only flowers of one specific sex and therefore needs at least another plant of the other sex to reproduce (dioecious) or can contain flowers that have both the sexes within the same flower (hermaphrodite).
255    /// - *Not used*
256    /// - *Scraper fill ratio:* 49.30%
257    // pub flower_type: Option<FlowerType>,
258
259    /// - Is readonly in attribute
260    /// - The creation date of the entry (actual time).
261    /// - Only for administration.
262    /// - *Database fill ratio:* 100.00%
263    /// - *Scraper fill ratio:* 70.78%
264    pub created_at: NaiveDateTime,
265
266    /// - Is readonly in attribute
267    /// - The last update date of the entry (actual time).
268    /// - Only for administration.
269    /// - *Database fill ratio:* 100.00%
270    /// - *Scraper fill ratio:* 70.78%
271    pub updated_at: NaiveDateTime,
272
273    /// - *Used* so that an icon can be shown in the search results. Also displayed in the plant attributes.
274    /// - Will be used in watering layer.
275    /// - Fetched from `PracticalPlants` and merged with `has_drought_tolerance` of Permapeople.
276    /// - *Database fill ratio:* 53.44%
277    /// - *Scraper fill ratio:* 53.27%
278    pub has_drought_tolerance: Option<bool>,
279
280    // /// - *Fetched from* `PracticalPlants`.
281    /// - *Not used*
282    /// - *Scraper fill ratio:* 7.46%
283    // pub tolerates_wind: Option<bool>,
284
285    // /// - The list of the references of the plant.
286    // /// - `references` items link to these items.
287    // /// - Only informational.
288    /// - *Not used*
289    /// - *Scraper fill ratio:* 45.96%
290    // pub plant_references: Option<Vec<Option<String>>>,
291
292    // /// - Boolean value indicating whether the plant is a tree.
293    // /// - Plants with `is_tree == true` can be used in the tree layer.
294    // /// - In plants layer all plants can be used.
295    // /// - *Initial value* is to `True` if  herbaceous_or_woody (woody) and life_cycle (perennial)
296    /// - *Not used*
297    /// - *Scraper fill ratio:* 0.08%
298    // pub is_tree: Option<bool>,
299
300    // /// - Only informational.
301    // /// - *Initial value* is to `light feeder` if "Nutritionally poor soil" in `environmental_tolerances` is present.
302    /// - *Not used*
303    /// - *Scraper fill ratio:* 0.03%
304    // pub nutrition_demand: Option<NutritionDemand>,
305
306    // /// - Number value between -1..6 (-1 should be printed as 00)
307    /// - *Not used*
308    // /// - *Fill ratio:* 0%
309    // pub preferable_permaculture_zone: Option<i16>,
310
311    // /// - When article was modified last time.
312    // /// - Only for administration.
313    // /// - Date value fetched from `PracticalPlants` page showing the last modification date of the plant.
314    /// - *Not used*
315    /// - *Scraper fill ratio:* 50.21%
316    // pub article_last_modified_at: Option<NaiveDateTime>,
317
318    /// - *Used* To diplay an icon in the search results.
319    /// - USDA Hardiness Zone (without subranges).
320    /// - Important information.
321    /// - Fetched from `PracticalPlants` and Permapeople (merged with `usda_hardiness_zone` of Permapeople).
322    /// - *Database fill ratio:* 58.25%
323    /// - *Scraper fill ratio:* 58.08%
324    pub hardiness_zone: Option<String>,
325
326    /// - Shade tolerance of the plant, to be used together with shade.
327    /// - *Used* in shade layer.
328    /// - *For example* a plant that has "Full sun", should get a warning if placed in a shade.
329    /// - **Fetched from*** `PracticalPlants` and Permapeople (merged with `sun` of `PracticalPlants`)
330    /// - Full sun: full sun exposure
331    /// - Partial sun/shade: about 3-6 hours of direct sunlight or moderately shaded throughout the day
332    /// - Full shade: less than 3 hours of direct sunlight or almost no sunlight/no direct sunlight
333    /// - *Database fill ratio:* 77.96%
334    /// - *Scraper fill ratio:* 77.93%
335    pub light_requirement: Option<Vec<Option<LightRequirement>>>,
336
337    /// - *Used* in hydrology layer.
338    /// - *Fetched from* `PracticalPlants` and Permapeople (merged with `water` of `PracticalPlants`).
339    /// - water = completely aquatic;
340    /// - wet = drowned, (often) flooded or in general very moist, e.g. swamp;
341    /// - moist = humid, regular water supply, e.g. flat bed with humus;
342    /// - well drained = dry, little water input.
343    /// - *Database fill ratio:* 77.93%
344    /// - *Scraper fill ratio:* 77.90%
345    pub water_requirement: Option<Vec<Option<WaterRequirementEnum>>>,
346
347    // /// - Only informational.
348    // /// - *Fetched from* Permapeople (renamed from `propagation`)
349    // /// - How to reproduce a plant: cuttings = cut pieces of wood; layering = let low branches reach the soil to root; Seed - direct sow = sow directly the seeds; division = split the rhizomes (roots) into pieces; Spores = plant reproduces via spores (e.g. ferns, funghi); seed - transplant = raise indoors from seed and transplant to outdoors later
350    /// - *Not used*
351    /// - *Scraper fill ratio:* 0.73%
352    // pub propagation_method: Option<Vec<Option<PropagationMethod>>>,
353
354    // /// - Only informational.
355    // /// - May be used in search functionality (low priority).
356    // /// - *Fetched from* Permapeople.
357    /// - *Not used*
358    /// - *Scraper fill ratio:* 27.55%
359    // pub alternate_name: Option<String>,
360
361    // /// - Only informational.
362    // /// - *Fetched from* Permapeople.
363    /// - *Not used*
364    /// - *Scraper fill ratio:* 0.02%
365    //pub diseases: Option<String>,
366
367    /// - *Used* so that an icon can be shown in the search results. Also displayed in the plant attributes.
368    /// - Important information.
369    /// - *Fetched from* Permapeople.
370    /// - *Database fill ratio:* 55.02%
371    /// - *Scraper fill ratio:* 54.98%
372    pub edible: Option<bool>,
373
374    /// - Only informational.
375    /// - *Used* Displayed in the plant attributes.
376    /// - *Fetched from* Permapeople.
377    /// - which organ of the plant can be eaten, e.g. root, leaves.
378    /// - *Database fill ratio:* 56.76%
379    /// - *Scraper fill ratio:* 56.56%
380    pub edible_parts: Option<Vec<Option<String>>>,
381
382    // /// - Only informational.
383    // /// - *Fetched from* Permapeople.
384    // /// - Reinsaat: `Keimtemperatur` should be copied to `germination_temperature`
385    // /// - Germination means that all conditions are right for a seed to start growing. Temperature is one essential factor.
386    /// - *Not used*
387    /// - *Scraper fill ratio:* 1.60%
388    //pub germination_temperature: Option<String>,
389
390    // /// - *Fetched from* Permapeople.
391    /// - *Not used*
392    /// - *Scraper fill ratio:* 29.12%
393    //pub introduced_into: Option<String>,
394
395    // /// - Only informational.
396    // /// - *Fetched from* Permapeople as \`layer\` and renamed.
397    // /// - Habitus describes the shape of a plant.
398    /// - *Not used*
399    /// - *Scraper fill ratio:* 37.94%
400    //pub habitus: Option<String>,
401
402    // /// - *Fetched from* Permapeople.
403    /// - *Not used*
404    /// - *Scraper fill ratio:* 0.07%
405    //pub medicinal_parts: Option<String>,
406
407    // /// - Only informational.
408    // /// - *Fetched from* Permapeople.
409    /// - *Not used*
410    /// - *Scraper fill ratio:* 63.83%
411    //pub native_to: Option<String>,
412
413    // /// - *Fetched from* Permapeople.
414    /// - *Not used*
415    /// - *Scraper fill ratio:* 68.35%
416    //pub plants_for_a_future: Option<String>,
417
418    // /// - *Fetched from* Permapeople.
419    /// - *Not used*
420    /// - *Scraper fill ratio:* 65.01%
421    //pub plants_of_the_world_online_link: Option<String>,
422
423    // /// - *Fetched from* Permapeople.
424    /// - *Not used*
425    /// - *Scraper fill ratio:* 11.44%
426    //pub plants_of_the_world_online_link_synonym: Option<String>,
427
428    // /// - Only informational.
429    // /// - *Fetched from* PracticalPlants as `pollinators` and merged with `pollination` of Permapeople.
430    // /// - Pollination is the process that the pollen (male part) gets united with the pistil (female part), e.g. via bees, wind.
431    /// - *Not used*
432    /// - *Scraper fill ratio:* 38.03%
433    //pub pollination: Option<String>,
434
435    // /// - Only informational.
436    // /// - *Fetched from* Permapeople.
437    /// - *Not used*
438    /// - *Scraper fill ratio:* 0.11%
439    //pub propagation_transplanting_en: Option<String>,
440
441    // /// - Nearly empty.
442    // /// - *Fetched from* Permapeople.
443    /// - *Not used*
444    /// - *Scraper fill ratio:* 0.01%
445    //pub resistance: Option<String>,
446
447    // /// - Only informational.
448    // /// - *Fetched from* Permapeople.
449    // /// - Root type describes the shape of the roots.
450    /// - *Not used*
451    /// - *Scraper fill ratio:* 0.19%
452    //pub root_type: Option<String>,
453
454    // /// - Only informational.
455    // /// - *Fetched from* Permapeople as `seed_planting_depth` and renamed.
456    // /// - Reinsaat: `Sowing depth` should be copied to `seed_planting_depth_en`
457    // /// - When sowing each plant has a specific value how deep the seeds should be covered with soil.
458    /// - *Not used*
459    /// - *Scraper fill ratio:* 0.06%
460    //pub seed_planting_depth_en: Option<String>,
461
462    // /// - Only informational.
463    // /// - *Fetched from* Permapeople.
464    // /// - expected average life span (in years) of a seed of a certain specie.
465    /// - *Not used*
466    /// - *Scraper fill ratio:* 0.51%
467    //pub seed_viability: Option<String>,
468
469    // /// - The final part of the URL of the plant on the Permapeople website.
470    // /// - This field can be potentially used to construct the `external_url` field traversing through all the parents given by `parent_id`.
471    // /// - *Fetched from* Permapeople.
472    /// - *Not used*
473    /// - *Scraper fill ratio:* 70.78%
474    //pub slug: Option<String>,
475
476    /// - **Used**
477    /// - How far a plant spreads (The 'width' of a plant) in cm
478    /// - *Fetched from* Permapeople.
479    /// - *Database fill ratio:* 78.38%
480    /// - *Scraper fill ratio:* 78.36%
481    pub spread: Option<i32>,
482
483    // /// - *Fetched from* Permapeople.
484    /// - *Not used*
485    /// - *Scraper fill ratio:* 1.69%
486    //pub utility: Option<String>,
487
488    /// - *Used* so that an icon can be shown in the search results. Also displayed in the plant attributes.
489    /// - Important information.
490    /// - *Fetched from* Permapeople.
491    /// - specific warnings for eather human, animal or environmental well-being, e.g. toxic, invasive.
492    /// - *Database fill ratio:* 8.77%
493    /// - *Scraper fill ratio:* 8.69%
494    pub warning: Option<String>,
495
496    // /// - *Fetched from* Permapeople.
497    /// - *Not used*
498    /// - *Scraper fill ratio:* 0.05%
499    //pub when_to_plant_cuttings_en: Option<String>,
500
501    // /// - *Fetched from* Permapeople.
502    /// - *Not used*
503    /// - *Scraper fill ratio:* 0.06%
504    //pub when_to_plant_division_en: Option<String>,
505
506    // /// - *Fetched from* Permapeople.
507    /// - *Not used*
508    /// - *Scraper fill ratio:* 0.15%
509    //pub when_to_plant_transplant_en: Option<String>,
510
511    // /// - Only informational.
512    // /// - *Fetched from* Permapeople.
513    /// - *Not used*
514    /// - *Scraper fill ratio:* 0.18%
515    //pub when_to_sow_indoors_en: Option<String>,
516
517    // /// - Only informational.
518    // /// - *Fetched from* Permapeople as `when_to_sow_outdoors` and renamed.
519    // /// - Reinsaat: `Sowing` or `Direct Sowing` or `Sowing outdoors` or `Sowing Direct Outdoors` should be copied to `sowing_outdoors_en`
520    /// - *Not used*
521    /// - *Scraper fill ratio:* 0.27%
522    //pub sowing_outdoors_en: Option<String>,
523
524    // /// - Only informational.
525    // /// - *Fetched from* Permapeople.
526    /// - *Not used*
527    /// - *Scraper fill ratio:* 0.44%
528    //pub when_to_start_indoors_weeks: Option<String>,
529
530    // /// - Only informational.
531    // /// - *Fetched from* Permapeople.
532    /// - *Not used*
533    /// - *Scraper fill ratio:* 0.09%
534    //pub when_to_start_outdoors_weeks: Option<String>,
535
536    // /// - Only informational.
537    // /// - *Fetched from* Permapeople.
538    // /// - Stratification is the process that a seed must go through to get triggered for germination, e.g. by a certain threshold of minus degrees.
539    /// - *Not used*
540    /// - *Scraper fill ratio:* 0.02%
541    //pub cold_stratification_temperature: Option<String>,
542
543    // /// - Only informational.
544    // /// - *Fetched from* Permapeople.
545    // /// - Suggested change
546    // /// - *Fetched from* Permapeople.
547    // /// - Stratification is the process that a seed must go through to get triggered for germination, e.g. by a certain amount of time under cold temperatures.
548    /// - *Not used*
549    /// - *Scraper fill ratio:* 0.04%
550    //pub cold_stratification_time: Option<String>,
551
552    // /// - Only informational.
553    // /// - *Fetched from* Permapeople.
554    // /// - Reinsaat: `1st harvest` should be copied to `days_to_harvest`
555    /// - *Not used*
556    /// - *Scraper fill ratio:* 0.73%
557    //pub days_to_harvest: Option<String>,
558
559    // /// - Needed for occupied space and in attributes
560    // /// - *TODO:* should be number and then be used for calender
561    //pub life_cycle_days: Option<int>,
562
563    // /// - *Fetched from* Permapeople.
564    /// - *Not used*
565    /// - *Scraper fill ratio:* 0.15%
566    //pub habitat: Option<String>,
567
568    // /// - One number means it is spacing between plants and rows. Two numbers means first is spacing between plants, second between rows.
569    // /// - Only informational.
570    // /// - *Fetched from* Permapeople as `spacing` and from Reinsaat as `Distances` and renamed.
571    // /// - Reinsaat: `Distances` or `Spacing` should be copied to `spacing_en`
572    /// - *Not used*
573    /// - *Scraper fill ratio:* 0.53%
574    //pub spacing_en: Option<String>,
575
576    // /// - *Fetched from* Permapeople as `wikipedia` and renamed.
577    /// - *Not used*
578    /// - *Scraper fill ratio:* 37.12%
579    //pub wikipedia_url: Option<String>,
580
581    // /// - Only informational.
582    // /// - *Fetched from* Permapeople.
583    /// - *Not used*
584    /// - *Scraper fill ratio:* 0.20%
585    //pub days_to_maturity: Option<String>,
586
587    // /// - Nearly empty.
588    // /// - *Fetched from* Permapeople.
589    /// - *Not used*
590    /// - *Scraper fill ratio:* 0.02%
591    //pub pests: Option<String>,
592
593    /// - Only for administration.
594    /// - The version of the entry.
595    /// - To be incremented after every relevant change.
596    /// - *Fetched from* Permapeople.
597    /// - *Database fill ratio:* 70.11%
598    /// - *Scraper fill ratio:* 70.78%
599    pub version: Option<i16>,
600
601    // /// - Only informational.
602    // /// - *Fetched from* Permapeople.
603    // /// - Germination time describes the time (days, weeks, months) that a seed needs to germinate given the right conditions.
604    /// - *Not used*
605    /// - *Scraper fill ratio:* 0.41%
606    //pub germination_time: Option<String>,
607
608    // /// - The description of the entry.
609    // /// - *Fetched from* Permapeople.
610    /// - *Not used*
611    /// - *Scraper fill ratio:* 3.73%
612    //pub description: Option<String>,
613
614    // /// - TODO: (not yet in database) add to attributes
615    // /// - Short important information to shown.
616    //pub info: Option<String>,
617
618    // /// - *Fetched from* permapeople id of the parent entry pointing to the `external_id` column.
619    /// - *Not used*
620    /// - *Scraper fill ratio:* 1.54%
621    //pub parent_id: Option<String>,
622
623    // /// - Enum value indicating the source of the entry.
624    /// - *Not used*
625    /// - *Scraper fill ratio:* 79.18%
626    // pub external_source: Option<ExternalSource>,
627
628    // /// - The external id of the entry used in combination with the `external_source` column.
629    /// - *Not used*
630    /// - *Scraper fill ratio:* 70.78%
631    //pub external_id: Option<String>,
632
633    // /// - The external URL provided by the origin source.
634    /// - *Not used*
635    /// - *Scraper fill ratio:* 7.55%
636    //pub external_url: Option<String>,
637
638    // /// - Only informational.
639    // /// - *Fetched from* PracticalPlants as `root_zone_tendency` and merged with root_depth of Permapeople.
640    // /// - Root depth can be considered when planning polycultures, e.g. combining shallow roots with deep roots.
641    /// - *Not used*
642    /// - *Scraper fill ratio:* 0.14%
643    //pub root_depth: Option<String>,
644
645    // /// - The article number `Artikelnummer` of the plant in the Reinsaat database.
646    /// - *Not used*
647    /// - *Scraper fill ratio:* 6.05%
648    //pub external_article_number: Option<String>,
649
650    // /// - `Portionsinhalt` should be called `external_portion_content`
651    // /// - *Fetched from* Reinsaat.
652    /// - *Not used*
653    /// - *Scraper fill ratio:* 5.67%
654    //pub external_portion_content: Option<String>,
655
656    // /// - Only informational.
657    // /// - *Fetched from* Reinsaat as \`Direktsaat\` and renamed.
658    // /// - `Direktsaat` or `Aussaat` should be called `sowing_outdoors_de`
659    /// - *Not used*
660    /// - *Scraper fill ratio:* 0.82%
661    //pub sowing_outdoors_de: Option<String>,
662
663    /// - *Used* Displayed in the plant attributes.
664    /// - String array of numbers representing a time period.
665    /// - The year is divided into 24 periods of half a month each.
666    /// - *For example* "\[8,9,10\]" means from the 2nd half of April to the 2nd half of May incl.
667    /// - *Fetched from* Reinsaat
668    /// - `Aussaat/ Pflanzung Freiland` should be called `sowing_outdoors`
669    /// - *Database fill ratio:* 5.73%
670    /// - *Scraper fill ratio:* 5.64%
671    pub sowing_outdoors: Option<Vec<Option<i16>>>,
672
673    /// - *Used* Displayed in the plant attributes.
674    /// - String array of numbers representing a time period.
675    /// - The year is divided into 24 periods of half a month each.
676    /// - *For example* "\[8,9,10\]" means from the 2nd half of April to the 2nd half of May incl.
677    /// - `Ernte` should be called `harvest_time`
678    /// - *Fetched from* Reinsaat
679    /// - *Database fill ratio:* 5.58%
680    /// - *Scraper fill ratio:* 4.97%
681    pub harvest_time: Option<Vec<Option<i16>>>,
682
683    /*
684    /// - Only informational.
685    /// - *Fetched from* Reinsaat.
686    /// - `Abstände` should be called `spacing_de`
687    /// - *Not used*
688    /// - *Scraper fill ratio:* 2.37%
689    //pub spacing_de: Option<String>,
690
691    /// - Only informational.
692    /// - *Fetched from* Reinsaat.
693    /// - *Not used*
694    /// - `Saatgutbedarf` should be called `required_quantity_of_seeds_de`
695    /// - *Scraper fill ratio:* 1.29%
696    //pub required_quantity_of_seeds_de: Option<String>,
697
698    /// - Only informational.
699    /// - *Fetched from* Reinsaat.
700    /// - `Required quantity of seeds` should be called `required_quantity_of_seeds_en`
701    /// - *Not used*
702    /// - *Scraper fill ratio:* 2.77%
703    //pub required_quantity_of_seeds_en: Option<String>,
704
705    /// - Only informational.
706    /// - *Fetched from* Reinsaat.
707    /// - `Saattiefe` should be called `seed_planting_depth_de`
708    /// - When sowing, each plant has a specific value how deep the seeds should be covered with soil.
709    /// - *Not used*
710    /// - *Scraper fill ratio:* 2.22%
711    //pub seed_planting_depth_de: Option<String>,
712
713    /// - German version of thousand grain weight (German: Tausendkornmasse)
714    /// - Only informational.
715    /// - *Fetched from* Reinsaat.
716    /// - Called `Tausendkornmasse` in Reinsaat
717    /// - *Not used*
718    /// - *Scraper fill ratio:* 2.12%
719    //pub seed_weight_1000_de: Option<String>,
720
721    /// - English version of thousand grain weight (German: Tausendkornmasse)
722    /// - Only informational.
723    /// - *Fetched from* Reinsaat.
724    /// - Called `Thousand seeds mass` in Reinsaat
725    /// - *Not used*
726    /// - *Scraper fill ratio:* 2.17%
727    //pub seed_weight_1000_en: Option<String>,
728
729    /// - Number for thousand grain weight (German: Tausendkornmasse)
730    /// - used in `doc/usecases/buy_seeds.md` to calculate seed weight based on number of plants.
731    /// - *Fetched from* Permapeople as `1000_seed_weight_g` and renamed.
732    /// - *TODO:* merge with data from reinsaat: `Tausendkorngewicht (TKG)` should be copied to `seed_weight` (remove ` g`)
733    /// - *Not used*
734    /// - *Scraper fill ratio:* 2.90%
735    // pub seed_weight_1000: Option<f64>,
736
737    /// - Only informational.
738    /// - *Fetched from* Reinsaat.
739    /// - `Suitable for professional cultivation` should be called `machine_cultivation_possible`
740    /// - *Not used*
741    /// - *Scraper fill ratio:* 7.55%
742    //pub machine_cultivation_possible: Option<bool>,
743
744    /// - *Fetched from* Reinsaat.
745    /// - could be used for plant search and informational.
746    /// - `subcategory` from Reinsaat should be copied to `edible_uses_de` and `edible_uses_en` respectively (DE and EN version)
747    /// - *Not used*
748    /// - *Scraper fill ratio:* 5.10%
749    //pub edible_uses_de: Option<String>,
750    */
751    /// - Hierarchy fields
752    /// - Either *Fetched from* `PracticalPlants` and Permapeople
753    /// - Or determined from the unique name
754    /// - Or set by scraper overrides
755    /// - *Database fill ratio:* 100.00%
756    /// - *Scraper fill ratio:* 100.00%
757    pub rank: TaxonomicRank,
758    pub family: Option<i64>,
759    pub genus: Option<i64>,
760    pub species: Option<i64>,
761    pub variety: Option<i64>,
762
763    /// - The path to the icon of the plant.
764    /// - *Database fill ratio:* 2.32%
765    /// - *Scraper fill ratio:* 2.12%
766    pub icon_path: Option<String>,
767}
768
769/// The `PlantsAndFamily` entity used for a self join.
770#[derive(Queryable)]
771pub struct PlantsAndFamily {
772    /// The plants entity
773    pub plant: Plants,
774    /// The plants family name
775    pub family_name: Option<String>,
776}
777/// The `Seed` entity.
778#[derive(Identifiable, Queryable)]
779#[diesel(table_name = seeds)]
780pub struct Seed {
781    /// The record id of the seed.
782    pub id: i64,
783    /// An additional name for the seed.
784    pub name: String,
785    /// When the seeds were harvested.
786    pub harvest_year: i16,
787    /// When the seeds should be used by.
788    pub use_by: Option<NaiveDate>,
789    /// Where the seeds came from.
790    pub origin: Option<String>,
791    /// What the seeds taste like.
792    pub taste: Option<String>,
793    /// The yield of the seeds.
794    pub yield_: Option<String>,
795    /// How many seeds there are.
796    pub quantity: Quantity,
797    /// The quality of the seeds.
798    pub quality: Option<Quality>,
799    /// How much the seeds cost.
800    pub price: Option<i16>,
801    /// How many generations the seeds have been grown.
802    pub generation: Option<i16>,
803    /// Notes about the seeds.
804    pub notes: Option<String>,
805    /// The id of the plant this seed belongs to.
806    pub plant_id: i64,
807    /// The id of the creator of the seed.
808    pub created_by: Uuid,
809    /// Timestamp indicating when the seed was archived.
810    /// Empty if the seed was not archived.
811    pub archived_at: Option<NaiveDateTime>,
812}
813
814/// The `NewSeed` entity.
815#[allow(clippy::missing_docs_in_private_items)] // TODO: See #97.
816#[derive(Insertable)]
817#[diesel(table_name = seeds)]
818pub struct NewSeed {
819    pub name: String,
820    pub plant_id: i64,
821    pub harvest_year: i16,
822    pub use_by: Option<NaiveDate>,
823    pub origin: Option<String>,
824    pub taste: Option<String>,
825    pub yield_: Option<String>,
826    pub quantity: Quantity,
827    pub quality: Option<Quality>,
828    pub price: Option<i16>,
829    pub generation: Option<i16>,
830    pub notes: Option<String>,
831    pub created_by: Uuid,
832}
833
834/// The `Map` entity.
835#[derive(Identifiable, Queryable)]
836#[diesel(table_name = maps)]
837pub struct Map {
838    /// The id of the map.
839    pub id: i64,
840    /// The name of the map.
841    pub name: String,
842    /// The date the map is supposed to be deleted.
843    pub deletion_date: Option<NaiveDate>,
844    /// The date the last time the map view was opened by any user.
845    pub last_visit: Option<NaiveDate>,
846    /// A flag indicating if this map is marked for deletion.
847    pub is_inactive: bool,
848    /// The zoom factor of the map.
849    pub zoom_factor: i16,
850    /// An enum indicating if this map is private or not.
851    pub privacy: PrivacyAccessControl,
852    /// The description of the map.
853    pub description: Option<String>,
854    /// The location of the map as a latitude/longitude point.
855    pub location: Option<Point>,
856    /// The id of the creator of the map.
857    pub created_by: Uuid,
858    /// The geometry of the map.
859    pub geometry: Polygon<Point>,
860    /// When the map was created.
861    pub created_at: NaiveDateTime,
862    /// When a map was last modified, e.g., by modifying plantings.
863    pub modified_at: NaiveDateTime,
864    /// By whom the map was last modified.
865    pub modified_by: Uuid,
866}
867
868/// The `NewMap` entity.
869#[derive(Insertable)]
870#[diesel(table_name = maps)]
871pub struct NewMap {
872    /// The name of the map.
873    pub name: String,
874    /// For a new map the same as `created_by`.
875    pub deletion_date: Option<NaiveDate>,
876    /// The date the last time the map view was opened by any user.
877    pub last_visit: Option<NaiveDate>,
878    /// A flag indicating if this map is marked for deletion.
879    pub is_inactive: bool,
880    /// The zoom factor of the map.
881    pub zoom_factor: i16,
882    /// An enum indicating if this map is private or not.
883    pub privacy: PrivacyAccessControl,
884    /// The description of the map.
885    pub description: Option<String>,
886    /// The location of the map as a latitude/longitude point.
887    pub location: Option<Point>,
888    /// The id of the creator of the map.
889    pub created_by: Uuid,
890    /// The geometry of the map.
891    pub geometry: Polygon<Point>,
892    /// The user who last modified the planting.
893    pub modified_by: Uuid,
894}
895
896/// The `UpdateMap` entity.
897#[derive(AsChangeset)]
898#[diesel(table_name = maps)]
899pub struct UpdateMap {
900    /// The name of the map.
901    pub name: Option<String>,
902    /// An enum indicating if this map is private or not.
903    pub privacy: Option<PrivacyAccessControl>,
904    /// The description of the map.
905    pub description: Option<String>,
906    /// The location of the map as a latitude/longitude point.
907    pub location: Option<Point>,
908}
909
910/// The `UpdateMapGeometry` entity.
911#[derive(AsChangeset)]
912#[diesel(table_name = maps)]
913pub struct UpdateMapGeometry {
914    /// New Map Bounds
915    pub geometry: Polygon<Point>,
916}
917
918/// The `GuidedTourProgress` entity.
919#[derive(Identifiable, Queryable)]
920#[diesel(primary_key(user_id, step_key), table_name = guided_tour_progress)]
921pub struct GuidedTourProgress {
922    /// ID of the user who completed the tour step
923    pub user_id: Uuid,
924    /// Human readable id of the step the user completed
925    pub step_key: String,
926    /// Time of completion
927    pub completed_at: NaiveDateTime,
928}
929
930/// Insertable for `guided_tour_progress` (`completed_at` uses DB default).
931#[derive(Insertable)]
932#[diesel(table_name = guided_tour_progress)]
933pub struct NewGuidedTourProgress {
934    /// ID of the user who is completing the step
935    pub user_id: Uuid,
936    /// Human readable id of the step the user is completing
937    pub step_key: String,
938}
939
940/// The `GuidedTourState` entity.
941#[derive(Insertable, Identifiable, Queryable)]
942#[diesel(primary_key(user_id), table_name = guided_tour_states)]
943pub struct GuidedTourState {
944    /// ID of the user
945    pub user_id: Uuid,
946    /// When the tour was paused
947    pub paused_at: Option<NaiveDateTime>,
948    /// How often the user has paused the tour already
949    pub pause_count: i32,
950}
951
952/// The `ApplicationSetting` entity.
953#[derive(Identifiable, Queryable)]
954#[diesel(primary_key(id), table_name = application_settings)]
955pub struct ApplicationSetting {
956    /// The id of the setting
957    pub id: i32,
958    /// The unique key of the setting
959    pub key: String,
960    /// The value of the setting
961    pub value: String,
962}
963
964/// The [`MapCollaborator`] entity.
965#[derive(Insertable, Identifiable, Queryable)]
966#[diesel(primary_key(map_id, user_id), table_name = map_collaborators)]
967pub struct MapCollaborator {
968    pub map_id: i64,
969    pub user_id: Uuid,
970    pub created_at: NaiveDateTime,
971}