backend service for Northwestern World Cup
This project needs to be in your go path. However, you can put this repo where ever you want on your local machine and create a symlink from your go path:
ln -s path/to/original your/go/path
You'll most likely want to create the link from ~/go/src but it could be different if you don't use the defaults for go
Install postgres on your local machine (best to do with brew) and let the server run on the default port 5432. Create a user called nuwcuser with password password and create a db called nuwc. Grant all privelages for this db to the new user.
CREATE ROLE nuwcuser WITH LOGIN PASSWORD 'password';
CREATE DATABASE nuwc;
GRANT ALL PRIVILEGES ON DATABASE nuwc TO nuwcuser;
Now when the server application is started, it will perform the necessary database migrations found in the migrate/migrations directory, using the migrate.go script.
To see that the first migration up has worked you can check the db to see that the changes are there:
psql nuwc -c "\d player"
- if you are in need of a Postgres client, Postico is good!
For basic psql commands visit this cheatsheet
For the app to be able update a spreadsheet you need to add your spreadsheet ID in server.go. Do not push token.go to github as it contains a token only acquired after authorization from a google account. If you want to use google sheets functionality locally, you'll need to manually authenticate on a browser the first time you use one of the available functions in sheets.go. Follow the instructions on the command line and in the browser and a token.json file will be added to gtools/ and all api calls from that point forward will use the token.json file to authenticate.
Navigate to the root directory and start the server:
go run server.go
If you're adding a table, index, adding a column or whatever it is, add another migration file. Make sure you put the sequential number in front of it, and add both a migrate up and migrate down. If you need help understanding migrations, it might be a good idea to look at the golang-migrate docs.
You can use the golang-migrate CLI to help you. Basically if you make a mistake, you can force a version. Or if you just want to see what a prior version of the db is like you can migrate up or down accordingly. To install the golang-migrate CLI on mac:
brew install golang-migrate
If you want to work with a database version that doesn't include the latest version of migrations, comment out migrate.Migrate() in main() of server.go(), then use the go-lang CLI to migrate to whatever verison you want to use and restart the application. Optionally, you could alter migrate.go, but don't push those changes.