Initial commit
This commit is contained in:
commit
358fed43ea
4 changed files with 177 additions and 0 deletions
55
README.md
Normal file
55
README.md
Normal file
|
@ -0,0 +1,55 @@
|
|||
# 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.
|
||||
|
||||
## Example
|
||||
|
||||
`files/0001.sql`:
|
||||
|
||||
```sql
|
||||
CREATE TABLE tests (
|
||||
Name varchar(100) NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO tests VALUES ('migration test');
|
||||
```
|
||||
|
||||
Run `go-bindata --prefix files files`
|
||||
*Optionally add the flags `-nomemcopy` and `-nometadata`*
|
||||
|
||||
`main.go`:
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"migrate"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db, err = sql.Open(`postgres`, `host=/run/postgresql dbname=testdb sslmode=disable`)
|
||||
if err != nil {
|
||||
fmt.Println(`Failed to connect to database. Message:`, err)
|
||||
}
|
||||
err = migrate.Migrate(db, 1, migrate.Options{Schema:`testschema`}, migrations.Asset}
|
||||
if err != nil {
|
||||
fmt.Println(`The migration failed! Message:`, err)
|
||||
}
|
||||
|
||||
fmt.Println(`The database migration/update was successful`)
|
||||
}
|
||||
```
|
||||
|
||||
## File names:
|
||||
|
||||
The names of your migration files should look like this:
|
||||
|
||||
```
|
||||
0001.sql
|
||||
0002.sql
|
||||
...
|
||||
0010.sql
|
||||
...
|
||||
0325.sql
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue