From 123210c2dd01dfc79acf0f7ac5f1b4ca8efc4a71 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 28 Jun 2024 09:31:17 +0700 Subject: [PATCH] feat: add user update info to history --- .../migration.sql | 14 ++++++++++++++ .../migration.sql | 7 +++++++ prisma/schema.prisma | 6 ++++++ 3 files changed, 27 insertions(+) create mode 100644 prisma/migrations/20240628020143_add_history_employee/migration.sql create mode 100644 prisma/migrations/20240628023020_add_updated_by_user_field/migration.sql diff --git a/prisma/migrations/20240628020143_add_history_employee/migration.sql b/prisma/migrations/20240628020143_add_history_employee/migration.sql new file mode 100644 index 0000000..b6840b8 --- /dev/null +++ b/prisma/migrations/20240628020143_add_history_employee/migration.sql @@ -0,0 +1,14 @@ +-- CreateTable +CREATE TABLE "EmployeeHistory" ( + "id" TEXT NOT NULL, + "field" TEXT NOT NULL, + "valueBefore" JSONB NOT NULL, + "valueAfter" JSONB NOT NULL, + "timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "masterId" TEXT NOT NULL, + + CONSTRAINT "EmployeeHistory_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "EmployeeHistory" ADD CONSTRAINT "EmployeeHistory_masterId_fkey" FOREIGN KEY ("masterId") REFERENCES "Employee"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240628023020_add_updated_by_user_field/migration.sql b/prisma/migrations/20240628023020_add_updated_by_user_field/migration.sql new file mode 100644 index 0000000..6ff205f --- /dev/null +++ b/prisma/migrations/20240628023020_add_updated_by_user_field/migration.sql @@ -0,0 +1,7 @@ +-- AlterTable +ALTER TABLE "EmployeeHistory" ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedBy" TEXT, +ADD COLUMN "updatedByUserId" TEXT; + +-- AddForeignKey +ALTER TABLE "EmployeeHistory" ADD CONSTRAINT "EmployeeHistory_updatedByUserId_fkey" FOREIGN KEY ("updatedByUserId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 6a2e62b..2a3caac 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -329,6 +329,7 @@ model User { branch BranchUser[] userMenuPermission UserMenuPermission[] userMenuComponentPermission UserMenuComponentPermission[] + employeeHistory EmployeeHistory[] } enum CustomerType { @@ -484,6 +485,11 @@ model EmployeeHistory { timestamp DateTime @default(now()) + updatedByUserId String? + updatedByUser User? @relation(fields: [updatedByUserId], references: [id]) + updatedBy String? + updatedAt DateTime @default(now()) + masterId String master Employee @relation(fields: [masterId], references: [id], onDelete: Cascade) }