/*
  Warnings:

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

*/
-- DropForeignKey
ALTER TABLE "account_issue_approve_request" DROP CONSTRAINT "account_issue_approve_request_requestId_fkey";

-- DropForeignKey
ALTER TABLE "account_issue_approve_request_entity" DROP CONSTRAINT "account_issue_approve_request_entity_accountId_fkey";

-- DropForeignKey
ALTER TABLE "account_issue_approve_request_entity" DROP CONSTRAINT "account_issue_approve_request_entity_accountIssueRequestId_fkey";

-- DropTable
DROP TABLE "account_issue_approve_request";

-- DropTable
DROP TABLE "account_issue_approve_request_entity";

-- CreateTable
CREATE TABLE "account_issue_request" (
    "id" SERIAL NOT NULL,
    "requestId" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "account_issue_request_entity" (
    "id" SERIAL NOT NULL,
    "issueType" "AccountIssueRequestIssueType" NOT NULL,
    "bmExternalId" TEXT NOT NULL,
    "accountId" INTEGER NOT NULL,
    "accountIssueRequestId" INTEGER NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "account_issue_request_id_key" ON "account_issue_request"("id");

-- CreateIndex
CREATE UNIQUE INDEX "account_issue_request_requestId_key" ON "account_issue_request"("requestId");

-- CreateIndex
CREATE UNIQUE INDEX "account_issue_request_entity_id_key" ON "account_issue_request_entity"("id");

-- AddForeignKey
ALTER TABLE "account_issue_request" ADD CONSTRAINT "account_issue_request_requestId_fkey" FOREIGN KEY ("requestId") REFERENCES "request"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "account_issue_request_entity" ADD CONSTRAINT "account_issue_request_entity_accountIssueRequestId_fkey" FOREIGN KEY ("accountIssueRequestId") REFERENCES "account_issue_request"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
