mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
dev day #69
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"fotbal-club/internal/config"
|
||||
dbpkg "fotbal-club/pkg/database"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
log.Fatalf("usage: go run ./cmd/sqlmigrate <path-to-sql>\n")
|
||||
}
|
||||
path := os.Args[1]
|
||||
|
||||
config.LoadConfig()
|
||||
db, err := dbpkg.InitDB()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to connect DB: %v", err)
|
||||
}
|
||||
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to read sql file: %v", err)
|
||||
}
|
||||
sql := string(b)
|
||||
if err := db.Exec(sql).Error; err != nil {
|
||||
log.Fatalf("failed to execute migration: %v", err)
|
||||
}
|
||||
fmt.Println("Migration executed successfully:", path)
|
||||
}
|
||||
Reference in New Issue
Block a user