This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/itworx/pulse/internal/database"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
defer cancel()
|
||||
databaseURL := os.Getenv("PULSE_DATABASE_URL")
|
||||
if databaseURL == "" {
|
||||
logger.Error("migration failed", "error", "PULSE_DATABASE_URL is required")
|
||||
os.Exit(1)
|
||||
}
|
||||
pool, err := database.NewPool(ctx, database.Config{URL: databaseURL})
|
||||
if err == nil {
|
||||
err = database.Ping(ctx, pool)
|
||||
}
|
||||
if err == nil {
|
||||
err = database.Migrate(ctx, pool)
|
||||
}
|
||||
if pool != nil {
|
||||
pool.Close()
|
||||
}
|
||||
if err != nil {
|
||||
logger.Error("migration failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
logger.Info("database migrations complete")
|
||||
}
|
||||
Reference in New Issue
Block a user