/*
  Warnings:

  - You are about to drop the column `tfType` on the `account_request` table. All the data in the column will be lost.
  - You are about to drop the column `requestId` on the `top_up` table. All the data in the column will be lost.
  - You are about to drop the column `deadline` on the `top_up_request` table. All the data in the column will be lost.
  - You are about to drop the `account_finanace_request` table. If the table is not empty, all the data it contains will be lost.
  - Added the required column `platform` to the `top_up_request` table without a default value. This is not possible if the table is not empty.
  - Added the required column `tfType` to the `top_up_request` table without a default value. This is not possible if the table is not empty.

*/
-- DropForeignKey
ALTER TABLE "account_finanace_request" DROP CONSTRAINT "account_finanace_request_userId_fkey";

-- DropForeignKey
ALTER TABLE "top_up" DROP CONSTRAINT "top_up_requestId_fkey";

-- AlterTable
ALTER TABLE "account_request" DROP COLUMN "tfType",
ADD COLUMN     "platform" "TrafficSource",
ADD COLUMN     "userId" INTEGER;

-- AlterTable
ALTER TABLE "top_up" DROP COLUMN "requestId";

-- AlterTable
ALTER TABLE "top_up_request" DROP COLUMN "deadline",
ADD COLUMN     "platform" "TrafficSource" NOT NULL,
ADD COLUMN     "tfType" "TrafficSource" NOT NULL;

-- DropTable
DROP TABLE "account_finanace_request";

-- CreateTable
CREATE TABLE "rename_request" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "note" TEXT,
    "status" "RequestStatus" NOT NULL DEFAULT 'NEW',
    "archived" BOOLEAN NOT NULL DEFAULT false,
    "requestType" "RequestType" NOT NULL DEFAULT 'RENAME_REQUEST',
    "newName" TEXT NOT NULL,
    "platform" "TrafficSource",
    "accountId" INTEGER NOT NULL,
    "userId" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "share_permition_request" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "note" TEXT,
    "status" "RequestStatus" NOT NULL DEFAULT 'NEW',
    "archived" BOOLEAN NOT NULL DEFAULT false,
    "requestType" "RequestType" NOT NULL DEFAULT 'SHARE_REQUEST',
    "platform" "TrafficSource",
    "userId" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "share_permition_request_accounts" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "requestId" INTEGER NOT NULL,
    "accountId" INTEGER NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "rename_request_id_key" ON "rename_request"("id");

-- CreateIndex
CREATE UNIQUE INDEX "share_permition_request_id_key" ON "share_permition_request"("id");

-- CreateIndex
CREATE UNIQUE INDEX "share_permition_request_accounts_id_key" ON "share_permition_request_accounts"("id");

-- AddForeignKey
ALTER TABLE "rename_request" ADD CONSTRAINT "rename_request_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "account"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "rename_request" ADD CONSTRAINT "rename_request_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "share_permition_request" ADD CONSTRAINT "share_permition_request_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "share_permition_request_accounts" ADD CONSTRAINT "share_permition_request_accounts_requestId_fkey" FOREIGN KEY ("requestId") REFERENCES "share_permition_request"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "share_permition_request_accounts" ADD CONSTRAINT "share_permition_request_accounts_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "account"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "account_request" ADD CONSTRAINT "account_request_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;
