/*
  Warnings:

  - You are about to drop the `Bookmark` table. If the table is not empty, all the data it contains will be lost.

*/
-- CreateEnum
CREATE TYPE "SettingStatus" AS ENUM ('ACTIVE', 'INACTIVE', 'DRAFT');

-- DropForeignKey
ALTER TABLE "Bookmark" DROP CONSTRAINT "Bookmark_userId_fkey";

-- DropTable
DROP TABLE "Bookmark";

-- CreateTable
CREATE TABLE "HeaderSetting" (
    "id" TEXT NOT NULL,
    "code" TEXT NOT NULL,
    "description" TEXT,
    "status" "SettingStatus" NOT NULL DEFAULT 'ACTIVE',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "modifiedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "DetailSetting" (
    "id" TEXT NOT NULL,
    "headerId" TEXT NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "status" "SettingStatus" NOT NULL DEFAULT 'ACTIVE',
    "beginEffective" TIMESTAMP(3) NOT NULL,
    "endEffective" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "modifiedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE UNIQUE INDEX "HeaderSetting_code_key" ON "HeaderSetting"("code");

-- CreateIndex
CREATE INDEX "DetailSetting_headerId_idx" ON "DetailSetting"("headerId");

-- CreateIndex
CREATE UNIQUE INDEX "DetailSetting_headerId_code_key" ON "DetailSetting"("headerId", "code");

-- AddForeignKey
ALTER TABLE "DetailSetting" ADD CONSTRAINT "DetailSetting_headerId_fkey" FOREIGN KEY ("headerId") REFERENCES "HeaderSetting"("id") ON DELETE CASCADE ON UPDATE CASCADE;
