-- Schema: bw_scheddebrock
SET search_path TO bw_scheddebrock, public;

-- 1. Table for Kabeltrasse (Cable Routes)
-- The user confirmed the name is "Kabeltrasse" and the ID column is "id_0"
CREATE TABLE IF NOT EXISTS "Kabeltrasse" (
    id_0 BIGINT PRIMARY KEY,
    name TEXT NOT NULL,
    color TEXT,
    active BOOLEAN DEFAULT false,
    visible BOOLEAN DEFAULT true,
    stats JSONB,
    geom GEOMETRY(Geometry, 25832) -- Using 25832, ST_Transform handled in server.js
);

-- 2. Ensure Eigentuemerdaten and Nutzung have the expected columns
ALTER TABLE "Eigentuemerdaten" ADD COLUMN IF NOT EXISTS status TEXT DEFAULT 'Unbekannt';
ALTER TABLE "Eigentuemerdaten" ADD COLUMN IF NOT EXISTS notiz TEXT DEFAULT '';

-- Spatial index for performance
CREATE INDEX IF NOT EXISTS trasse_geom_idx ON "Kabeltrasse" USING GIST (geom);
