mirror of
https://github.com/pressly/goose.git
synced 2025-05-31 11:42:04 +00:00
Merge pull request #123 from pressly/goose-lite
support build tags to exclude drivers
This commit is contained in:
commit
da4711c369
5
.gitignore
vendored
5
.gitignore
vendored
@ -4,7 +4,8 @@ cmd/goose/goose*
|
|||||||
*.test
|
*.test
|
||||||
|
|
||||||
# Files output by tests
|
# Files output by tests
|
||||||
custom-goose
|
bin
|
||||||
go.db
|
go.db
|
||||||
goose
|
|
||||||
sql.db
|
sql.db
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,6 +30,11 @@ Goose is a database migration tool. Manage your database schema by creating incr
|
|||||||
|
|
||||||
This will install the `goose` binary to your `$GOPATH/bin` directory.
|
This will install the `goose` binary to your `$GOPATH/bin` directory.
|
||||||
|
|
||||||
|
For a lite version of the binary without DB connection dependent commands, use the exclusive build tags:
|
||||||
|
|
||||||
|
$ go build -tags='no_mysql no_sqlite no_psql' -i -o goose ./cmd/goose
|
||||||
|
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
|
8
cmd/goose/driver_mysql.go
Normal file
8
cmd/goose/driver_mysql.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// +build !no_mysql
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/ziutek/mymysql/godrv"
|
||||||
|
)
|
7
cmd/goose/driver_psql.go
Normal file
7
cmd/goose/driver_psql.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// +build !no_pq
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
)
|
7
cmd/goose/driver_sqlite.go
Normal file
7
cmd/goose/driver_sqlite.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// +build !no_sqlite
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
)
|
@ -7,12 +7,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/pressly/goose"
|
"github.com/pressly/goose"
|
||||||
|
|
||||||
// Init DB drivers.
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
|
||||||
_ "github.com/lib/pq"
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
|
||||||
_ "github.com/ziutek/mymysql/godrv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
18
fix_test.go
18
fix_test.go
@ -20,12 +20,12 @@ func TestFix(t *testing.T) {
|
|||||||
defer os.Remove("goose") // clean up
|
defer os.Remove("goose") // clean up
|
||||||
|
|
||||||
commands := []string{
|
commands := []string{
|
||||||
"go build -i -o goose ./cmd/goose",
|
"go build -i -o ./bin/goose ./cmd/goose",
|
||||||
fmt.Sprintf("./goose -dir=%s create create_table", dir),
|
fmt.Sprintf("./bin/goose -dir=%s create create_table", dir),
|
||||||
fmt.Sprintf("./goose -dir=%s create add_users", dir),
|
fmt.Sprintf("./bin/goose -dir=%s create add_users", dir),
|
||||||
fmt.Sprintf("./goose -dir=%s create add_indices", dir),
|
fmt.Sprintf("./bin/goose -dir=%s create add_indices", dir),
|
||||||
fmt.Sprintf("./goose -dir=%s create update_users", dir),
|
fmt.Sprintf("./bin/goose -dir=%s create update_users", dir),
|
||||||
fmt.Sprintf("./goose -dir=%s fix", dir),
|
fmt.Sprintf("./bin/goose -dir=%s fix", dir),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cmd := range commands {
|
for _, cmd := range commands {
|
||||||
@ -52,9 +52,9 @@ func TestFix(t *testing.T) {
|
|||||||
|
|
||||||
// add more migrations and then fix it
|
// add more migrations and then fix it
|
||||||
commands = []string{
|
commands = []string{
|
||||||
fmt.Sprintf("./goose -dir=%s create remove_column", dir),
|
fmt.Sprintf("./bin/goose -dir=%s create remove_column", dir),
|
||||||
fmt.Sprintf("./goose -dir=%s create create_books_table", dir),
|
fmt.Sprintf("./bin/goose -dir=%s create create_books_table", dir),
|
||||||
fmt.Sprintf("./goose -dir=%s fix", dir),
|
fmt.Sprintf("./bin/goose -dir=%s fix", dir),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cmd := range commands {
|
for _, cmd := range commands {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package goose
|
package goose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -8,11 +11,42 @@ import (
|
|||||||
|
|
||||||
func TestDefaultBinary(t *testing.T) {
|
func TestDefaultBinary(t *testing.T) {
|
||||||
commands := []string{
|
commands := []string{
|
||||||
"go build -i -o goose ./cmd/goose",
|
"go build -i -o ./bin/goose ./cmd/goose",
|
||||||
"./goose -dir=examples/sql-migrations sqlite3 sql.db up",
|
"./bin/goose -dir=examples/sql-migrations sqlite3 sql.db up",
|
||||||
"./goose -dir=examples/sql-migrations sqlite3 sql.db version",
|
"./bin/goose -dir=examples/sql-migrations sqlite3 sql.db version",
|
||||||
"./goose -dir=examples/sql-migrations sqlite3 sql.db down",
|
"./bin/goose -dir=examples/sql-migrations sqlite3 sql.db down",
|
||||||
"./goose -dir=examples/sql-migrations sqlite3 sql.db status",
|
"./bin/goose -dir=examples/sql-migrations sqlite3 sql.db status",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, cmd := range commands {
|
||||||
|
args := strings.Split(cmd, " ")
|
||||||
|
out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s:\n%v\n\n%s", err, cmd, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLiteBinary(t *testing.T) {
|
||||||
|
dir, err := ioutil.TempDir("", "tmptest")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer os.RemoveAll(dir) // clean up
|
||||||
|
defer os.Remove("./bin/goose") // clean up
|
||||||
|
|
||||||
|
commands := []string{
|
||||||
|
fmt.Sprintf("./bin/goose -dir=%s create user_indices sql", dir),
|
||||||
|
fmt.Sprintf("./bin/goose -dir=%s fix", dir),
|
||||||
|
}
|
||||||
|
|
||||||
|
// this has to be done outside of the loop
|
||||||
|
// since go only supports space separated tags list.
|
||||||
|
cmd := "go build -tags='no_mysql no_sqlite no_psql' -i -o ./bin/goose ./cmd/goose"
|
||||||
|
out, err := exec.Command("go", "build", "-tags='no_mysql no_sqlite no_psql'", "-i", "-o", "./bin/goose", "./cmd/goose").CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("%s:\n%v\n\n%s", err, cmd, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cmd := range commands {
|
for _, cmd := range commands {
|
||||||
@ -26,11 +60,11 @@ func TestDefaultBinary(t *testing.T) {
|
|||||||
|
|
||||||
func TestCustomBinary(t *testing.T) {
|
func TestCustomBinary(t *testing.T) {
|
||||||
commands := []string{
|
commands := []string{
|
||||||
"go build -i -o custom-goose ./examples/go-migrations",
|
"go build -i -o ./bin/custom-goose ./examples/go-migrations",
|
||||||
"./custom-goose -dir=examples/go-migrations sqlite3 go.db up",
|
"./bin/custom-goose -dir=examples/go-migrations sqlite3 go.db up",
|
||||||
"./custom-goose -dir=examples/go-migrations sqlite3 go.db version",
|
"./bin/custom-goose -dir=examples/go-migrations sqlite3 go.db version",
|
||||||
"./custom-goose -dir=examples/go-migrations sqlite3 go.db down",
|
"./bin/custom-goose -dir=examples/go-migrations sqlite3 go.db down",
|
||||||
"./custom-goose -dir=examples/go-migrations sqlite3 go.db status",
|
"./bin/custom-goose -dir=examples/go-migrations sqlite3 go.db status",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cmd := range commands {
|
for _, cmd := range commands {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user