Update Readme to include migrations

This commit is contained in:
Amarpreet Minhas 2020-01-18 14:58:55 -05:00
parent 6656d8b474
commit 8d29d8a744

View file

@ -36,7 +36,15 @@ Install steps are for Debian 9 (stretch)
export GOPATH=${HOME}/go export GOPATH=${HOME}/go
``` ```
3. Clone repo and configure the settings 3. Install migrate
```
# this assumes you have ${GOPATH}/bin in your ${PATH}
go get -u -d github.com/mattes/migrate/cli github.com/lib/pq
go build -tags 'postgres' -o ${GOPATH}/bin/migrate github.com/mattes/migrate/cli
```
4. Clone repo and configure the settings
``` ```
mkdir -p ${GOPATH}/src/git.minhas.io/asara mkdir -p ${GOPATH}/src/git.minhas.io/asara
cd ${GOPATH}/src/git.minhas.io/asara cd ${GOPATH}/src/git.minhas.io/asara
@ -45,7 +53,7 @@ Install steps are for Debian 9 (stretch)
# make sure the extension is .env (db.env, secrets.env, website.env... etc.) # make sure the extension is .env (db.env, secrets.env, website.env... etc.)
``` ```
4. Configure docker postgres for testing 5. Configure docker postgres for testing
``` ```
# make sure your user is in the docker group # make sure your user is in the docker group
sudo usermod -aG docker $(whoami) sudo usermod -aG docker $(whoami)
@ -61,14 +69,17 @@ Install steps are for Debian 9 (stretch)
CREATE DATABASE ${DB_NAME}; CREATE DATABASE ${DB_NAME};
CREATE USER ${DB_USER} WITH ENCRYPTED PASSWORD '${DB_PW}'; CREATE USER ${DB_USER} WITH ENCRYPTED PASSWORD '${DB_PW}';
GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_USER}; GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_USER};
ALTER DATABASE ${DB_NAME} OWNER TO ${DB_USER};
EOF EOF
``` ```
5. Run the application! 6. Run the application!
``` ```
cd ${GOPATH}/src/git.minhas.io/asara/sudoscientist-go-backend cd ${GOPATH}/src/git.minhas.io/asara/sudoscientist-go-backend
for i in settings/*; do source $i; done for i in settings/*; do source $i; done
export DB_HOST=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" sudosci-db) export DB_HOST=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" sudosci-db)
PSQL_QUERY_STRING="postgres://${DB_USER}:${DB_PW}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=${DB_SSL}"
migrate -path migrations/ -database ${PSQL_QUERY_STRING} up
go get go get
go run main.go go run main.go
``` ```