You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 28, 2018. It is now read-only.
package db1
import (
"database/sql"
"log"
"os"
_ "github.com/lib/pq"
"github.com/mattes/migrate"
"github.com/mattes/migrate/database/postgres"
_ "github.com/mattes/migrate/source/file"
)
var Db *sql.DB
func Connect() {
var error error
Db1ConnectString := os.Getenv("DB1_CONNECT_STRING")
if Db1ConnectString == "" {
log.Fatal("$DB1_CONNECT_STRING must be set")
}
Db, error = sql.Open("postgres", Db1ConnectString)
if error != nil {
log.Fatal(error)
}
error = Db.Ping()
if error != nil {
log.Fatal(error)
}
log.Println("DB1 Ready to Rock 🤘")
driver, err := postgres.WithInstance(Db, &postgres.Config{})
if err != nil {
log.Fatal(error)
}
log.Print(driver)
m, err := migrate.NewWithDatabaseInstance(
"file:///Users/transistor/Documents/Go/src/asc-api-go/db1/migrations",
"myDB",
driver)
if err != nil {
log.Fatal(error)
}
err = m.Up()
if err != nil {
log.Fatal(err)
}
}
I also read that there might be a "confilct" while using vendoring (I'm using Godep), and I do in fact have two pq libraries, but I don't know if this is a problem and therefore no idea how to solve it:
I was having this problem, and like other assorted comments mention, it has to do with loading lib/pg twice. The way I fixed it was moving the migrate in to my vendor directory and out of $GOPATH/src/github.com/.... It worked after that. The moral of that story is that if you use vendor, everything should be there, don't use it, but some packages get confused when loaded in both places.
I've seen this question asked before, but I could not find a solution.
My code before the migration works just fine (DB Ready to Rock), but when i add the
migrate
packages and code it doesn't.The error:
This is my db file:
I also read that there might be a "confilct" while using vendoring (I'm using Godep), and I do in fact have two
pq
libraries, but I don't know if this is a problem and therefore no idea how to solve it:/Users/transistor/Documents/Go/src/asc-api-go/vendor/github.com/lib/pq
/Users/transistor/Documents/Go/src/github.com/lib/pq
Can you help?
Thank you.
The text was updated successfully, but these errors were encountered: