-- Migration: 083_sag_hardware_locations
-- Created: 2026-02-01
-- Description: Enable linking Hardware and Locations to Cases

BEGIN;

CREATE TABLE IF NOT EXISTS sag_hardware (
    id SERIAL PRIMARY KEY,
    sag_id INTEGER NOT NULL REFERENCES sag_sager(id) ON DELETE CASCADE,
    hardware_id INTEGER NOT NULL REFERENCES hardware_assets(id) ON DELETE CASCADE,
    note TEXT,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    deleted_at TIMESTAMP,
    UNIQUE(sag_id, hardware_id)
);

CREATE TABLE IF NOT EXISTS sag_lokationer (
    id SERIAL PRIMARY KEY,
    sag_id INTEGER NOT NULL REFERENCES sag_sager(id) ON DELETE CASCADE,
    location_id INTEGER NOT NULL REFERENCES locations_locations(id) ON DELETE CASCADE,
    note TEXT,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    deleted_at TIMESTAMP,
    UNIQUE(sag_id, location_id)
);

COMMIT;
