-- CreateEnum
CREATE TYPE "SlotState" AS ENUM ('READY', 'SUCCESS', 'EXTEND', 'DELETE', 'ERROR');

-- CreateTable
CREATE TABLE "User" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "auth" INTEGER NOT NULL DEFAULT 0,
    "pwd" TEXT NOT NULL DEFAULT '1234',
    "memo" TEXT,
    "slots" INTEGER NOT NULL DEFAULT 0,
    "date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "p2" INTEGER NOT NULL DEFAULT 0,
    "p3" INTEGER NOT NULL DEFAULT 0,
    "p4" INTEGER NOT NULL DEFAULT 0,

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

-- CreateTable
CREATE TABLE "Notify" (
    "id" SERIAL NOT NULL,
    "title" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "Slot" (
    "id" SERIAL NOT NULL,
    "status" "SlotState" NOT NULL DEFAULT 'READY',
    "parent" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "keyword" TEXT,
    "product" TEXT,
    "url" TEXT,
    "product2" TEXT,
    "url2" TEXT,
    "sDate" TIMESTAMP(3) NOT NULL,
    "eDate" TIMESTAMP(3) NOT NULL,
    "date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "p2" INTEGER NOT NULL DEFAULT 0,
    "p3" INTEGER NOT NULL DEFAULT 0,
    "p4" INTEGER NOT NULL DEFAULT 0,
    "productName" TEXT,
    "storeName" TEXT,
    "rank" INTEGER NOT NULL DEFAULT 0,
    "rankTime" TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE "Log" (
    "id" SERIAL NOT NULL,
    "p2" INTEGER NOT NULL DEFAULT 0,
    "p3" INTEGER NOT NULL DEFAULT 0,
    "p4" INTEGER NOT NULL DEFAULT 0,
    "status" "SlotState" NOT NULL DEFAULT 'READY',
    "parent" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "sDate" TIMESTAMP(3) NOT NULL,
    "eDate" TIMESTAMP(3) NOT NULL,
    "date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "slots" INTEGER NOT NULL DEFAULT 0,

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

-- CreateTable
CREATE TABLE "Setup" (
    "id" SERIAL NOT NULL,
    "key" TEXT NOT NULL,
    "value" TEXT,

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

-- CreateTable
CREATE TABLE "Crawl" (
    "id" SERIAL NOT NULL,
    "product" TEXT,
    "store" TEXT,
    "date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "mid" TEXT NOT NULL,
    "rtime" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "Rank" (
    "id" SERIAL NOT NULL,
    "mid" TEXT NOT NULL,
    "rank" INTEGER NOT NULL DEFAULT 0,
    "date" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE UNIQUE INDEX "User_name_key" ON "User"("name");

-- CreateIndex
CREATE UNIQUE INDEX "Setup_key_key" ON "Setup"("key");

-- CreateIndex
CREATE UNIQUE INDEX "Crawl_mid_key" ON "Crawl"("mid");

-- CreateIndex
CREATE INDEX "Rank_mid_idx" ON "Rank"("mid");
