Fixed issues in README and documentation
This commit is contained in:
parent
358fed43ea
commit
adc0a5ad10
24
README.md
24
README.md
@ -1,8 +1,17 @@
|
|||||||
# Go database migrate
|
# Go database migrate
|
||||||
|
|
||||||
This is a simple database migration library for Go. This library is intended to be used with go-bindata.
|
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.
|
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
|
## Example
|
||||||
|
|
||||||
`files/0001.sql`:
|
`files/0001.sql`:
|
||||||
@ -16,7 +25,8 @@ INSERT INTO tests VALUES ('migration test');
|
|||||||
```
|
```
|
||||||
|
|
||||||
Run `go-bindata --prefix files files`
|
Run `go-bindata --prefix files files`
|
||||||
*Optionally add the flags `-nomemcopy` and `-nometadata`*
|
|
||||||
|
*Optionally you can add the flags `-nomemcopy` and `-nometadata`*
|
||||||
|
|
||||||
`main.go`:
|
`main.go`:
|
||||||
|
|
||||||
@ -24,17 +34,23 @@ Run `go-bindata --prefix files files`
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"migrate"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.fuyu.moe/Fuyu/migrate"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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 {
|
if err != nil {
|
||||||
fmt.Println(`Failed to connect to database. Message:`, err)
|
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 {
|
if err != nil {
|
||||||
fmt.Println(`The migration failed! Message:`, err)
|
fmt.Println(`The migration failed! Message:`, err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(`The database migration/update was successful`)
|
fmt.Println(`The database migration/update was successful`)
|
||||||
|
@ -29,7 +29,8 @@ const fileFormat = `%04d.sql`
|
|||||||
// AssetFunc is a function that returns the data for the given name
|
// AssetFunc is a function that returns the data for the given name
|
||||||
type AssetFunc func(string) ([]byte, error)
|
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 {
|
func Migrate(db *sql.DB, version int, o Options, asset AssetFunc) error {
|
||||||
if o.TableName == `` {
|
if o.TableName == `` {
|
||||||
o.TableName = DefaultTableName
|
o.TableName = DefaultTableName
|
||||||
|
Loading…
Reference in New Issue
Block a user