From 92d4fb8d3888bb84b8f5e1c1ba5ff39aa342326b Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 1 Oct 2025 11:27:32 +0700 Subject: [PATCH 1/5] migration from server --- cmd/main-migration/atlas.hcl | 7 ++-- cmd/main-migration/migrations/atlas.sum | 46 ++++++++++++------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/cmd/main-migration/atlas.hcl b/cmd/main-migration/atlas.hcl index 3372fb2d..163119d3 100644 --- a/cmd/main-migration/atlas.hcl +++ b/cmd/main-migration/atlas.hcl @@ -9,14 +9,15 @@ data "external_schema" "gorm" { env "gorm" { src = data.external_schema.gorm.url - dev = "postgres://moko:password@localhost:5432/simrs_vx3?sslmode=disable" + dev = "postgres://simrs:p@ssw0rd@localhost:5432/simrs-diff-01?sslmode=disable" migration { dir = "file://migrations" } - url = "postgres://moko:password@localhost:5432/simrs_vx1?sslmode=disable" + url = "postgres://simrs:p@ssw0rd@localhost:5432/simrs-01?sslmode=disable" format { migrate { diff = "{{ sql . \" \" }}" } } -} \ No newline at end of file +} + diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 4c7a0491..3c24d36a 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,23 +1,23 @@ -h1:X7LbOLpbDhciJ1O92KiWgnrVP60dDAyBKJqQKJnom+M= -20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= -20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= -20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= -20250908062323.sql h1:oXl6Z143tOpIl4EfP4B8JNU8LrMvVmHEtCgAfiB4gs8= -20250908073811.sql h1:m2aNXfnGxnLq1+rVWrh4f60q7fhyhV3gEwNu/OIqQlE= -20250908073839.sql h1:cPk54xjLdMs26uY8ZHjNWLuyfAMzV7Zb0/9oJQrsw04= -20250910055902.sql h1:5xwjAV6QbtZT9empTJKfhyAjdknbHzb15B0Ku5dzqtQ= -20250915123412.sql h1:D83xaU2YlDEd21HLup/YQpQ2easMToYCyy/oK6AFgQs= -20250916043819.sql h1:ekoTJsBqQZ8G8n0qJ03d13+eoNoc7sAUEQGA5D/CCxk= -20250917040616.sql h1:zoCnmcXuM7AVv85SmN7RmFglCgJnoDmpRWExH0LAc9Q= -20250917040751.sql h1:J1xyRrh32y1+lezwAyNwPcUQ6ABBSgbvzNLva4SVdQU= -20250917045138.sql h1:jKe1Z0uOLG4SGBYM+S/3P+/zMPztmgoderD5swnMuCg= -20250917093645.sql h1:cNI3Pbz1R3LxvIXLuexafJFCXUXrmuFCgXXJ2sG+FW0= -20250918073552.sql h1:RJ1SvMzP6aeWnoPVD3eVAmIQOkcp6Php8z3QRri6v4g= -20250918073742.sql h1:+cEsnJTJFybe2fR69ZoOiX2R6c6iITl4m6WTZ1hjyzY= -20250918074745.sql h1:2hNVQCXF/dVYXAh+T/7oBFgERGWxzVb2FXJjwkFWGCI= -20250923025134.sql h1:Ykz/qpHiGDXPsCsWTjydQFVSibZP2D+h2fIeb2h2JGA= -20250924051317.sql h1:yQuW6SwJxIOM5fcxeAaie5lSm1oLysU/C2hH2xNCVoQ= -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= +h1:NqZplHE9s3i2A3OK3OMBOTHfYgRfb+1HyZLBfS9SLeM= +20250904105930.sql h1:Vv4vCurl7m7/ZB6TjRpkubHpQ4RYwSUn0QHdzfoGpzY= +20250904141448.sql h1:FYCHH9Os4KkrZMDu/jR8FMP+wLMRW+Mb0PkLU/9BRDg= +20250908062237.sql h1:oanBpKZd+akPu2I/xYhUSbd0G5tAFbXzKLER/Zs8ENI= +20250908062323.sql h1:miNG9COddXkD1jGTgaROMAZ618eT6oiLGiJhXWnQwhE= +20250908073811.sql h1:gOi5cnGG1htlpfizybYmUIT0vYjZTBfXiI0nPSYK2u8= +20250908073839.sql h1:cWNDA4YikjoOteAJuNLFILjQUJPFB6o8Wxreiek4QyI= +20250910055902.sql h1:nxxOGnU0BbH/v3IPgeIOXOwH8d3tKomw7h6FTeMnnBs= +20250915123412.sql h1:mz7SiWfrdf0qE1VTSAAnA/147d6gyp6ry5vZ2bR9SH0= +20250916043819.sql h1:RHXVtmMkB6wfv06HfPyHMBmUfIpFt1xveafNz0kwKnE= +20250917040616.sql h1:MYVDht+akBlzQGKNu2hTTTLPEcH1bxT/Q8MK6WEtuhs= +20250917040751.sql h1:J79YyS2JzWgh5oKXMTgh67uo3gLxKaAsxRiZmSIfjBs= +20250917045138.sql h1:/SM1N4O8X3yxpoJgMEARmS1uOkuLKsTOy4PLsRCOKaQ= +20250917093645.sql h1:PNBTGZ7s10e5b5+Tie8YfVQBN0zKtJ5T34oK1iOUEb4= +20250918073552.sql h1:jG7+g3i8ODYaJdcdZz12v3nbsZ5mB9wG6kWnGyTQIRI= +20250918073742.sql h1:j+rgw7puxE7s+phqPVZHmPk0af3rcaA56Itp86y1suY= +20250918074745.sql h1:rPmP4DXs6OnY4Vp+xO/z9jFpJt/RrJ52SJJjIIxeDvc= +20250923025134.sql h1:2r6pcwnBSU5Y9Czk1OHBoh4yZXiMtEca9X8843fTEX0= +20250924051317.sql h1:iUAk2gsGoEGIPQ0lEEUp8maMSId8emNbP+kP712ABIA= +20250929034321.sql h1:UlpALNVmdi95zOIT0yc6ZyTj9bBjQEIpZhvgrc52M+k= +20250929034428.sql h1:feF+H4nDyHh5bdx48Oiz0A1qecZfi6v3qTTdjzJ45Dg= +20250930025550.sql h1:6XT1kXI3Z3ZIxxmvT7poufZWWCW0QiejZPaFV5wBnjI= +20250930140351.sql h1:HxnmAbh9gCy8jwl/9ycGktiByaUripsjFFvohofY2CY= From fe0fcecf807216d17e9b8d0008bce636cf56174e Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 2 Oct 2025 16:02:47 +0700 Subject: [PATCH 2/5] git commit -m "migration updates" --- .gitignore | 3 +- .../migrations/20251002085604.sql | 2 + cmd/main-migration/migrations/atlas.sum | 47 ++++++++++--------- .../domain/main-entities/division/entity.go | 10 ++-- 4 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 cmd/main-migration/migrations/20251002085604.sql diff --git a/.gitignore b/.gitignore index 286b9405..f7357d8a 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,8 @@ go.work.sum # env file .env config.yml -cmd/migration/atlas.hcl +cmd/main-migration/atlas.hcl +cmd/satusehat-migration/atlas.hcl # 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 3c24d36a..dc21429b 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,23 +1,24 @@ -h1:NqZplHE9s3i2A3OK3OMBOTHfYgRfb+1HyZLBfS9SLeM= -20250904105930.sql h1:Vv4vCurl7m7/ZB6TjRpkubHpQ4RYwSUn0QHdzfoGpzY= -20250904141448.sql h1:FYCHH9Os4KkrZMDu/jR8FMP+wLMRW+Mb0PkLU/9BRDg= -20250908062237.sql h1:oanBpKZd+akPu2I/xYhUSbd0G5tAFbXzKLER/Zs8ENI= -20250908062323.sql h1:miNG9COddXkD1jGTgaROMAZ618eT6oiLGiJhXWnQwhE= -20250908073811.sql h1:gOi5cnGG1htlpfizybYmUIT0vYjZTBfXiI0nPSYK2u8= -20250908073839.sql h1:cWNDA4YikjoOteAJuNLFILjQUJPFB6o8Wxreiek4QyI= -20250910055902.sql h1:nxxOGnU0BbH/v3IPgeIOXOwH8d3tKomw7h6FTeMnnBs= -20250915123412.sql h1:mz7SiWfrdf0qE1VTSAAnA/147d6gyp6ry5vZ2bR9SH0= -20250916043819.sql h1:RHXVtmMkB6wfv06HfPyHMBmUfIpFt1xveafNz0kwKnE= -20250917040616.sql h1:MYVDht+akBlzQGKNu2hTTTLPEcH1bxT/Q8MK6WEtuhs= -20250917040751.sql h1:J79YyS2JzWgh5oKXMTgh67uo3gLxKaAsxRiZmSIfjBs= -20250917045138.sql h1:/SM1N4O8X3yxpoJgMEARmS1uOkuLKsTOy4PLsRCOKaQ= -20250917093645.sql h1:PNBTGZ7s10e5b5+Tie8YfVQBN0zKtJ5T34oK1iOUEb4= -20250918073552.sql h1:jG7+g3i8ODYaJdcdZz12v3nbsZ5mB9wG6kWnGyTQIRI= -20250918073742.sql h1:j+rgw7puxE7s+phqPVZHmPk0af3rcaA56Itp86y1suY= -20250918074745.sql h1:rPmP4DXs6OnY4Vp+xO/z9jFpJt/RrJ52SJJjIIxeDvc= -20250923025134.sql h1:2r6pcwnBSU5Y9Czk1OHBoh4yZXiMtEca9X8843fTEX0= -20250924051317.sql h1:iUAk2gsGoEGIPQ0lEEUp8maMSId8emNbP+kP712ABIA= -20250929034321.sql h1:UlpALNVmdi95zOIT0yc6ZyTj9bBjQEIpZhvgrc52M+k= -20250929034428.sql h1:feF+H4nDyHh5bdx48Oiz0A1qecZfi6v3qTTdjzJ45Dg= -20250930025550.sql h1:6XT1kXI3Z3ZIxxmvT7poufZWWCW0QiejZPaFV5wBnjI= -20250930140351.sql h1:HxnmAbh9gCy8jwl/9ycGktiByaUripsjFFvohofY2CY= +h1:kkT6c88mNI2KVSF5h2r1qdgxouqRlqt6scn0lhxl9+Q= +20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= +20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= +20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= +20250908062323.sql h1:oXl6Z143tOpIl4EfP4B8JNU8LrMvVmHEtCgAfiB4gs8= +20250908073811.sql h1:m2aNXfnGxnLq1+rVWrh4f60q7fhyhV3gEwNu/OIqQlE= +20250908073839.sql h1:cPk54xjLdMs26uY8ZHjNWLuyfAMzV7Zb0/9oJQrsw04= +20250910055902.sql h1:5xwjAV6QbtZT9empTJKfhyAjdknbHzb15B0Ku5dzqtQ= +20250915123412.sql h1:D83xaU2YlDEd21HLup/YQpQ2easMToYCyy/oK6AFgQs= +20250916043819.sql h1:ekoTJsBqQZ8G8n0qJ03d13+eoNoc7sAUEQGA5D/CCxk= +20250917040616.sql h1:zoCnmcXuM7AVv85SmN7RmFglCgJnoDmpRWExH0LAc9Q= +20250917040751.sql h1:J1xyRrh32y1+lezwAyNwPcUQ6ABBSgbvzNLva4SVdQU= +20250917045138.sql h1:jKe1Z0uOLG4SGBYM+S/3P+/zMPztmgoderD5swnMuCg= +20250917093645.sql h1:cNI3Pbz1R3LxvIXLuexafJFCXUXrmuFCgXXJ2sG+FW0= +20250918073552.sql h1:RJ1SvMzP6aeWnoPVD3eVAmIQOkcp6Php8z3QRri6v4g= +20250918073742.sql h1:+cEsnJTJFybe2fR69ZoOiX2R6c6iITl4m6WTZ1hjyzY= +20250918074745.sql h1:2hNVQCXF/dVYXAh+T/7oBFgERGWxzVb2FXJjwkFWGCI= +20250923025134.sql h1:Ykz/qpHiGDXPsCsWTjydQFVSibZP2D+h2fIeb2h2JGA= +20250924051317.sql h1:yQuW6SwJxIOM5fcxeAaie5lSm1oLysU/C2hH2xNCVoQ= +20250929034321.sql h1:101FJ8VH12mrZWlt/X1gvKUGOhoiF8tFbjiapAjnHzg= +20250929034428.sql h1:i+pROD9p+g5dOmmZma6WF/0Hw5g3Ha28NN85iTo1K34= +20250930025550.sql h1:+F+CsCUXD/ql0tHGEow70GhPBX1ZybVn+bh/T4YMh7Y= +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..bf600c88 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"` } From 82fd71dbbf7240a0994f7b7dbebf5fc5f3698cee Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 2 Oct 2025 16:03:26 +0700 Subject: [PATCH 3/5] update gitignore to ignore atlas.hcl files --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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/ From c946380e4a436a724c6b7f47603756b4e80919c9 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 2 Oct 2025 16:05:21 +0700 Subject: [PATCH 4/5] stop tracking atlas.hcl files (ignored) --- cmd/main-migration/atlas.hcl | 23 ----------------------- cmd/satusehat-migration/atlas.hcl | 22 ---------------------- 2 files changed, 45 deletions(-) delete mode 100644 cmd/main-migration/atlas.hcl delete mode 100644 cmd/satusehat-migration/atlas.hcl diff --git a/cmd/main-migration/atlas.hcl b/cmd/main-migration/atlas.hcl deleted file mode 100644 index 163119d3..00000000 --- a/cmd/main-migration/atlas.hcl +++ /dev/null @@ -1,23 +0,0 @@ -data "external_schema" "gorm" { - program = [ - "go", - "run", - "-mod=mod", - ".", - ] -} - -env "gorm" { - src = data.external_schema.gorm.url - dev = "postgres://simrs:p@ssw0rd@localhost:5432/simrs-diff-01?sslmode=disable" - migration { - dir = "file://migrations" - } - url = "postgres://simrs:p@ssw0rd@localhost:5432/simrs-01?sslmode=disable" - format { - migrate { - diff = "{{ sql . \" \" }}" - } - } -} - diff --git a/cmd/satusehat-migration/atlas.hcl b/cmd/satusehat-migration/atlas.hcl deleted file mode 100644 index 5efd3e80..00000000 --- a/cmd/satusehat-migration/atlas.hcl +++ /dev/null @@ -1,22 +0,0 @@ -data "external_schema" "gorm" { - program = [ - "go", - "run", - "-mod=mod", - ".", - ] -} - -env "gorm" { - src = data.external_schema.gorm.url - dev = "postgres://moko:password@localhost:5432/satusehat_diff?sslmode=disable" - migration { - dir = "file://migrations" - } - url = "postgres://moko:password@localhost:5432/satusehat_main?sslmode=disable" - format { - migrate { - diff = "{{ sql . \" \" }}" - } - } -} \ No newline at end of file From 01ea6b0961cbb0782e72df760ab46d6fcaba1e94 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 2 Oct 2025 16:06:44 +0700 Subject: [PATCH 5/5] add comment in division entity --- internal/domain/main-entities/division/entity.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/domain/main-entities/division/entity.go b/internal/domain/main-entities/division/entity.go index bf600c88..5585d8a2 100644 --- a/internal/domain/main-entities/division/entity.go +++ b/internal/domain/main-entities/division/entity.go @@ -10,5 +10,5 @@ type Division struct { 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"` + Childrens []Division `gorm:"foreignKey:Parent_Id"` // may need references to self }