emissary/internal/migrate/migrate.go

34 lines
677 B
Go
Raw Normal View History

2023-02-02 10:55:24 +01:00
package migrate
import (
"fmt"
"log"
"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,
)
log.Println(migrationDir, driver, dsn)
if err != nil {
return nil, errors.WithStack(err)
}
return migr, nil
}