Browse Source

Fixed issues in README and documentation

pull/1/head
Nise Void 5 years ago
parent
commit
adc0a5ad10
2 changed files with 22 additions and 5 deletions
  1. +20
    -4
      README.md
  2. +2
    -1
      migrate.go

+ 20
- 4
README.md View File

@ -1,8 +1,17 @@
# Go database migrate
This is a simple database migration library for Go. This library is intended to be used with go-bindata.
We recommended using a go generate command to update the go-bindata file.
## Installation
You can install this library with go get
```
go get git.fuyu.moe/Fuyu/migrate
```
## Example
`files/0001.sql`:
@ -16,7 +25,8 @@ INSERT INTO tests VALUES ('migration test');
```
Run `go-bindata --prefix files files`
*Optionally add the flags `-nomemcopy` and `-nometadata`*
*Optionally you can add the flags `-nomemcopy` and `-nometadata`*
`main.go`:
@ -24,17 +34,23 @@ Run `go-bindata --prefix files files`
package main
import (
"migrate"
"database/sql"
"fmt"
"git.fuyu.moe/Fuyu/migrate"
_ "github.com/lib/pq"
)
func main() {
db, err = sql.Open(`postgres`, `host=/run/postgresql dbname=testdb sslmode=disable`)
db, err := sql.Open(`postgres`, `host=/run/postgresql dbname=testdb sslmode=disable`)
if err != nil {
fmt.Println(`Failed to connect to database. Message:`, err)
return
}
err = migrate.Migrate(db, 1, migrate.Options{Schema:`testschema`}, migrations.Asset}
err = migrate.Migrate(db, 1, migrate.Options{Schema: `testschema`}, Asset)
if err != nil {
fmt.Println(`The migration failed! Message:`, err)
return
}
fmt.Println(`The database migration/update was successful`)


+ 2
- 1
migrate.go View File

@ -29,7 +29,8 @@ const fileFormat = `%04d.sql`
// AssetFunc is a function that returns the data for the given name
type AssetFunc func(string) ([]byte, error)
// Migrate executes
// Migrate executes migrations to get to the desired version
// Downgrading is not supported as it could result in data loss
func Migrate(db *sql.DB, version int, o Options, asset AssetFunc) error {
if o.TableName == `` {
o.TableName = DefaultTableName


Loading…
Cancel
Save