mirror of
https://github.com/get-drexa/drive.git
synced 2025-12-01 05:51:39 +00:00
fix: migration code not working
- read database config from config file - rename migration file to expected file name format
This commit is contained in:
@@ -1,17 +1,28 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
|
||||
"github.com/uptrace/bun"
|
||||
"github.com/uptrace/bun/migrate"
|
||||
)
|
||||
|
||||
//go:embed migrations/*.sql
|
||||
var sqlMigrations embed.FS
|
||||
|
||||
// RunMigrations discovers and runs all migrations in the migrations directory.
|
||||
// Currently, the migrations directory is in internal/db/migrations.
|
||||
func RunMigrations() error {
|
||||
m := migrate.NewMigrations()
|
||||
return m.Discover(sqlMigrations)
|
||||
// RunMigrations discovers and runs all migrations against the database.
|
||||
func RunMigrations(ctx context.Context, db *bun.DB) error {
|
||||
migrations := migrate.NewMigrations()
|
||||
if err := migrations.Discover(sqlMigrations); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
migrator := migrate.NewMigrator(db, migrations)
|
||||
if err := migrator.Init(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := migrator.Migrate(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user