Add a makefile to setup the env

This commit is contained in:
Grégoire Delattre 2016-05-25 18:56:19 +02:00
parent 7dd1eba942
commit 4afbd63b91
2 changed files with 45 additions and 26 deletions

30
Makefile Normal file
View File

@ -0,0 +1,30 @@
.PHONY: docker migration dev clean test
DB_USER=test
DB_PASS=test
DB_DATABASE=test
DB_DSN=postgres://$(DB_USER):$(DB_PASS)@127.0.0.1:5432/$(DB_DATABASE)?sslmode=disable
MIGRATION=migrate -url '$(DB_DSN)'
MIGRATION_SCHEMA=./sql
MIGRATION_TEST_DATA=./sqltest
DOCKER_COMPOSE_FILE=./docker/docker-compose.yml
DOCKER_COMPOSE=docker-compose -f $(DOCKER_COMPOSE_FILE)
docker:
$(DOCKER_COMPOSE) up -d
sleep 2
migration:
$(MIGRATION) -path $(MIGRATION_SCHEMA) up
$(MIGRATION) -path $(MIGRATION_TEST_DATA) up
dev: docker migration
clean:
$(DOCKER_COMPOSE) stop
$(DOCKER_COMPOSE) rm --force --all
test: docker
POSTGRES_DSN="$(DB_DSN)" go test -v -p=1 ./...

View File

@ -1,37 +1,26 @@
## Setup the dev env
Just run the docker-compose file to create the database.
```
docker-compose up -d
```
## Dev ## Dev
### Connect to the database ```
make dev
```
To setup the dev env.
## Connect to the database
``` ```
docker run -it --rm --link canape_postgresql_dev:postgres postgres:9.5 psql -h postgres -U test docker run -it --rm --link canape_postgresql_dev:postgres postgres:9.5 psql -h postgres -U test
``` ```
Then connect to the database you wanna check : ## Run the tests
```
\c dev
```
### Apply the migrations
```
migrate -url 'postgres://test:test@127.0.0.1:5432/dev?sslmode=disable' -path ./sql up
migrate -url 'postgres://test:test@127.0.0.1:5432/dev?sslmode=disable' -path ./sqltest up
```
### Run the tests
``` ```
POSTGRES_DSN="postgres://test:test@127.0.0.1:5432/test?sslmode=disable" go test -v -p=1 ./... make test
```
## To clean up
```
make clean
``` ```