-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
167 lines (143 loc) · 4.45 KB
/
Makefile
File metadata and controls
167 lines (143 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
BIN = $(GOPATH)/bin
BASE = $(GOPATH)/src/$(PACKAGE)
PKGS = go list ./... | grep -v "^vendor/"
# Tools
## Testing library
GINKGO = $(BIN)/ginkgo
$(BIN)/ginkgo:
go get -u github.com/onsi/ginkgo/ginkgo
## Migration tool
GOOSE = go run -tags='no_mysql no_sqlite3 no_mssql no_redshift' github.com/pressly/goose/cmd/goose
## Source linter
LINT = $(BIN)/golint
$(BIN)/golint:
go get -u golang.org/x/lint/golint
.PHONY: installtools
installtools: | $(LINT) $(GINKGO)
echo "Installing tools"
#Test
TEST_DB = vulcanize_testing
TEST_CONNECT_STRING = postgresql://localhost:5432/$(TEST_DB)?sslmode=disable
.PHONY: test
test: | $(GINKGO) $(LINT)
go vet ./...
go fmt ./...
dropdb --if-exists $(TEST_DB)
createdb $(TEST_DB)
psql -q $(TEST_DB) < test_data/vulcanize_schema.sql
make migrate NAME=$(TEST_DB)
make reset NAME=$(TEST_DB)
make migrate NAME=$(TEST_DB)
$(GINKGO) -r --skipPackage=integration_tests,integration
.PHONY: integrationtest
integrationtest: | $(GINKGO) $(LINT)
go vet ./...
go fmt ./...
dropdb --if-exists $(TEST_DB)
createdb $(TEST_DB)
psql -q $(TEST_DB) < test_data/vulcanize_schema.sql
make migrate NAME=$(TEST_DB)
make reset NAME=$(TEST_DB)
make migrate NAME=$(TEST_DB)
$(GINKGO) -r transformers/integration_tests/
vdb-oasis-transformers:
go build
# Build is really "clean/rebuild"
.PHONY: build
build:
- rm vdb-oasis-transformers
go fmt ./...
go build
#Database
HOST_NAME = localhost
PORT = 5432
NAME =
CONNECT_STRING=postgresql://$(HOST_NAME):$(PORT)/$(NAME)?sslmode=disable
# Parameter checks
## Check that DB variables are provided
.PHONY: checkdbvars
checkdbvars:
test -n "$(HOST_NAME)" # $$HOST_NAME
test -n "$(PORT)" # $$PORT
test -n "$(NAME)" # $$NAME
@echo $(CONNECT_STRING)
## Check that the migration variable (id/timestamp) is provided
.PHONY: checkmigration
checkmigration:
test -n "$(MIGRATION)" # $$MIGRATION
## Check that the migration name is provided
.PHONY: checkmigname
checkmigname:
test -n "$(NAME)" # $$NAME
# Migration operations
## Rollback the last migration
.PHONY: rollback
rollback: checkdbvars
cd db/migrations;\
$(GOOSE) -table "oasis.goose_db_version" postgres "$(CONNECT_STRING)" down
pg_dump -n 'oasis' -n -s $(CONNECT_STRING) > db/schema.sql
## Rollback to a select migration (id/timestamp)
.PHONY: rollback_to
rollback_to: checkmigration checkdbvars
cd db/migrations;\
$(GOOSE) -table "oasis.goose_db_version" postgres "$(CONNECT_STRING)" down-to "$(MIGRATION)"
## Apply all migrations not already run
.PHONY: migrate
migrate: checkdbvars
psql $(NAME) -c 'CREATE SCHEMA IF NOT EXISTS oasis;'
cd db/migrations;\
$(GOOSE) -table "oasis.goose_db_version" postgres "$(CONNECT_STRING)" up
pg_dump -n 'oasis' -O -s $(CONNECT_STRING) > db/schema.sql
.PHONY: reset
reset: checkdbvars
cd db/migrations/;\
$(GOOSE) -table "oasis.goose_db_version" postgres "$(CONNECT_STRING)" reset
pg_dump -n 'oasis' -O -s $(CONNECT_STRING) > db/schema.sql
psql $(NAME) -c 'DROP SCHEMA oasis CASCADE;'
## Create a new migration file
.PHONY: new_migration
new_migration: checkmigname
cd db/migrations;\
$(GOOSE) create $(NAME) sql
## Check which migrations are applied at the moment
.PHONY: migration_status
migration_status: checkdbvars
cd db/migrations;\
$(GOOSE) -table oasis.goose_db_version postgres "$(CONNECT_STRING)" status
# Import a psql schema to the database
.PHONY: import
import:
test -n "$(NAME)" # $$NAME
psql $(NAME) < db/schema.sql
# Update vulcanizedb version
.PHONY: update_vulcanize
update_vulcanize:
test -n "$(BRANCH)" # $$BRANCH
go get github.com/makerdao/vulcanizedb@$(BRANCH)
wget https://raw.githubusercontent.com/makerdao/vulcanizedb/$(BRANCH)/db/schema.sql --output-document=test_data/vulcanize_schema.sql
# Build plugin
.PHONY: plugin
plugin:
go build -buildmode=plugin -o $(OUTPUT_LOCATION) $(TARGET_LOCATION)
# Docker actions
# Build any docker image in dockerfiles
.PHONY: dockerbuild
dockerbuild:
test -n "$(IMAGE)" # $$IMAGE
docker build --no-cache -t vdb-oasis-$(IMAGE) -f dockerfiles/$(IMAGE)/Dockerfile .
.PHONY: execute
execute: HOST ?= host.docker.internal
execute: DATABASE_PASSWORD ?= postgres
execute:
test -n "$(NAME)" # $$(NAME) - Database Name
test -n "$(CLIENT_IPCPATH)" # $$(CLIENT_IPCPATH) - Node path
docker run \
-it \
-p "$(PORT):$(PORT)" \
-e "DATABASE_NAME=$(NAME)" \
-e "DATABASE_HOSTNAME=$(HOST)" \
-e "DATABASE_PORT=$(PORT)" \
-e "DATABASE_USER=$(USER)" \
-e "DATABASE_PASSWORD=$(DATABASE_PASSWORD)" \
-e "CLIENT_IPCPATH=$(CLIENT_IPCPATH)" \
vdb-oasis-execute:latest