-- Table: public.Kanaele

-- DROP TABLE IF EXISTS public."Kanaele";

CREATE TABLE IF NOT EXISTS public."Kanaele"
(
    "Id" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    "Objektbezeichnung" text COLLATE pg_catalog."default",
    "StartSchachtId" integer,
    "EndSchachtId" integer,
    "DN" integer NOT NULL,
    "Material" text COLLATE pg_catalog."default",
    "Haltungslaenge" numeric NOT NULL,
    "Entwaesserung" integer NOT NULL,
    "ProjektId" integer,
    CONSTRAINT "PK_Kanaele" PRIMARY KEY ("Id"),
    CONSTRAINT "FK_Kanaele_Projekte_ProjektId" FOREIGN KEY ("ProjektId")
        REFERENCES public."Projekte" ("Id") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "FK_Kanaele_Schaechte_EndSchachtId" FOREIGN KEY ("EndSchachtId")
        REFERENCES public."Schaechte" ("Id") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "FK_Kanaele_Schaechte_StartSchachtId" FOREIGN KEY ("StartSchachtId")
        REFERENCES public."Schaechte" ("Id") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public."Kanaele"
    OWNER to "SewerGen";
-- Index: IX_Kanaele_EndSchachtId

-- DROP INDEX IF EXISTS public."IX_Kanaele_EndSchachtId";

CREATE INDEX IF NOT EXISTS "IX_Kanaele_EndSchachtId"
    ON public."Kanaele" USING btree
    ("EndSchachtId" ASC NULLS LAST)
    TABLESPACE pg_default;
-- Index: IX_Kanaele_ProjektId

-- DROP INDEX IF EXISTS public."IX_Kanaele_ProjektId";

CREATE INDEX IF NOT EXISTS "IX_Kanaele_ProjektId"
    ON public."Kanaele" USING btree
    ("ProjektId" ASC NULLS LAST)
    TABLESPACE pg_default;
-- Index: IX_Kanaele_StartSchachtId

-- DROP INDEX IF EXISTS public."IX_Kanaele_StartSchachtId";

CREATE INDEX IF NOT EXISTS "IX_Kanaele_StartSchachtId"
    ON public."Kanaele" USING btree
    ("StartSchachtId" ASC NULLS LAST)
    TABLESPACE pg_default;