/*
  Warnings:

  - You are about to alter the column `spend` on the `account_spend_report` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
  - You are about to alter the column `fee` on the `account_spend_report` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
  - You are about to alter the column `feePercent` on the `account_spend_report` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
  - You are about to alter the column `feeSubscription` on the `account_spend_report` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
  - You are about to alter the column `totalSpend` on the `account_spend_report` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
  - You are about to alter the column `clawback` on the `provider_revenue` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
  - You are about to alter the column `revenue` on the `provider_revenue` table. The data in that column could be lost. The data in that column will be cast from `DoublePrecision` to `Decimal(65,30)`.
  - A unique constraint covering the columns `[monthlyReportId]` on the table `total_finance_report` will be added. If there are existing duplicate values, this will fail.
  - Added the required column `monthlyReportId` to the `total_finance_report` table without a default value. This is not possible if the table is not empty.
  - Added the required column `monthlyReportId` to the `transaction` table without a default value. This is not possible if the table is not empty.

*/
-- AlterEnum
ALTER TYPE "TransactionType" ADD VALUE 'OUTSTANDING_TO_PAID';

-- AlterTable
ALTER TABLE "account_spend_report" ALTER COLUMN "spend" SET DATA TYPE DECIMAL(65,30),
ALTER COLUMN "fee" SET DATA TYPE DECIMAL(65,30),
ALTER COLUMN "feePercent" SET DATA TYPE DECIMAL(65,30),
ALTER COLUMN "feeSubscription" SET DATA TYPE DECIMAL(65,30),
ALTER COLUMN "totalSpend" SET DATA TYPE DECIMAL(65,30);

-- AlterTable
ALTER TABLE "provider_revenue" ALTER COLUMN "clawback" SET DATA TYPE DECIMAL(65,30),
ALTER COLUMN "revenue" SET DATA TYPE DECIMAL(65,30);

-- AlterTable
ALTER TABLE "total_finance_report" ADD COLUMN     "monthlyReportId" INTEGER NOT NULL;

-- AlterTable
ALTER TABLE "transaction" ADD COLUMN     "monthlyReportId" INTEGER NOT NULL;

-- CreateTable
CREATE TABLE "monthly_report" (
    "id" SERIAL NOT NULL,
    "createDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updateDate" TIMESTAMP(3) NOT NULL,
    "dateFrom" TIMESTAMP(3) NOT NULL,
    "dateTo" TIMESTAMP(3) NOT NULL,
    "archived" BOOLEAN NOT NULL DEFAULT false,

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

-- CreateIndex
CREATE UNIQUE INDEX "total_finance_report_monthlyReportId_key" ON "total_finance_report"("monthlyReportId");

-- AddForeignKey
ALTER TABLE "total_finance_report" ADD CONSTRAINT "total_finance_report_monthlyReportId_fkey" FOREIGN KEY ("monthlyReportId") REFERENCES "monthly_report"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "transaction" ADD CONSTRAINT "transaction_monthlyReportId_fkey" FOREIGN KEY ("monthlyReportId") REFERENCES "monthly_report"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
