Merged in rubenv/goose/readme-codeblocks (pull request #41)

Fix non-standard code blocks.
pull/2/head
Liam Staskawicz 2014-09-08 10:14:02 -07:00
commit a72c5a598e
1 changed files with 73 additions and 62 deletions

View File

@ -103,7 +103,7 @@ goose supports migrations written in SQL or in Go - see the `goose create` comma
A sample SQL migration looks like: A sample SQL migration looks like:
:::sql ```sql
-- +goose Up -- +goose Up
CREATE TABLE post ( CREATE TABLE post (
id int NOT NULL, id int NOT NULL,
@ -114,6 +114,7 @@ A sample SQL migration looks like:
-- +goose Down -- +goose Down
DROP TABLE post; DROP TABLE post;
```
Notice the annotations in the comments. Any statements following `-- +goose Up` will be executed as part of a forward migration, and any statements following `-- +goose Down` will be executed as part of a rollback. Notice the annotations in the comments. Any statements following `-- +goose Up` will be executed as part of a forward migration, and any statements following `-- +goose Down` will be executed as part of a rollback.
@ -121,7 +122,7 @@ By default, SQL statements are delimited by semicolons - in fact, query statemen
More complex statements (PL/pgSQL) that have semicolons within them must be annotated with `-- +goose StatementBegin` and `-- +goose StatementEnd` to be properly recognized. For example: More complex statements (PL/pgSQL) that have semicolons within them must be annotated with `-- +goose StatementBegin` and `-- +goose StatementEnd` to be properly recognized. For example:
:::sql ```sql
-- +goose Up -- +goose Up
-- +goose StatementBegin -- +goose StatementBegin
CREATE OR REPLACE FUNCTION histories_partition_creation( DATE, DATE ) CREATE OR REPLACE FUNCTION histories_partition_creation( DATE, DATE )
@ -145,12 +146,13 @@ More complex statements (PL/pgSQL) that have semicolons within them must be anno
$$ $$
language plpgsql; language plpgsql;
-- +goose StatementEnd -- +goose StatementEnd
```
## Go Migrations ## Go Migrations
A sample Go migration looks like: A sample Go migration looks like:
:::go ```go
package main package main
import ( import (
@ -165,6 +167,7 @@ A sample Go migration looks like:
func Down_20130106222315(txn *sql.Tx) { func Down_20130106222315(txn *sql.Tx) {
fmt.Println("Hello from migration 20130106222315 Down!") fmt.Println("Hello from migration 20130106222315 Down!")
} }
```
`Up_20130106222315()` will be executed as part of a forward migration, and `Down_20130106222315()` 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.
@ -184,9 +187,11 @@ You may use the `-path` option to specify an alternate location for the folder c
A sample `dbconf.yml` looks like A sample `dbconf.yml` looks like
```yml
development: development:
driver: postgres driver: postgres
open: user=liam dbname=tester sslmode=disable open: user=liam dbname=tester sslmode=disable
```
Here, `development` specifies the name of the environment, and the `driver` and `open` elements are passed directly to database/sql to access the specified database. Here, `development` specifies the name of the environment, and the `driver` and `open` elements are passed directly to database/sql to access the specified database.
@ -201,11 +206,13 @@ Currently, available dialects are: "postgres", "mysql", or "sqlite3"
To run Go-based migrations with another driver, specify its import path and dialect, as shown below. To run Go-based migrations with another driver, specify its import path and dialect, as shown below.
```yml
customdriver: customdriver:
driver: custom driver: custom
open: custom open string open: custom open string
import: github.com/custom/driver import: github.com/custom/driver
dialect: mysql dialect: mysql
```
NOTE: Because migrations written in SQL are executed directly by the goose binary, only drivers compiled into goose may be used for these migrations. NOTE: Because migrations written in SQL are executed directly by the goose binary, only drivers compiled into goose may be used for these migrations.
@ -213,6 +220,7 @@ NOTE: Because migrations written in SQL are executed directly by the goose binar
These instructions assume that you're using [Keith Rarick's Heroku Go buildpack](https://github.com/kr/heroku-buildpack-go). First, add a file to your project called (e.g.) `install_goose.go` to trigger building of the goose executable during deployment, with these contents: These instructions assume that you're using [Keith Rarick's Heroku Go buildpack](https://github.com/kr/heroku-buildpack-go). First, add a file to your project called (e.g.) `install_goose.go` to trigger building of the goose executable during deployment, with these contents:
```go
// use build constraints to work around http://code.google.com/p/go/issues/detail?id=4210 // use build constraints to work around http://code.google.com/p/go/issues/detail?id=4210
// +build heroku // +build heroku
@ -220,14 +228,17 @@ These instructions assume that you're using [Keith Rarick's Heroku Go buildpack]
package main package main
import _ "bitbucket.org/liamstask/goose/cmd/goose" import _ "bitbucket.org/liamstask/goose/cmd/goose"
```
[Set up your Heroku database(s) as usual.](https://devcenter.heroku.com/articles/heroku-postgresql) [Set up your Heroku database(s) as usual.](https://devcenter.heroku.com/articles/heroku-postgresql)
Then make use of environment variable expansion in your `dbconf.yml`: Then make use of environment variable expansion in your `dbconf.yml`:
```yml
production: production:
driver: postgres driver: postgres
open: $DATABASE_URL open: $DATABASE_URL
```
To run goose in production, use `heroku run`: To run goose in production, use `heroku run`: