multiarea
This commit is contained in:
24
database/migrations/support_multiple_areas_per_plan.sql
Normal file
24
database/migrations/support_multiple_areas_per_plan.sql
Normal 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);
|
||||
Reference in New Issue
Block a user