add user and person fk for employee

This commit is contained in:
dpurbosakti
2025-09-01 14:34:19 +07:00
parent 2cacfc5f33
commit ee160f877f
4 changed files with 14 additions and 3 deletions
@@ -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;
+3 -2
View File
@@ -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=
@@ -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"`
+1 -1
View File
@@ -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"`