/*
  Warnings:

  - A unique constraint covering the columns `[employee_id]` on the table `users` will be added. If there are existing duplicate values, this will fail.

*/
-- CreateTable
CREATE TABLE "employee_salaries" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "salaryDate" TIMESTAMP(3) NOT NULL,
    "salaryMonth" INTEGER NOT NULL,
    "salaryYear" INTEGER NOT NULL,
    "paidDays" DECIMAL(5,2) NOT NULL,
    "netGrossTotal" DECIMAL(12,2) NOT NULL,
    "pf" DECIMAL(10,2) NOT NULL,
    "uploadedById" TEXT NOT NULL,
    "uploadedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "originalRow" JSONB,

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

-- CreateIndex
CREATE INDEX "employee_salaries_employeeId_salaryMonth_salaryYear_idx" ON "employee_salaries"("employeeId", "salaryMonth", "salaryYear");

-- CreateIndex
CREATE UNIQUE INDEX "users_employee_id_key" ON "users"("employee_id");

-- AddForeignKey
ALTER TABLE "employee_salaries" ADD CONSTRAINT "employee_salaries_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "users"("employee_id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "employee_salaries" ADD CONSTRAINT "employee_salaries_uploadedById_fkey" FOREIGN KEY ("uploadedById") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- Add unique constraint on employeeId, salaryMonth, salaryYear
ALTER TABLE "employee_salaries" ADD CONSTRAINT "employee_salaries_employeeId_salaryMonth_salaryYear_key" UNIQUE ("employeeId", "salaryMonth", "salaryYear");
