feat: Added migration tool

This commit is contained in:
2025-08-11 18:58:52 +03:00
parent e5aadbe9c8
commit 40a313f93b
6 changed files with 100 additions and 17 deletions

45
migration/main.go Normal file
View File

@@ -0,0 +1,45 @@
package migration
import (
"text/template"
"git.ostiwe.com/ostiwe-com/status/modules/db"
appLog "git.ostiwe.com/ostiwe-com/status/modules/log"
"github.com/pressly/goose/v3"
)
const migrationDir = "migrations"
var sqlMigrationTemplate = template.Must(template.New("goose.sql-migration").Parse(`-- +goose Up
-- +goose Down
`))
func init() {
goose.SetSequential(true)
goose.SetLogger(appLog.Global.Get(appLog.DATABASE))
}
func CreateMigration(name string) error {
return goose.CreateWithTemplate(nil, migrationDir, sqlMigrationTemplate, name, "sql")
}
func RunMigration() {
connect, err := db.Connect()
if err != nil {
panic(err)
}
dbConn, err := connect.DB()
if err != nil {
panic(err)
}
if err = goose.SetDialect("postgres"); err != nil {
panic(err)
}
if err = goose.Up(dbConn, migrationDir); err != nil {
panic(err)
}
}