bouncer/internal/migrate/migrate.go

31 lines
629 B
Go
Raw Permalink Normal View History

2023-04-24 20:52:12 +02:00
package migrate
import (
"fmt"
"github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/database/postgres"
_ "github.com/golang-migrate/migrate/v4/database/sqlite"
_ "github.com/golang-migrate/migrate/v4/source/file"
"github.com/pkg/errors"
)
type Migrate = migrate.Migrate
var (
ErrNilVersion = migrate.ErrNilVersion
ErrNoChange = migrate.ErrNoChange
)
func New(migrationDir, driver, dsn string) (*migrate.Migrate, error) {
migr, err := migrate.New(
fmt.Sprintf("file://%s/%s", migrationDir, driver),
dsn,
)
if err != nil {
return nil, errors.WithStack(err)
}
return migr, nil
}