watering attempt 1
This commit is contained in:
27
database/migrations/V10__sprinkler_equipment.sql
Normal file
27
database/migrations/V10__sprinkler_equipment.sql
Normal file
@@ -0,0 +1,27 @@
|
||||
-- Add sprinkler-specific fields to user_equipment
|
||||
ALTER TABLE user_equipment
|
||||
ADD COLUMN IF NOT EXISTS sprinkler_mount VARCHAR(20) CHECK (sprinkler_mount IN ('in_ground','above_ground')),
|
||||
ADD COLUMN IF NOT EXISTS sprinkler_head_type VARCHAR(30) CHECK (sprinkler_head_type IN ('rotor_impact','oscillating_fan','spray_fixed','drip')),
|
||||
ADD COLUMN IF NOT EXISTS sprinkler_gpm DECIMAL(8,2),
|
||||
ADD COLUMN IF NOT EXISTS sprinkler_throw_feet DECIMAL(8,2),
|
||||
ADD COLUMN IF NOT EXISTS sprinkler_degrees INTEGER,
|
||||
ADD COLUMN IF NOT EXISTS sprinkler_length_feet DECIMAL(8,2),
|
||||
ADD COLUMN IF NOT EXISTS sprinkler_width_feet DECIMAL(8,2),
|
||||
ADD COLUMN IF NOT EXISTS sprinkler_coverage_sqft DECIMAL(10,2);
|
||||
|
||||
-- Ensure a Sprinkler category and type exist
|
||||
DO $$
|
||||
DECLARE cid INT; tid INT;
|
||||
BEGIN
|
||||
SELECT id INTO cid FROM equipment_categories WHERE name ILIKE 'Sprinkler' LIMIT 1;
|
||||
IF cid IS NULL THEN
|
||||
INSERT INTO equipment_categories(name, description) VALUES ('Sprinkler','Watering sprinklers') RETURNING id INTO cid;
|
||||
END IF;
|
||||
SELECT id INTO tid FROM equipment_types WHERE name ILIKE 'Sprinkler' LIMIT 1;
|
||||
IF tid IS NULL THEN
|
||||
INSERT INTO equipment_types(name, category_id) VALUES ('Sprinkler', cid);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
SELECT 'Sprinkler equipment fields added' as migration_status;
|
||||
|
||||
34
database/migrations/V11__watering_plans.sql
Normal file
34
database/migrations/V11__watering_plans.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
-- Watering plans for guiding sprinkler placement and timing
|
||||
CREATE TABLE IF NOT EXISTS watering_plans (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
||||
property_id INTEGER REFERENCES properties(id) ON DELETE CASCADE,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
notes TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS watering_plan_points (
|
||||
id SERIAL PRIMARY KEY,
|
||||
plan_id INTEGER REFERENCES watering_plans(id) ON DELETE CASCADE,
|
||||
sequence INTEGER NOT NULL,
|
||||
lat DECIMAL(10,8) NOT NULL,
|
||||
lng DECIMAL(11,8) NOT NULL,
|
||||
duration_minutes INTEGER DEFAULT 0,
|
||||
sprinkler_mount VARCHAR(20) CHECK (sprinkler_mount IN ('in_ground','above_ground')),
|
||||
sprinkler_head_type VARCHAR(30) CHECK (sprinkler_head_type IN ('rotor_impact','oscillating_fan','spray_fixed','drip')),
|
||||
sprinkler_gpm DECIMAL(8,2),
|
||||
sprinkler_throw_feet DECIMAL(8,2),
|
||||
sprinkler_degrees INTEGER,
|
||||
sprinkler_length_feet DECIMAL(8,2),
|
||||
sprinkler_width_feet DECIMAL(8,2),
|
||||
coverage_sqft DECIMAL(10,2),
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_watering_plans_user ON watering_plans(user_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_watering_points_plan ON watering_plan_points(plan_id);
|
||||
|
||||
SELECT 'Watering plans tables created' as migration_status;
|
||||
|
||||
Reference in New Issue
Block a user