-- CreateTable
CREATE TABLE "users" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "username" TEXT NOT NULL,
    "email" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "layout_configurations" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "layout_configurations_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "layout_sections" (
    "id" SERIAL NOT NULL,
    "configurationId" INTEGER NOT NULL,
    "name" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "sheetName" TEXT NOT NULL,
    "startingRow" INTEGER,
    "endingRow" INTEGER,
    "tableName" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "layout_sections_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "layout_section_fields" (
    "id" SERIAL NOT NULL,
    "layoutSectionId" INTEGER NOT NULL,
    "cellPosition" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "dataType" TEXT NOT NULL,
    "dataTypeFormat" TEXT,
    "importTableColumnName" TEXT NOT NULL,
    "importColumnOrderNumber" INTEGER NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "layout_section_fields_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "layout_sections" ADD CONSTRAINT "layout_sections_configurationId_fkey" FOREIGN KEY ("configurationId") REFERENCES "layout_configurations"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "layout_section_fields" ADD CONSTRAINT "layout_section_fields_layoutSectionId_fkey" FOREIGN KEY ("layoutSectionId") REFERENCES "layout_sections"("id") ON DELETE CASCADE ON UPDATE CASCADE;
