mirror of https://github.com/pressly/goose.git
readme: update and clarify go migration example
parent
dd0239febf
commit
d5427607db
14
README.md
14
README.md
|
@ -96,22 +96,24 @@ Notice the annotations in the comments. Any statements following `-- +goose Up`
|
||||||
A sample Go migration looks like:
|
A sample Go migration looks like:
|
||||||
|
|
||||||
:::go
|
:::go
|
||||||
package migration_003
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Up(txn *sql.Tx) {
|
func Up_20130106222315(txn *sql.Tx) {
|
||||||
fmt.Println("Hello from migration_003 Up!")
|
fmt.Println("Hello from migration 20130106222315 Up!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func Down(txn *sql.Tx) {
|
func Down_20130106222315(txn *sql.Tx) {
|
||||||
fmt.Println("Hello from migration_003 Down!")
|
fmt.Println("Hello from migration 20130106222315 Down!")
|
||||||
}
|
}
|
||||||
|
|
||||||
`Up()` will be executed as part of a forward migration, and `Down()` will be executed as part of a rollback.
|
`Up_20130106222315()` will be executed as part of a forward migration, and `Down_20130106222315()` will be executed as part of a rollback.
|
||||||
|
|
||||||
|
The numeric portion of the function name (20130106222315) must be the leading portion of migration's filename, such as `20130106222315_descriptive_name.go`. `goose create` does this by default.
|
||||||
|
|
||||||
A transaction is provided, rather than the DB instance directly, since goose also needs to record the schema version within the same transaction. Each migration should run as a single transaction to ensure DB integrity, so it's good practice anyway.
|
A transaction is provided, rather than the DB instance directly, since goose also needs to record the schema version within the same transaction. Each migration should run as a single transaction to ensure DB integrity, so it's good practice anyway.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue