add NewWithDatabaseInstance example

This commit is contained in:
Matthias Kadenbach 2017-02-14 23:25:19 -08:00
parent 3feee5958a
commit 53630f5ff1
No known key found for this signature in database
GPG Key ID: DC1F4DC6D31A7031
1 changed files with 20 additions and 0 deletions

View File

@ -85,6 +85,26 @@ func main() {
}
```
Want to use an existing database client?
```go
import (
"database/sql"
_ "github.com/lib/pq"
"github.com/mattes/migrate/migrate"
"github.com/mattes/migrate/database/postgres"
)
func main() {
db, err := sql.Open("postgres", "postgres://localhost:5432/database?sslmode=enable")
driver, err := postgres.WithInstance(db, &postgres.Config{})
m, err := migrate.NewWithDatabaseInstance(
"file:///migrations",
"postgres", driver)
m.Steps(2)
}
```
## Migration files
Each migration has an up and down migration. [Why?](FAQ.md#why-two-separate-files-up-and-down-for-a-migration)