This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
forked from ninthclowd/migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hard work
- Loading branch information
Showing
129 changed files
with
5,159 additions
and
4,903 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.DS_Store | ||
test.db | ||
cli/build | ||
cli/cli | ||
cli/migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build github | ||
|
||
package main | ||
|
||
import ( | ||
_ "github.com/mattes/migrate/source/github" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build go-bindata | ||
|
||
package main | ||
|
||
import ( | ||
_ "github.com/mattes/migrate/source/go-bindata" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build postgres | ||
|
||
package main | ||
|
||
import ( | ||
_ "github.com/mattes/migrate/database/postgres" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
Oops, something went wrong.