20 lines
545 B
MySQL
20 lines
545 B
MySQL
|
|
-- Migration: 072_locations_parent_relation
|
||
|
|
-- Created: 2026-01-31
|
||
|
|
-- Description: Add hierarchical parent relationship to locations
|
||
|
|
|
||
|
|
BEGIN;
|
||
|
|
|
||
|
|
ALTER TABLE locations_locations
|
||
|
|
ADD COLUMN IF NOT EXISTS parent_location_id INTEGER;
|
||
|
|
|
||
|
|
ALTER TABLE locations_locations
|
||
|
|
ADD CONSTRAINT locations_locations_parent_location_id_fkey
|
||
|
|
FOREIGN KEY (parent_location_id)
|
||
|
|
REFERENCES locations_locations(id)
|
||
|
|
ON DELETE SET NULL;
|
||
|
|
|
||
|
|
CREATE INDEX IF NOT EXISTS idx_locations_parent_location_id
|
||
|
|
ON locations_locations(parent_location_id);
|
||
|
|
|
||
|
|
COMMIT;
|