feat(skel): db package with embedded migrations stub
Establishes the embed.FS and migrations/ layout up front. Migrate() returns ErrNotConfigured intentionally — the real goose runner lands in M2 alongside Postgres work, avoiding a toolchain bump to Go 1.24/1.25 through goose's transitive modernc.org/libc dependency chain.
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package db
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed migrations/*.sql
|
||||||
|
var migrationsFS embed.FS
|
||||||
|
|
||||||
|
// MigrationsFS exposes the embedded migration files. The concrete migration
|
||||||
|
// runner (goose) will be wired in M2 when Postgres work begins; this package
|
||||||
|
// intentionally keeps the embed + a placeholder surface so the file layout
|
||||||
|
// and `go:embed` directive are established from day one.
|
||||||
|
func MigrationsFS() embed.FS {
|
||||||
|
return migrationsFS
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrNotConfigured is returned by Migrate until the real runner is wired.
|
||||||
|
var ErrNotConfigured = errors.New("db: migrations not yet configured (wired in M2)")
|
||||||
|
|
||||||
|
// Migrate is a placeholder. It validates that the embedded migrations load
|
||||||
|
// and then returns ErrNotConfigured so callers can detect the stub.
|
||||||
|
func Migrate() error {
|
||||||
|
entries, err := migrationsFS.ReadDir("migrations")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(entries) == 0 {
|
||||||
|
return errors.New("db: no migration files found")
|
||||||
|
}
|
||||||
|
return ErrNotConfigured
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user