Skip to content

Commit ee384ed

Browse files
committed
initial version 3.0.0 preview
hard work
1 parent e92f038 commit ee384ed

File tree

129 files changed

+5159
-4903
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+5159
-4903
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.DS_Store
2-
test.db
2+
cli/build
3+
cli/cli
4+
cli/migrate

.travis.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@ language: go
22
sudo: required
33

44
go:
5-
- 1.4
65
- 1.5
76
- 1.6
87
- 1.7
98

109
services:
1110
- docker
1211

13-
before_install:
14-
- curl -L https://github.com/docker/compose/releases/download/1.4.2/docker-compose-`uname -s`-`uname -m` > docker-compose
15-
- chmod +x docker-compose
16-
- sudo mv docker-compose /usr/local/bin
17-
- sed -i -e 's/golang/golang:'"$TRAVIS_GO_VERSION"'/' docker-compose.yml
18-
1912
script: make test
13+

Dockerfile

-3
This file was deleted.

LICENSE

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Matthias Kadenbach
3+
Copyright (c) 2016 Matthias Kadenbach
4+
5+
https://github.com/mattes/migrate
46

57
Permission is hereby granted, free of charge, to any person obtaining a copy
68
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1820
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1921
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2022
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
23+
THE SOFTWARE.

Makefile

+43-21
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
1-
TESTFLAGS?=
2-
IMAGE=mattes/migrate
3-
DCR=docker-compose run --rm
4-
GOTEST=go test $(TESTFLAGS) `go list ./... | grep -v "/vendor/"`
5-
6-
.PHONY: clean test build release docker-build docker-push run
7-
all: release
1+
SOURCE?=file go-bindata github
2+
DATABASE?=postgres
3+
VERSION?=$(shell git describe --tags 2>/dev/null)
4+
TEST_FLAGS?=
5+
6+
# define comma and space
7+
, := ,
8+
space :=
9+
space +=
10+
11+
build-cli: clean
12+
-mkdir ./cli/build
13+
cd ./cli && GOOS=linux GOARCH=amd64 go build -a -o build/migrate.$(VERSION).linux-amd64 -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' .
14+
cd ./cli && GOOS=darwin GOARCH=amd64 go build -a -o build/migrate.$(VERSION).darwin-amd64 -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' .
15+
cd ./cli && GOOS=windows GOARCH=amd64 go build -a -o build/migrate.$(VERSION).windows-amd64.exe -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' .
16+
cd ./cli/build && find . -name 'migrate*' | xargs -I{} tar czf {}.tar.gz {}
17+
cd ./cli/build && shasum -a 256 * > sha256sum.txt
18+
cat ./cli/build/sha256sum.txt
819

920
clean:
10-
rm -f migrate
21+
-rm -r ./cli/build
22+
23+
test-short:
24+
make test-with-flags --ignore-errors TEST_FLAGS='-short'
25+
26+
test:
27+
make test-with-flags TEST_FLAGS='-race -v -cover -bench=. -benchmem'
28+
29+
coverage:
30+
make test-with-flags TEST_FLAGS='-cover -short'
1131

12-
fmt:
13-
@gofmt -s -w `go list -f {{.Dir}} ./... | grep -v "/vendor/"`
32+
test-with-flags:
33+
@echo SOURCE: $(SOURCE)
34+
@echo DATABASE: $(DATABASE)
1435

15-
test: fmt
16-
$(DCR) go-test
36+
@go test $(TEST_FLAGS) .
37+
@go test $(TEST_FLAGS) ./cli/...
1738

18-
go-test: fmt
19-
@$(GOTEST)
39+
@go test $(TEST_FLAGS) ./source/{$(subst $(space),$(,),$(SOURCE)),}
40+
@go test $(TEST_FLAGS) ./source/testing
41+
@go test $(TEST_FLAGS) ./source/stub
2042

21-
build:
22-
$(DCR) go-build
43+
@go test $(TEST_FLAGS) ./database/{$(subst $(space),$(,),$(DATABASE)),}
44+
@go test $(TEST_FLAGS) ./database/testing
45+
@go test $(TEST_FLAGS) ./database/stub
46+
47+
# deprecated v1compat:
48+
@go test $(TEST_FLAGS) ./migrate/...
2349

24-
release: test build docker-build docker-push
2550

26-
docker-build:
27-
docker build --rm -t $(IMAGE) .
51+
.PHONY: build-cli clean test-short test coverage test-with-flags
2852

29-
docker-push:
30-
docker push $(IMAGE)

cli/build_github.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// +build github
2+
3+
package main
4+
5+
import (
6+
_ "github.com/mattes/migrate/source/github"
7+
)

cli/build_go-bindata.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// +build go-bindata
2+
3+
package main
4+
5+
import (
6+
_ "github.com/mattes/migrate/source/go-bindata"
7+
)

cli/build_postgres.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// +build postgres
2+
3+
package main
4+
5+
import (
6+
_ "github.com/mattes/migrate/database/postgres"
7+
)

cli/commands.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package main
2+
3+
import (
4+
"github.com/mattes/migrate"
5+
_ "github.com/mattes/migrate/database/stub" // TODO remove again
6+
_ "github.com/mattes/migrate/source/file"
7+
)
8+
9+
func gotoCmd(m *migrate.Migrate, v uint) {
10+
if err := m.Migrate(v); err != nil {
11+
log.fatalErr(err)
12+
}
13+
}
14+
15+
func upCmd(m *migrate.Migrate, limit int) {
16+
if limit >= 0 {
17+
if err := m.Steps(limit); err != nil {
18+
log.fatalErr(err)
19+
}
20+
} else {
21+
if err := m.Up(); err != nil {
22+
log.fatalErr(err)
23+
}
24+
}
25+
}
26+
27+
func downCmd(m *migrate.Migrate, limit int) {
28+
if limit >= 0 {
29+
if err := m.Steps(-limit); err != nil {
30+
log.fatalErr(err)
31+
}
32+
} else {
33+
if err := m.Down(); err != nil {
34+
log.fatalErr(err)
35+
}
36+
}
37+
}
38+
39+
func dropCmd(m *migrate.Migrate) {
40+
if err := m.Drop(); err != nil {
41+
log.fatalErr(err)
42+
}
43+
}
44+
45+
func versionCmd(m *migrate.Migrate) {
46+
v, err := m.Version()
47+
if err != nil {
48+
log.fatalErr(err)
49+
}
50+
log.Println(v)
51+
}

cli/log.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
logpkg "log"
6+
"os"
7+
)
8+
9+
type Log struct {
10+
verbose bool
11+
}
12+
13+
func (l *Log) Printf(format string, v ...interface{}) {
14+
if l.verbose {
15+
logpkg.Printf(format, v...)
16+
} else {
17+
fmt.Fprintf(os.Stderr, format, v...)
18+
}
19+
}
20+
21+
func (l *Log) Println(args ...interface{}) {
22+
if l.verbose {
23+
logpkg.Println(args...)
24+
} else {
25+
fmt.Fprintln(os.Stderr, args...)
26+
}
27+
}
28+
29+
func (l *Log) Verbose() bool {
30+
return l.verbose
31+
}
32+
33+
func (l *Log) fatalf(format string, v ...interface{}) {
34+
l.Printf(format, v...)
35+
os.Exit(1)
36+
}
37+
38+
func (l *Log) fatal(args ...interface{}) {
39+
l.Println(args...)
40+
os.Exit(1)
41+
}
42+
43+
func (l *Log) fatalErr(err error) {
44+
l.fatal("error:", err)
45+
}

0 commit comments

Comments
 (0)