-- DropForeignKey
ALTER TABLE "RequestWorkStepStatus" DROP CONSTRAINT "RequestWorkStepStatus_requestWorkId_fkey";

-- DropForeignKey
ALTER TABLE "Task" DROP CONSTRAINT "Task_taskOrderId_fkey";

-- DropForeignKey
ALTER TABLE "TaskOrder" DROP CONSTRAINT "TaskOrder_createdByUserId_fkey";

-- DropForeignKey
ALTER TABLE "TaskProduct" DROP CONSTRAINT "TaskProduct_taskOrderId_fkey";

-- DropForeignKey
ALTER TABLE "UserTask" DROP CONSTRAINT "UserTask_taskOrderId_fkey";

-- DropForeignKey
ALTER TABLE "UserTask" DROP CONSTRAINT "UserTask_userId_fkey";

-- AlterTable
ALTER TABLE "TaskOrder" ALTER COLUMN "createdByUserId" DROP NOT NULL;

-- AddForeignKey
ALTER TABLE "RequestWorkStepStatus" ADD CONSTRAINT "RequestWorkStepStatus_requestWorkId_fkey" FOREIGN KEY ("requestWorkId") REFERENCES "RequestWork"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Task" ADD CONSTRAINT "Task_taskOrderId_fkey" FOREIGN KEY ("taskOrderId") REFERENCES "TaskOrder"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TaskProduct" ADD CONSTRAINT "TaskProduct_taskOrderId_fkey" FOREIGN KEY ("taskOrderId") REFERENCES "TaskOrder"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TaskOrder" ADD CONSTRAINT "TaskOrder_createdByUserId_fkey" FOREIGN KEY ("createdByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UserTask" ADD CONSTRAINT "UserTask_taskOrderId_fkey" FOREIGN KEY ("taskOrderId") REFERENCES "TaskOrder"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UserTask" ADD CONSTRAINT "UserTask_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
