package main import ( "context" "database/sql" "flag" "fmt" "os" "time" "github.com/cosmic-clash/cosmic-clash/server/migrations" _ "github.com/jackc/pgx/v5/stdlib" ) func main() { dsn := flag.String("dsn", os.Getenv("COSMIC_CLASH_POSTGRES_DSN"), "PostgreSQL connection string") directory := flag.String("dir", "migrations", "directory containing numbered SQL migrations") flag.Parse() if *dsn == "" { fmt.Fprintln(os.Stderr, "migrate: --dsn or COSMIC_CLASH_POSTGRES_DSN is required") os.Exit(2) } db, err := sql.Open("pgx", *dsn) if err != nil { fmt.Fprintln(os.Stderr, "migrate:", err) os.Exit(1) } defer db.Close() ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() if err := migrations.Apply(ctx, db, *directory); err != nil { fmt.Fprintln(os.Stderr, "migrate:", err) os.Exit(1) } fmt.Println("migrations applied") }