20260629154839

This commit is contained in:
oneao committed 2026-06-29 15:48:39 +08:00
1 parent e687846eb4
commit bb596f3245
41 files changed
+5735 -86

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"time"
"allapp-go/internal/bootstrap/boots"
"allapp-go/internal/config"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintln(os.Stderr, "usage: go run ./cmd/apply_sql <sql-file>")
os.Exit(1)
}
sqlPath, err := filepath.Abs(os.Args[1])
if err != nil {
exitErr("resolve sql path", err)
}
sqlBytes, err := os.ReadFile(sqlPath)
if err != nil {
exitErr("read sql file", err)
}
cfg, err := config.Load()
if err != nil {
exitErr("load config", err)
}
pool, err := boots.InitPgsql(cfg)
if err != nil {
exitErr("connect postgres", err)
}
defer pool.Close()
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
if _, err := pool.Exec(ctx, string(sqlBytes)); err != nil {
exitErr("execute sql", err)
}
fmt.Printf("applied sql: %s\n", sqlPath)
}
func exitErr(step string, err error) {
fmt.Fprintf(os.Stderr, "%s failed: %v\n", step, err)
os.Exit(1)
}