diff --git a/cmd/main-migration/migrations/20251010031743.sql b/cmd/main-migration/migrations/20251010031743.sql new file mode 100644 index 00000000..1dea016a --- /dev/null +++ b/cmd/main-migration/migrations/20251010031743.sql @@ -0,0 +1,6 @@ +-- Modify "Person" table +ALTER TABLE "public"."Person" ADD CONSTRAINT "fk_Person_BirthRegency" FOREIGN KEY ("BirthRegency_Code") REFERENCES "public"."Regency" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Rename a column from "PostalCode" to "PostalCode_Code" +ALTER TABLE "public"."PersonAddress" RENAME COLUMN "PostalCode" TO "PostalCode_Code"; +-- Modify "PersonAddress" table +ALTER TABLE "public"."PersonAddress" ADD CONSTRAINT "fk_PersonAddress_PostalCode" FOREIGN KEY ("PostalCode_Code") REFERENCES "public"."PostalCode" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index e06784b3..fed6c077 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:TrdoKKXrICvDA283WGDf33WtWHglk1twvjDpYrNwc8o= +h1:tvJWAAI1ENRhCwoYTUekIO7b9RxtkQllUFwCYQ/S17w= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -32,5 +32,6 @@ h1:TrdoKKXrICvDA283WGDf33WtWHglk1twvjDpYrNwc8o= 20251008031554.sql h1:AqrVfIhSzY3PCy8ZlP5W91wn2iznfIuj5qQfubp6/94= 20251008052346.sql h1:nxnXmooIJ6r1mmzwnw+6efxLfc/k9h2aE6RMptPRons= 20251008073620.sql h1:6YsJp1W4SmQJ1lxpqF27BBlDC1zqhw7Yhc7pLzQTY6M= -20251009042854.sql h1:vK7bDqUDTxjHMSh1wrQiKITeqbB/7aqkWaPut8nGA68= -20251009052657.sql h1:I0rBPBg1o6zuRaxqWqCh82rI+NN7Gr6C//8ItUaLmtY= +20251009042854.sql h1:nkBV+R6j0fg7/JY6wH3eb5Vv0asJLnXmb6lINfT/GLQ= +20251009052657.sql h1:EPvdsib5rzCGPryd10HShGKvFPwM/R5S2lIVwtYxpms= +20251010031743.sql h1:XGl/0//kV22jCXS+k+qZASm/zN6uapZjOCPBAGg7+yo= diff --git a/internal/domain/main-entities/person-address/entity.go b/internal/domain/main-entities/person-address/entity.go index eacfd9f0..f3fc3bac 100644 --- a/internal/domain/main-entities/person-address/entity.go +++ b/internal/domain/main-entities/person-address/entity.go @@ -2,14 +2,16 @@ package personaddress import ( ecore "simrs-vx/internal/domain/base-entities/core" + epc "simrs-vx/internal/domain/main-entities/postal-code" ) type PersonAddress struct { - ecore.Main // adjust this according to the needs - Person_Id uint `json:"person_id"` - Address string `json:"address" gorm:"size:150"` - Rt string `json:"rt" gorm:"size:2"` - Rw string `json:"rw" gorm:"size:2"` - PostalCode string `json:"postalCode" gorm:"size:6"` - Village_Code string `json:"village_code" gorm:"size:10"` + ecore.Main // adjust this according to the needs + Person_Id uint `json:"person_id"` + Address string `json:"address" gorm:"size:150"` + Rt string `json:"rt" gorm:"size:2"` + Rw string `json:"rw" gorm:"size:2"` + PostalCode_Code string `json:"postalCode_code" gorm:"size:6"` + PostalCode *epc.PostalCode `json:"postalCode,omitempty" gorm:"foreignKey:PostalCode_Code;references:Code"` + Village_Code string `json:"village_code" gorm:"size:10"` } diff --git a/internal/domain/main-entities/person/entity.go b/internal/domain/main-entities/person/entity.go index 91b2462e..8639df25 100644 --- a/internal/domain/main-entities/person/entity.go +++ b/internal/domain/main-entities/person/entity.go @@ -7,6 +7,8 @@ import ( epa "simrs-vx/internal/domain/main-entities/person-address" epc "simrs-vx/internal/domain/main-entities/person-contact" epr "simrs-vx/internal/domain/main-entities/person-relative" + er "simrs-vx/internal/domain/main-entities/regency" + erp "simrs-vx/internal/domain/references/person" "time" @@ -19,6 +21,7 @@ type Person struct { EndTitle *string `json:"endTitle" gorm:"size:50"` BirthDate *time.Time `json:"birthDate,omitempty"` BirthRegency_Code *string `json:"birthRegency_code" gorm:"size:4"` + BirthRegency *er.Regency `json:"birthRegency,omitempty" gorm:"foreignKey:BirthRegency_Code;references:Code"` Gender_Code *erp.GenderCode `json:"gender_code" gorm:"size:10"` ResidentIdentityNumber *string `json:"residentIdentityNumber" gorm:"unique;size:16"` PassportNumber *string `json:"passportNumber" gorm:"unique;size:20"`