internal/database/migrate.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
package database import ( "fmt" "os" _ "github.com/lib/pq" // PostgreSQL driver "github.com/pressly/goose/v3" ) func (s *service) RunMigrations() error { databaseURL := os.Getenv("DB_CONN_STR") migrationPath := "internal/database/migrations" db, err := goose.OpenDBWithDriver("postgres", databaseURL) if err != nil { return fmt.Errorf("could not open database: %v", err) } defer db.Close() if err := goose.Up(db, migrationPath); err != nil { return fmt.Errorf("could not apply migrations: %v", err) } fmt.Println("Migrations applied successfully.") return nil } |