multiarea

This commit is contained in:
Jake Kasper
2025-08-26 07:46:37 -05:00
parent 24c0fa7b86
commit 7983503e5e
4 changed files with 251 additions and 274 deletions

View File

@@ -0,0 +1,24 @@
-- Migration: Support multiple lawn sections per application plan
-- This allows a single plan to cover multiple areas of a property
-- Create junction table for plan-section relationships
CREATE TABLE application_plan_sections (
id SERIAL PRIMARY KEY,
plan_id INTEGER REFERENCES application_plans(id) ON DELETE CASCADE,
lawn_section_id INTEGER REFERENCES lawn_sections(id) ON DELETE CASCADE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE(plan_id, lawn_section_id)
);
-- Migrate existing data from application_plans.lawn_section_id to the junction table
INSERT INTO application_plan_sections (plan_id, lawn_section_id)
SELECT id, lawn_section_id
FROM application_plans
WHERE lawn_section_id IS NOT NULL;
-- Remove the lawn_section_id column from application_plans (it's now in the junction table)
ALTER TABLE application_plans DROP COLUMN lawn_section_id;
-- Create index for better performance on lookups
CREATE INDEX idx_application_plan_sections_plan_id ON application_plan_sections(plan_id);
CREATE INDEX idx_application_plan_sections_section_id ON application_plan_sections(lawn_section_id);