Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Plant Hierarchy Implementation Proposal #764

Description

@temmey

Here's a proposal to discuss how we can build our plant hierarchy:

  1. Tables: Family, Genus, Species, Variety, Cultivar

    Please refer to the guide outlined in Hierarchy. Every table should have most of the properties we already use for plants. This means we still have info even if a child table doesn't have a value. We might want to add certain columns to tables based on what makes biological sense.

    Inheritance isn't going to work here. For more details, check out Decision Hierarchy. Also, Rust Diesel isn't made for this.

  2. Changing the "plants" Table

    We can change "plants" table to "PlantDetails" or something similar. We'll add nullable columns for Variety FK and Species FK.

  3. Creating a "Plants" View

    We'll make a "Plants" view that brings all tables together. This will help us use them in the backend without big changes.

  4. Handling Null Values

    This view will deal with null values in the "plants" table. For example, if plants.heat_zone = null, it'll try to get the value from its cultivar. If that's also null, it'll look in the variety, and so on.

  5. Functions: Update, Insert, Delete

    • Update: Only updates a null value in the plants table if it's different from its parent table value. If the parent table value is null, it'll check the one above.
      If the hierarchy changes, it'll keep inserting the hierarchy tree until it finds an already existing hierarchy.
    • Insert: Only adds values to columns if they're different from their parent table, otherwise adds null. If parent doesn't exist, also add an entry to parent table like a new Species and insert all values there.
    • Delete: Removes the entry from the plants table.
  6. Creating Triggers

    We'll make triggers with the INSTEAD OF keyword to replace the UPDATE, INSERT, and DELETE events from the new "Plants" view.

Problems Solved

  • Backend changes are too big: The "plants" view should help keep changes small.
  • When we change values in a parent table like genus, all children should change, unless a child has its own value. We should be able to solve this by saving only values that are different from their parent.
  • Hybrid plants: We treat them as their own species as mentioned in hierarchy.md. For example, species.name: Iris × germanica, plants.unique_name: Iris × germanica. This should be possible with this solution.
  • Plants without a genus/varieties, etc.: FK Ids to parents can be nullable, so not all plants need a full hierarchy.

Problems We Still Need to Solve

  • Dealing with a new plant with a different species but the same genus that we haven't yet added to our database. The old species A doesn't have a link to species B.
  • Special cases of hybrid plants, like a mix between different genus. It's possible, like with Shipova. Should we think about such cases? They seem to be rare.

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is neededquestionFurther information is requested

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Current Sprint

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions