fix: migration code not working

- read database config from config file
- rename migration file to expected file name format
This commit is contained in:
2025-11-29 20:32:32 +00:00
parent 42b805fbd1
commit 5e4e08c255
3 changed files with 46 additions and 34 deletions

View File

@@ -1,13 +1,37 @@
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"github.com/get-drexa/drexa/internal/database"
"github.com/get-drexa/drexa/internal/drexa"
)
func main() {
if err := database.RunMigrations(); err != nil {
log.Fatalf("Failed to run migrations: %v", err)
configPath := flag.String("config", "", "path to config file (required)")
flag.Parse()
if *configPath == "" {
fmt.Fprintln(os.Stderr, "error: --config is required")
flag.Usage()
os.Exit(1)
}
config, err := drexa.ConfigFromFile(*configPath)
if err != nil {
log.Fatalf("failed to load config: %v", err)
}
db := database.NewFromPostgres(config.Database.PostgresURL)
defer db.Close()
log.Println("running migrations...")
if err := database.RunMigrations(context.Background(), db); err != nil {
log.Fatalf("failed to run migrations: %v", err)
}
log.Println("migrations completed successfully")
}