mirror of
https://github.com/ForFarmTeam/ForFarm.git
synced 2025-12-19 14:04:08 +01:00
feat: add farm, cropland, and plant-related tables with FKs
This commit is contained in:
parent
b6967032ab
commit
30324e81b4
73
backend/migrations/00002_create_farm_and_cropland_tables.sql
Normal file
73
backend/migrations/00002_create_farm_and_cropland_tables.sql
Normal file
@ -0,0 +1,73 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE light_profiles (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE soil_conditions (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE harvest_units (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE plants (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
variety TEXT,
|
||||
row_spacing DOUBLE PRECISION,
|
||||
optimal_temp DOUBLE PRECISION,
|
||||
planting_depth DOUBLE PRECISION,
|
||||
average_height DOUBLE PRECISION,
|
||||
light_profile_id INT NOT NULL,
|
||||
soil_condition_id INT NOT NULL,
|
||||
planting_detail TEXT,
|
||||
is_perennial BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
days_to_emerge INT,
|
||||
days_to_flower INT,
|
||||
days_to_maturity INT,
|
||||
harvest_window INT,
|
||||
ph_value DOUBLE PRECISION,
|
||||
estimate_loss_rate DOUBLE PRECISION,
|
||||
estimate_revenue_per_hu DOUBLE PRECISION,
|
||||
harvest_unit_id INT NOT NULL,
|
||||
water_needs DOUBLE PRECISION,
|
||||
CONSTRAINT fk_plant_light_profile FOREIGN KEY (light_profile_id) REFERENCES light_profiles(id),
|
||||
CONSTRAINT fk_plant_soil_condition FOREIGN KEY (soil_condition_id) REFERENCES soil_conditions(id),
|
||||
CONSTRAINT fk_plant_harvest_unit FOREIGN KEY (harvest_unit_id) REFERENCES harvest_units(id)
|
||||
);
|
||||
|
||||
CREATE TABLE farms (
|
||||
id SERIAL PRIMARY KEY,
|
||||
uuid UUID NOT NULL DEFAULT gen_random_uuid(),
|
||||
name TEXT NOT NULL,
|
||||
lat DOUBLE PRECISION NOT NULL,
|
||||
lon DOUBLE PRECISION NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
owner_id UUID NOT NULL,
|
||||
CONSTRAINT fk_farm_owner FOREIGN KEY (owner_id) REFERENCES users(uuid) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_farms_uuid ON farms(uuid);
|
||||
|
||||
CREATE TABLE croplands (
|
||||
id SERIAL PRIMARY KEY,
|
||||
uuid UUID NOT NULL DEFAULT gen_random_uuid(),
|
||||
name TEXT NOT NULL,
|
||||
status TEXT NOT NULL,
|
||||
priority INT NOT NULL,
|
||||
land_size DOUBLE PRECISION NOT NULL,
|
||||
growth_stage TEXT NOT NULL,
|
||||
plant_id INT NOT NULL,
|
||||
farm_id INT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
CONSTRAINT fk_cropland_farm FOREIGN KEY (farm_id) REFERENCES farms(id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_cropland_plant FOREIGN KEY (plant_id) REFERENCES plants(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX idx_croplands_uuid ON croplands(uuid);
|
||||
Loading…
Reference in New Issue
Block a user