27 lines
1.1 KiB
SQL
27 lines
1.1 KiB
SQL
-- Performance indexes for common queries and joins
|
|
|
|
-- Application plans
|
|
CREATE INDEX IF NOT EXISTS idx_application_plans_user_id ON application_plans(user_id);
|
|
CREATE INDEX IF NOT EXISTS idx_application_plans_user_status ON application_plans(user_id, status);
|
|
CREATE INDEX IF NOT EXISTS idx_application_plans_user_planned_date ON application_plans(user_id, planned_date);
|
|
|
|
-- Application plan products
|
|
CREATE INDEX IF NOT EXISTS idx_application_plan_products_plan_id ON application_plan_products(plan_id);
|
|
|
|
-- Properties and lawn sections
|
|
CREATE INDEX IF NOT EXISTS idx_properties_user_id ON properties(user_id);
|
|
CREATE INDEX IF NOT EXISTS idx_lawn_sections_property_id ON lawn_sections(property_id);
|
|
|
|
-- User equipment
|
|
CREATE INDEX IF NOT EXISTS idx_user_equipment_user_id ON user_equipment(user_id);
|
|
|
|
-- User products and products
|
|
CREATE INDEX IF NOT EXISTS idx_user_products_user_id ON user_products(user_id);
|
|
CREATE INDEX IF NOT EXISTS idx_products_category_id ON products(category_id);
|
|
|
|
-- Weather logs (if present)
|
|
-- CREATE INDEX IF NOT EXISTS idx_weather_logs_property_id ON weather_logs(property_id);
|
|
|
|
SELECT 'Core indexes added' AS migration_status;
|
|
|