migrate
migrate copied to clipboard
missing transient dependency?
These two functions are run in seq, DB wraps sql.DB. The result is the following output
INFO[0000] Connecting to postgres://postgres:postgres@localhost:7883/myservice?sslmode=disable
INFO[0000] Connection SUCCESS
INFO[0000] Migrating &{0x151c098 postgres://postgres:postgres@localhost:7883/myservice?sslmode=disable 0 {0 0} [] map[] 0 0 0xc420078420 false map[] map[] 0 0 0 <nil>}
INFO[0000] Got DB driver.
panic: source driver: unknown driver file (forgotten import?)
import (
"os"
"strconv"
"database/sql"
_ "github.com/lib/pq"
_ "github.com/lib/pq/oid"
"github.com/mattes/migrate"
_ "github.com/mattes/migrate/source/github"
"github.com/mattes/migrate/database/postgres"
log "github.com/Sirupsen/logrus"
)
func (db *DB) Connect() error {
url := getEnv("PG_HC_PERIODIC_ELECTION_0_1_URL", "postgres://postgres:postgres@localhost:7883/myservice?sslmode=disable")
log.Info("Connecting to ", url)
conn, err := sql.Open("postgres", url)
if err != nil {
return err
}
log.Info("Connection SUCCESS")
db.conn = conn
return nil
}
func (db *DB) Migrate() error {
log.Info("Migrating ", db.conn)
driver, err := postgres.WithInstance(db.conn, &postgres.Config{})
if err != nil {
return err
}
log.Info("Got DB driver.")
m, err := migrate.NewWithDatabaseInstance("file://db/migrations", "postgres", driver)
if err != nil {
return err // missing driver error here.
}
log.Info("Opened Migration Store.")
version, dirty, err := m.Version()
if err != nil {
return err
}
log.Info("Migrating: Current schema version ", strconv.FormatInt(int64(version), 10), " dirty: ", strconv.FormatBool(dirty))
err = m.Up()
if err != nil {
return err
}
log.Info("Migration SUCCESS")
return nil
}
Solved, needed import
_ "github.com/mattes/migrate/source/file"
The documentation in the main readme reads:
Migration Sources
Source drivers read migrations from local or remote sources. Add a new source?
Filesystem - read from fileystem (always included)
Maybe before closing this you should fix the documentation that caused it in the first place....
Sorry, I didn't see the action item here. Would you mind opening a PR?
@mattes import helped me as well.