diff --git a/.gitignore b/.gitignore index f7357d8a..5f88f352 100644 --- a/.gitignore +++ b/.gitignore @@ -27,8 +27,8 @@ go.work.sum # env file .env config.yml -cmd/main-migration/atlas.hcl -cmd/satusehat-migration/atlas.hcl +**/atlas.hcl +!**/atlas.hcl.example # Editor/IDE # .idea/ diff --git a/cmd/main-migration/migrations/20251002085604.sql b/cmd/main-migration/migrations/20251002085604.sql new file mode 100644 index 00000000..e215cd13 --- /dev/null +++ b/cmd/main-migration/migrations/20251002085604.sql @@ -0,0 +1,2 @@ +-- Modify "Division" table +ALTER TABLE "public"."Division" ALTER COLUMN "Parent_Id" TYPE integer, ADD CONSTRAINT "fk_Division_Childrens" FOREIGN KEY ("Parent_Id") REFERENCES "public"."Division" ("Id") 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 4c7a0491..dc21429b 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:X7LbOLpbDhciJ1O92KiWgnrVP60dDAyBKJqQKJnom+M= +h1:kkT6c88mNI2KVSF5h2r1qdgxouqRlqt6scn0lhxl9+Q= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -20,4 +20,5 @@ h1:X7LbOLpbDhciJ1O92KiWgnrVP60dDAyBKJqQKJnom+M= 20250929034321.sql h1:101FJ8VH12mrZWlt/X1gvKUGOhoiF8tFbjiapAjnHzg= 20250929034428.sql h1:i+pROD9p+g5dOmmZma6WF/0Hw5g3Ha28NN85iTo1K34= 20250930025550.sql h1:+F+CsCUXD/ql0tHGEow70GhPBX1ZybVn+bh/T4YMh7Y= -20250930140351.sql h1:aqXw0j09+xjFqemWlo0enw3tn/IT1FMxw3oUPljkjks= +20250930140351.sql h1:9AAEG1AnOAH+o0+oHL5G7I8vqlWOhwRlCGyyCpT/y1Q= +20251002085604.sql h1:ml+jTtNkj5T12/loEW77jMScHbt+XAx4mN80heqo7+Q= diff --git a/internal/domain/main-entities/division/entity.go b/internal/domain/main-entities/division/entity.go index 7d3bc65d..5585d8a2 100644 --- a/internal/domain/main-entities/division/entity.go +++ b/internal/domain/main-entities/division/entity.go @@ -5,8 +5,10 @@ import ( ) type Division struct { - ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:10"` - Name string `json:"name" gorm:"size:50"` - Parent_Id *int16 `json:"parent_id"` + ecore.SmallMain // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:10"` + Name string `json:"name" gorm:"size:50"` + Parent_Id *int16 `json:"parent_id"` + Parent *Division `gorm:"foreignKey:Parent_Id;references:Id"` + Childrens []Division `gorm:"foreignKey:Parent_Id"` // may need references to self }