-- CreateTable
CREATE TABLE "Location" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "name" TEXT NOT NULL,
    "description" TEXT
);

-- CreateTable
CREATE TABLE "Cable" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "identifier" TEXT NOT NULL,
    "description" TEXT,
    "notes" TEXT,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    "startLocationId" INTEGER NOT NULL,
    "endLocationId" INTEGER NOT NULL,
    CONSTRAINT "Cable_startLocationId_fkey" FOREIGN KEY ("startLocationId") REFERENCES "Location" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT "Cable_endLocationId_fkey" FOREIGN KEY ("endLocationId") REFERENCES "Location" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "Core" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "color" TEXT NOT NULL,
    "notes" TEXT,
    "cableId" INTEGER NOT NULL,
    CONSTRAINT "Core_cableId_fkey" FOREIGN KEY ("cableId") REFERENCES "Cable" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "CableStop" (
    "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    "order" INTEGER NOT NULL,
    "cableId" INTEGER NOT NULL,
    "locationId" INTEGER NOT NULL,
    CONSTRAINT "CableStop_cableId_fkey" FOREIGN KEY ("cableId") REFERENCES "Cable" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "CableStop_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "Location" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateIndex
CREATE UNIQUE INDEX "CableStop_cableId_order_key" ON "CableStop"("cableId", "order");
