mirror of
https://github.com/gabehf/Koito.git
synced 2026-04-22 20:11:50 -07:00
fix: embed db migrations
This commit is contained in:
parent
5537b6fb89
commit
4a0519f01b
2 changed files with 9 additions and 8 deletions
6
db/migrations/migrations.go
Normal file
6
db/migrations/migrations.go
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
package migrations
|
||||||
|
|
||||||
|
import "embed"
|
||||||
|
|
||||||
|
//go:embed *.sql
|
||||||
|
var Files embed.FS
|
||||||
|
|
@ -5,10 +5,9 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gabehf/koito/db/migrations"
|
||||||
"github.com/gabehf/koito/internal/cfg"
|
"github.com/gabehf/koito/internal/cfg"
|
||||||
"github.com/gabehf/koito/internal/db"
|
"github.com/gabehf/koito/internal/db"
|
||||||
"github.com/gabehf/koito/internal/repository"
|
"github.com/gabehf/koito/internal/repository"
|
||||||
|
|
@ -54,13 +53,9 @@ func New() (*Psql, error) {
|
||||||
return nil, fmt.Errorf("psql.New: failed to open db for migrations: %w", err)
|
return nil, fmt.Errorf("psql.New: failed to open db for migrations: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, filename, _, ok := runtime.Caller(0)
|
goose.SetBaseFS(migrations.Files)
|
||||||
if !ok {
|
|
||||||
return nil, fmt.Errorf("psql.New: unable to get caller info")
|
|
||||||
}
|
|
||||||
migrationsPath := filepath.Join(filepath.Dir(filename), "..", "..", "..", "db", "migrations")
|
|
||||||
|
|
||||||
if err := goose.Up(sqlDB, migrationsPath); err != nil {
|
if err := goose.Up(sqlDB, "."); err != nil {
|
||||||
return nil, fmt.Errorf("psql.New: goose failed: %w", err)
|
return nil, fmt.Errorf("psql.New: goose failed: %w", err)
|
||||||
}
|
}
|
||||||
_ = sqlDB.Close()
|
_ = sqlDB.Close()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue