set infra

This commit is contained in:
vanilia
2025-11-13 09:57:10 +07:00
parent 94ce6bd5ee
commit ebc2ca5659
24 changed files with 843 additions and 105 deletions
-41
View File
@@ -1,41 +0,0 @@
appCfg:
fullName: SIMRS Sync
codeName: simrs-sync
version: 0.1.0
env: development
lang: en
dbCfg:
dsn:
maxOpenConns: 5
maxIdleConns: 5
maxIdleTime: 100
multiDbCfg:
dbs :
- name: simrs_sync
dsn:
maxOpenConns: 5
maxIdleConns: 5
maxIdleTime: 100
httpCfg:
host: 127.0.0.1
port: 8003
loggerCfg:
hideTime: true
hideLevel: true
langCfg:
active: en
path: ../../assets/language/en
fileName: data.json
corsCfg:
allowedOrigin:
allowedMethod: GET, POST, PUT, PATCH, DELETE, OPTIONS
syncUrlCfg:
target:
host:
-15
View File
@@ -1,15 +0,0 @@
package main
import (
a "github.com/karincake/apem"
h "simrs-vx/internal/interface/main-sync-handler"
d "github.com/karincake/apem/db-gorm-pg"
l "github.com/karincake/apem/logger-zerolog"
)
func main() {
a.Run(h.SetRoutes(), &l.O, &d.O)
}
+1 -5
View File
@@ -34,8 +34,4 @@ langCfg:
corsCfg:
allowedOrigin:
allowedMethod: GET, POST, PUT, PATCH, DELETE, OPTIONS
syncUrlCfg:
target:
host:
allowedMethod: GET, POST, PUT, PATCH, DELETE, OPTIONS
+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)
}