34 lines
677 B
Go
34 lines
677 B
Go
|
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
|
||
|
}
|