From ee160f877f1a6138294dc641cbfabbddf75d39be Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 1 Sep 2025 14:34:19 +0700 Subject: [PATCH] add user and person fk for employee --- cmd/migration/migrations/20250901073356.sql | 6 ++++++ cmd/migration/migrations/atlas.sum | 5 +++-- internal/domain/main-entities/employee/entity.go | 4 ++++ internal/domain/main-entities/user/entity.go | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 cmd/migration/migrations/20250901073356.sql diff --git a/cmd/migration/migrations/20250901073356.sql b/cmd/migration/migrations/20250901073356.sql new file mode 100644 index 00000000..4ffe005f --- /dev/null +++ b/cmd/migration/migrations/20250901073356.sql @@ -0,0 +1,6 @@ +-- Modify "Infra" table +ALTER TABLE "public"."Infra" ALTER COLUMN "Parent_Id" TYPE integer; +-- Modify "User" table +ALTER TABLE "public"."User" ADD CONSTRAINT "uni_User_Name" UNIQUE ("Name"); +-- Modify "Employee" table +ALTER TABLE "public"."Employee" ADD CONSTRAINT "fk_Employee_Person" FOREIGN KEY ("Person_Id") REFERENCES "public"."Person" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Employee_User" FOREIGN KEY ("User_Id") REFERENCES "public"."User" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/migration/migrations/atlas.sum b/cmd/migration/migrations/atlas.sum index e818fb5f..6da3d7a3 100644 --- a/cmd/migration/migrations/atlas.sum +++ b/cmd/migration/migrations/atlas.sum @@ -1,2 +1,3 @@ -h1:UO+I1wZYLfwSyDcWbSN/dgiNfkPYW567Smq1CT+Xeng= -20250829081952.sql h1:WgG/R3VjMqxFwOaqOACdoDVM9UKQDcaKAq77LxfIDWo= +h1:LmZ7NtbArHgEvza5276tSjY3D8/0w98RKEJYM3gxMZk= +20250829081952.sql h1:YMsYq3uPsx70EjWSGfYnVRR5GV0q1fRGIszYZAWzXNo= +20250901073356.sql h1:Me41GuoGLGDagM6claco/7G6I1aFBxZAQjdR3qhTxuQ= diff --git a/internal/domain/main-entities/employee/entity.go b/internal/domain/main-entities/employee/entity.go index 15ca4ce9..24687262 100644 --- a/internal/domain/main-entities/employee/entity.go +++ b/internal/domain/main-entities/employee/entity.go @@ -3,6 +3,8 @@ package employee import ( ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/division" + ep "simrs-vx/internal/domain/main-entities/person" + eu "simrs-vx/internal/domain/main-entities/user" erc "simrs-vx/internal/domain/references/common" ero "simrs-vx/internal/domain/references/organization" ) @@ -10,7 +12,9 @@ import ( type Employee struct { ecore.Main // adjust this according to the needs User_Id *uint `json:"user_id"` + User *eu.User `json:"user,omitempty" gorm:"foreignKey:User_Id;references:Id"` Person_Id *uint `json:"person_id"` + Person *ep.Person `json:"person,omitempty" gorm:"foreignKey:Person_Id;references:Id"` Position_Code ero.EmployeePosisitionCode `json:"position_code" gorm:"not null;size:20"` Division_Code *string `json:"division_code"` Division *ed.Division `json:"division,omitempty" gorm:"foreignKey:Division_Code;references:Code"` diff --git a/internal/domain/main-entities/user/entity.go b/internal/domain/main-entities/user/entity.go index 0db3beea..3ad46b9d 100644 --- a/internal/domain/main-entities/user/entity.go +++ b/internal/domain/main-entities/user/entity.go @@ -8,7 +8,7 @@ import ( type User struct { ecore.Main // adjust this according to the needs - Name string `json:"name" gorm:"not null;size:25"` + Name string `json:"name" gorm:"unique;not null;size:25"` Password string `json:"password" gorm:"not null;size:255"` Status_Code erc.UserStatusCode `json:"status_code" gorm:"not null;size:10"` FailedLoginCount uint8 `json:"failedLoginCount" gorm:"type:smallint"`