-- Migration: 075_locations_update_type_hierarchy
-- Created: 2026-01-31
-- Description: Update location_type values to hierarchy (kompleks > bygning > etage > customer_site > rum)

BEGIN;

-- Normalize legacy values to the new hierarchy
UPDATE locations_locations
SET location_type = 'bygning'
WHERE location_type IN ('branch', 'warehouse');

UPDATE locations_locations
SET location_type = 'customer_site'
WHERE location_type IN ('client_site');

-- Update CHECK constraint to new allowed values
ALTER TABLE locations_locations
    DROP CONSTRAINT IF EXISTS locations_locations_location_type_check;

ALTER TABLE locations_locations
    ADD CONSTRAINT locations_locations_location_type_check
    CHECK (location_type IN (
        'kompleks',
        'bygning',
        'etage',
        'customer_site',
        'rum',
        'vehicle'
    ));

COMMIT;
