/*
  Warnings:

  - You are about to drop the column `currentSyncStartedAt` on the `PayrollProvider` table. All the data in the column will be lost.

*/
-- CreateEnum
CREATE TYPE "PayrollSyncStatus" AS ENUM ('Pending', 'Running', 'Failed', 'Complete');

-- CreateEnum
CREATE TYPE "PayrollSyncChangeType" AS ENUM ('Added', 'Updated', 'Connected');

-- CreateEnum
CREATE TYPE "PayrollSyncModelName" AS ENUM ('PayrollSync');

-- CreateEnum
CREATE TYPE "PayrollSyncChangeModelName" AS ENUM ('PayrollSyncChange');

-- AlterTable
ALTER TABLE "Member" ADD COLUMN     "dateOfBirth" DATE;

-- AlterTable
ALTER TABLE "PayrollProvider" DROP COLUMN "currentSyncStartedAt";

-- CreateTable
CREATE TABLE "PayrollSync" (
    "modelName" "PayrollSyncModelName" NOT NULL DEFAULT 'PayrollSync',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "payrollProviderId" UUID NOT NULL,
    "status" "PayrollSyncStatus" NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "organizationId" UUID NOT NULL,

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

-- CreateTable
CREATE TABLE "PayrollSyncChange" (
    "modelName" "PayrollSyncChangeModelName" NOT NULL DEFAULT 'PayrollSyncChange',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "payrollSyncId" UUID NOT NULL,
    "memberId" UUID NOT NULL,
    "type" "PayrollSyncChangeType" NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "organizationId" UUID NOT NULL,

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

-- AddForeignKey
ALTER TABLE "PayrollSync" ADD CONSTRAINT "PayrollSync_payrollProviderId_fkey" FOREIGN KEY ("payrollProviderId") REFERENCES "PayrollProvider"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PayrollSync" ADD CONSTRAINT "PayrollSync_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PayrollSyncChange" ADD CONSTRAINT "PayrollSyncChange_payrollSyncId_fkey" FOREIGN KEY ("payrollSyncId") REFERENCES "PayrollSync"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PayrollSyncChange" ADD CONSTRAINT "PayrollSyncChange_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PayrollSyncChange" ADD CONSTRAINT "PayrollSyncChange_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
