equipment stuff

This commit is contained in:
Jake Kasper
2025-08-22 09:17:22 -04:00
parent f95422325c
commit b7ceed70a5
7 changed files with 2137 additions and 260 deletions

View File

@@ -41,29 +41,107 @@ CREATE TABLE lawn_sections (
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Equipment categories master table
CREATE TABLE equipment_categories (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL UNIQUE,
description TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Equipment types master table (shared across all users)
CREATE TABLE equipment_types (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE,
category VARCHAR(100) NOT NULL, -- mower, trimmer, spreader, sprayer, aerator, dethatcher
category_id INTEGER REFERENCES equipment_categories(id),
manufacturer VARCHAR(100),
model VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- User equipment table
-- User equipment table - comprehensive equipment management
CREATE TABLE user_equipment (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
equipment_type_id INTEGER REFERENCES equipment_types(id),
category_id INTEGER REFERENCES equipment_categories(id),
custom_name VARCHAR(255),
tank_size DECIMAL(8, 2), -- gallons (for sprayers)
pump_gpm DECIMAL(8, 2), -- gallons per minute (for sprayers)
nozzle_gpm DECIMAL(8, 2), -- gallons per minute per nozzle
nozzle_count INTEGER, -- number of nozzles
spreader_width DECIMAL(8, 2), -- width in feet (for spreaders)
manufacturer VARCHAR(100),
model VARCHAR(100),
-- Spreader specific fields
capacity_lbs DECIMAL(8, 2),
spreader_type VARCHAR(50) CHECK (spreader_type IN ('walk_behind', 'pull_behind', 'handheld')),
spread_width DECIMAL(8, 2),
-- Sprayer specific fields
tank_size_gallons DECIMAL(8, 2),
sprayer_type VARCHAR(50) CHECK (sprayer_type IN ('tow_behind', 'mower_mounted', 'ride_on', 'walk_behind', 'hand_pump')),
spray_width_feet DECIMAL(8, 2),
pump_gpm DECIMAL(8, 2),
pump_psi DECIMAL(8, 2),
boom_sections INTEGER,
-- Mower specific fields
mower_style VARCHAR(50) CHECK (mower_style IN ('push', 'self_propelled', 'zero_turn', 'lawn_tractor', 'riding')),
cutting_width_inches DECIMAL(6, 2),
engine_hp DECIMAL(6, 2),
fuel_type VARCHAR(30),
-- Tool specific fields (aerator, dethatcher, scarifier)
tool_type VARCHAR(50) CHECK (tool_type IN ('walk_behind', 'tow_behind', 'handheld')),
working_width_inches DECIMAL(6, 2),
-- Pump specific fields
pump_type VARCHAR(50),
max_gpm DECIMAL(8, 2),
max_psi DECIMAL(8, 2),
power_source VARCHAR(50), -- electric, gas, pto, etc.
-- General fields
purchase_date DATE,
purchase_price DECIMAL(10, 2),
notes TEXT,
is_active BOOLEAN DEFAULT true,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Nozzle types master table
CREATE TABLE nozzle_types (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
manufacturer VARCHAR(100),
model VARCHAR(100),
orifice_size VARCHAR(20),
spray_angle INTEGER,
flow_rate_gpm DECIMAL(6, 3),
droplet_size VARCHAR(50), -- fine, medium, coarse, very_coarse, extremely_coarse
spray_pattern VARCHAR(50), -- flat_fan, hollow_cone, full_cone, flooding
pressure_range_psi VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- User's nozzle inventory
CREATE TABLE user_nozzles (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
nozzle_type_id INTEGER REFERENCES nozzle_types(id),
custom_name VARCHAR(255),
quantity INTEGER DEFAULT 1,
condition VARCHAR(50) DEFAULT 'good', -- excellent, good, fair, poor, needs_replacement
purchase_date DATE,
notes TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Equipment nozzle assignments (which nozzles are on which sprayers)
CREATE TABLE equipment_nozzle_assignments (
id SERIAL PRIMARY KEY,
user_equipment_id INTEGER REFERENCES user_equipment(id) ON DELETE CASCADE,
user_nozzle_id INTEGER REFERENCES user_nozzles(id) ON DELETE CASCADE,
position VARCHAR(50), -- left, right, center, boom_1, boom_2, etc.
quantity_assigned INTEGER DEFAULT 1,
assigned_date DATE DEFAULT CURRENT_DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(user_equipment_id, user_nozzle_id, position)
);
-- Product categories
CREATE TABLE product_categories (
id SERIAL PRIMARY KEY,
@@ -181,22 +259,72 @@ CREATE TABLE weather_data (
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert equipment categories
INSERT INTO equipment_categories (name, description) VALUES
('Mower', 'Lawn mowing equipment'),
('Spreader', 'Granular product application equipment'),
('Sprayer', 'Liquid product application equipment'),
('Nozzle', 'Spray nozzles and tips'),
('Pump', 'Water and chemical pumps'),
('Aerator', 'Soil aeration equipment'),
('Dethatcher', 'Thatch removal equipment'),
('Scarifier', 'Soil scarification equipment'),
('Trimmer', 'Edge and trim equipment'),
('Other', 'Miscellaneous lawn care equipment');
-- Insert default equipment types
INSERT INTO equipment_types (name, category) VALUES
('Walk-behind Mower', 'mower'),
('Riding Mower', 'mower'),
('Zero-turn Mower', 'mower'),
('String Trimmer', 'trimmer'),
('Backpack Sprayer', 'sprayer'),
('Pull-behind Sprayer', 'sprayer'),
('Boom Sprayer', 'sprayer'),
('Broadcast Spreader', 'spreader'),
('Drop Spreader', 'spreader'),
('Hand Spreader', 'spreader'),
('Core Aerator', 'aerator'),
('Spike Aerator', 'aerator'),
('Dethatcher', 'dethatcher'),
('Power Rake', 'dethatcher');
INSERT INTO equipment_types (name, category_id) VALUES
-- Mowers
('Walk-behind Mower', 1),
('Self-Propelled Mower', 1),
('Zero-turn Mower', 1),
('Lawn Tractor', 1),
('Riding Mower', 1),
-- Spreaders
('Broadcast Spreader', 2),
('Drop Spreader', 2),
('Hand Spreader', 2),
('Pull-behind Spreader', 2),
-- Sprayers
('Backpack Sprayer', 3),
('Pull-behind Sprayer', 3),
('Boom Sprayer', 3),
('Hand Pump Sprayer', 3),
('Ride-on Sprayer', 3),
('Mower-mounted Sprayer', 3),
-- Pumps
('Centrifugal Pump', 5),
('Diaphragm Pump', 5),
('Roller Pump', 5),
('Gear Pump', 5),
-- Aerators
('Core Aerator', 6),
('Spike Aerator', 6),
('Plug Aerator', 6),
-- Dethatchers
('Power Rake', 7),
('Vertical Mower', 7),
('Dethatcher', 7),
-- Scarifiers
('Walk-behind Scarifier', 8),
('Tow-behind Scarifier', 8),
-- Trimmers
('String Trimmer', 9),
('Brush Cutter', 9),
('Edger', 9);
-- Insert common nozzle types
INSERT INTO nozzle_types (name, manufacturer, orifice_size, spray_angle, flow_rate_gpm, droplet_size, spray_pattern, pressure_range_psi) VALUES
('XR8002', 'TeeJet', '02', 80, 0.20, 'fine', 'flat_fan', '15-60'),
('XR8003', 'TeeJet', '03', 80, 0.30, 'fine', 'flat_fan', '15-60'),
('XR8004', 'TeeJet', '04', 80, 0.40, 'fine', 'flat_fan', '15-60'),
('XR8005', 'TeeJet', '05', 80, 0.50, 'fine', 'flat_fan', '15-60'),
('AIXR11002', 'TeeJet', '02', 110, 0.20, 'medium', 'flat_fan', '15-60'),
('AIXR11003', 'TeeJet', '03', 110, 0.30, 'medium', 'flat_fan', '15-60'),
('AIXR11004', 'TeeJet', '04', 110, 0.40, 'medium', 'flat_fan', '15-60'),
('TTI11002', 'TeeJet', '02', 110, 0.20, 'very_coarse', 'flat_fan', '15-60'),
('TTI11003', 'TeeJet', '03', 110, 0.30, 'very_coarse', 'flat_fan', '15-60'),
('TTI11004', 'TeeJet', '04', 110, 0.40, 'very_coarse', 'flat_fan', '15-60');
-- Insert product categories
INSERT INTO product_categories (name, description) VALUES
@@ -248,5 +376,6 @@ CREATE TRIGGER update_users_updated_at BEFORE UPDATE ON users FOR EACH ROW EXECU
CREATE TRIGGER update_properties_updated_at BEFORE UPDATE ON properties FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
CREATE TRIGGER update_lawn_sections_updated_at BEFORE UPDATE ON lawn_sections FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
CREATE TRIGGER update_user_equipment_updated_at BEFORE UPDATE ON user_equipment FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
CREATE TRIGGER update_user_nozzles_updated_at BEFORE UPDATE ON user_nozzles FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
CREATE TRIGGER update_user_products_updated_at BEFORE UPDATE ON user_products FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
CREATE TRIGGER update_application_plans_updated_at BEFORE UPDATE ON application_plans FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();