diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7c19b61 --- /dev/null +++ b/Makefile @@ -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 ./... diff --git a/README.md b/README.md index f33c4cf..0b9ea33 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,26 @@ -## Setup the dev env - -Just run the docker-compose file to create the database. - - -``` -docker-compose up -d -``` - ## 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 ``` -Then connect to the database you wanna check : - -``` -\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 +## 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 ```