Skip to content

Commit

Permalink
initial version 3.0.0 preview
Browse files Browse the repository at this point in the history
hard work
  • Loading branch information
mattes committed Feb 8, 2017
1 parent e92f038 commit ee384ed
Show file tree
Hide file tree
Showing 129 changed files with 5,159 additions and 4,903 deletions.
4 changes: 3 additions & 1 deletion .gitignore
@@ -1,2 +1,4 @@
.DS_Store
test.db
cli/build
cli/cli
cli/migrate
8 changes: 1 addition & 7 deletions .travis.yml
Expand Up @@ -2,18 +2,12 @@ language: go
sudo: required

go:
- 1.4
- 1.5
- 1.6
- 1.7

services:
- docker

before_install:
- curl -L https://github.com/docker/compose/releases/download/1.4.2/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
- sed -i -e 's/golang/golang:'"$TRAVIS_GO_VERSION"'/' docker-compose.yml

script: make test

3 changes: 0 additions & 3 deletions Dockerfile

This file was deleted.

6 changes: 4 additions & 2 deletions LICENSE
@@ -1,6 +1,8 @@
The MIT License (MIT)

Copyright (c) 2014 Matthias Kadenbach
Copyright (c) 2016 Matthias Kadenbach

https://github.com/mattes/migrate

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
64 changes: 43 additions & 21 deletions Makefile
@@ -1,30 +1,52 @@
TESTFLAGS?=
IMAGE=mattes/migrate
DCR=docker-compose run --rm
GOTEST=go test $(TESTFLAGS) `go list ./... | grep -v "/vendor/"`

.PHONY: clean test build release docker-build docker-push run
all: release
SOURCE?=file go-bindata github
DATABASE?=postgres
VERSION?=$(shell git describe --tags 2>/dev/null)
TEST_FLAGS?=

# define comma and space
, := ,
space :=
space +=

build-cli: clean
-mkdir ./cli/build
cd ./cli && GOOS=linux GOARCH=amd64 go build -a -o build/migrate.$(VERSION).linux-amd64 -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' .
cd ./cli && GOOS=darwin GOARCH=amd64 go build -a -o build/migrate.$(VERSION).darwin-amd64 -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' .
cd ./cli && GOOS=windows GOARCH=amd64 go build -a -o build/migrate.$(VERSION).windows-amd64.exe -ldflags="-X main.Version=$(VERSION)" -tags '$(DATABASE) $(SOURCE)' .
cd ./cli/build && find . -name 'migrate*' | xargs -I{} tar czf {}.tar.gz {}
cd ./cli/build && shasum -a 256 * > sha256sum.txt
cat ./cli/build/sha256sum.txt

clean:
rm -f migrate
-rm -r ./cli/build

test-short:
make test-with-flags --ignore-errors TEST_FLAGS='-short'

test:
make test-with-flags TEST_FLAGS='-race -v -cover -bench=. -benchmem'

coverage:
make test-with-flags TEST_FLAGS='-cover -short'

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

test: fmt
$(DCR) go-test
@go test $(TEST_FLAGS) .
@go test $(TEST_FLAGS) ./cli/...

go-test: fmt
@$(GOTEST)
@go test $(TEST_FLAGS) ./source/{$(subst $(space),$(,),$(SOURCE)),}
@go test $(TEST_FLAGS) ./source/testing
@go test $(TEST_FLAGS) ./source/stub

build:
$(DCR) go-build
@go test $(TEST_FLAGS) ./database/{$(subst $(space),$(,),$(DATABASE)),}
@go test $(TEST_FLAGS) ./database/testing
@go test $(TEST_FLAGS) ./database/stub

# deprecated v1compat:
@go test $(TEST_FLAGS) ./migrate/...

release: test build docker-build docker-push

docker-build:
docker build --rm -t $(IMAGE) .
.PHONY: build-cli clean test-short test coverage test-with-flags

docker-push:
docker push $(IMAGE)
7 changes: 7 additions & 0 deletions cli/build_github.go
@@ -0,0 +1,7 @@
// +build github

package main

import (
_ "github.com/mattes/migrate/source/github"
)
7 changes: 7 additions & 0 deletions cli/build_go-bindata.go
@@ -0,0 +1,7 @@
// +build go-bindata

package main

import (
_ "github.com/mattes/migrate/source/go-bindata"
)
7 changes: 7 additions & 0 deletions cli/build_postgres.go
@@ -0,0 +1,7 @@
// +build postgres

package main

import (
_ "github.com/mattes/migrate/database/postgres"
)
51 changes: 51 additions & 0 deletions cli/commands.go
@@ -0,0 +1,51 @@
package main

import (
"github.com/mattes/migrate"
_ "github.com/mattes/migrate/database/stub" // TODO remove again
_ "github.com/mattes/migrate/source/file"
)

func gotoCmd(m *migrate.Migrate, v uint) {
if err := m.Migrate(v); err != nil {
log.fatalErr(err)
}
}

func upCmd(m *migrate.Migrate, limit int) {
if limit >= 0 {
if err := m.Steps(limit); err != nil {
log.fatalErr(err)
}
} else {
if err := m.Up(); err != nil {
log.fatalErr(err)
}
}
}

func downCmd(m *migrate.Migrate, limit int) {
if limit >= 0 {
if err := m.Steps(-limit); err != nil {
log.fatalErr(err)
}
} else {
if err := m.Down(); err != nil {
log.fatalErr(err)
}
}
}

func dropCmd(m *migrate.Migrate) {
if err := m.Drop(); err != nil {
log.fatalErr(err)
}
}

func versionCmd(m *migrate.Migrate) {
v, err := m.Version()
if err != nil {
log.fatalErr(err)
}
log.Println(v)
}
45 changes: 45 additions & 0 deletions cli/log.go
@@ -0,0 +1,45 @@
package main

import (
"fmt"
logpkg "log"
"os"
)

type Log struct {
verbose bool
}

func (l *Log) Printf(format string, v ...interface{}) {
if l.verbose {
logpkg.Printf(format, v...)
} else {
fmt.Fprintf(os.Stderr, format, v...)
}
}

func (l *Log) Println(args ...interface{}) {
if l.verbose {
logpkg.Println(args...)
} else {
fmt.Fprintln(os.Stderr, args...)
}
}

func (l *Log) Verbose() bool {
return l.verbose
}

func (l *Log) fatalf(format string, v ...interface{}) {
l.Printf(format, v...)
os.Exit(1)
}

func (l *Log) fatal(args ...interface{}) {
l.Println(args...)
os.Exit(1)
}

func (l *Log) fatalErr(err error) {
l.fatal("error:", err)
}

0 comments on commit ee384ed

Please sign in to comment.