add instalation entity

This commit is contained in:
vanilia
2025-11-13 10:33:37 +07:00
parent 78f1502930
commit 4b78e489ef
11 changed files with 167 additions and 2 deletions
+18
View File
@@ -0,0 +1,18 @@
# Makefile for Atlas migrations
# Default environment
ENV ?= gorm
.PHONY: diff apply hash
## Generate a new migration diff
diff:
atlas migrate diff --env $(ENV)
## Apply migrations to the database
apply:
atlas migrate apply --env $(ENV)
## Calculate the schema hash
hash:
atlas migrate hash
+59
View File
@@ -0,0 +1,59 @@
# Database Migration with Atlas
This project uses [Atlas](https://atlasgo.io/) for database schema management and migrations.
## 📋 Prerequisites
1. **Download and Install Atlas CLI**
Run the following command in PowerShell or Git Bash:
```sh
curl -sSf https://atlasgo.sh | sh
```
Verify installation:
```sh
atlas version
```
2. Install GORM Provider
Run inside your Go project:
```sh
go get -u ariga.io/atlas-provider-gorm
```
3. Create atlas.hcl configuration file
Just create an atlas.hcl file in your project root as example given at atlas.hcl.example
4. Create migrations folder
```sh
mkdir migrations
```
5. Usage
You can use the provided Makefile for common commands:
Generate a migration diff
```sh
make diff
```
Apply migrations
```sh
make apply
```
Compute schema hash
```sh
make hash
```
If you dont have make installed, you can run the Atlas commands directly:
```sh
atlas migrate diff --env gorm
```
```sh
atlas migrate apply --env gorm
```
```sh
atlas migrate hash
```
@@ -0,0 +1,22 @@
data "external_schema" "gorm" {
program = [
"go",
"run",
"-mod=mod",
".",
]
}
env "gorm" {
src = data.external_schema.gorm.url
dev = "" // dsn db to check the diff
migration {
dir = "file://migrations"
}
url = "" // dsn db to apply
format {
migrate {
diff = "{{ sql . \" \" }}"
}
}
}
+9
View File
@@ -0,0 +1,9 @@
package main
import (
m "simrs-vx/internal/interface/migration"
)
func main() {
m.Migrate(m.SimgosSync)
}
@@ -16,6 +16,7 @@ type (
DataVerifiedCode string
CrudCode string
DataApprovalCode string
ProcessStatusCode string
)
const (
@@ -101,6 +102,9 @@ const (
DACNew DataApprovalCode = "new"
DACApproved DataApprovalCode = "approved"
DACRejected DataApprovalCode = "rejected"
PSCSuccess ProcessStatusCode = "success"
PSCFailed ProcessStatusCode = "failed"
)
func GetDayCodes() map[DayCode]string {
@@ -0,0 +1,12 @@
package installation
type MInstalasi struct {
NoInstalasi uint `json:"no_instalasi"`
NamaInstalasi string `json:"nama_instalasi"`
StatusRawatInap *uint `json:"status_rawat_inap"`
StAktif *uint64 `json:"st_aktif"`
}
func (MInstalasi) TableName() string {
return "m_instalasi"
}
@@ -0,0 +1,29 @@
package installation
import (
ecore "simrs-vx/internal/domain/base-entities/core"
erc "simrs-vx/internal/domain/references/common"
"time"
)
type InstallationLink struct {
ecore.Main
Simx_Id string `json:"simx_id" gorm:"unique"`
Simgos_Id uint64 `json:"simgos_id" gorm:"unique"`
}
type InstallationSimxLog struct {
ecore.Main
Value *string `json:"value"`
Date *time.Time `json:"date"`
Status erc.ProcessStatusCode `json:"status"`
ErrMessage *string `json:"errMessage"`
}
type InstallationSimgosLog struct {
ecore.Main
Value *string `json:"value"`
Date *time.Time `json:"date"`
Status erc.ProcessStatusCode `json:"status"`
ErrMessage *string `json:"errMessage"`
}
@@ -31,6 +31,8 @@ func getEntities(input string) []any {
return getMainEntities()
case "satusehat":
return getSatuSehatEntities()
case "simgossync":
return getSimgosSyncEntities()
}
return nil
}
@@ -0,0 +1,9 @@
package migration
func getSimgosSyncEntities() []any {
return []any{
//&installation.InstallationLink{},
//&installation.InstallationSimxLog{},
//&installation.InstallationSimgosLog{},
}
}
+3 -2
View File
@@ -2,6 +2,7 @@
package migration
const (
Main = "main"
SatuSehat = "satusehat"
Main = "main"
SatuSehat = "satusehat"
SimgosSync = "simgossync"
)