Database configuration (for MacOS)
Useful article - click to read
- Install postgres
- Run
cd /Library/PostgreSQL/13/bin
- Run
sudo -u postgres ./createdb restapi_dev
to create new database - Install migrate tool
- Run
migrate create -ext sql -dir migrations create_users
- Define up and down migrations
- Run
migrate -path migrations -database "postgres://localhost/restapi_dev?sslmode=disable&user=postgres&password=qwe123QWE" up
- Check DB:
sudo -u postgres ./psql -d restapi_dev
- Create new DB for tests:
sudo -u postgres ./createdb restapi_test
- Run migration for test DB:
migrate -path migrations -database "postgres://localhost/restapi_test?sslmode=disable&user=postgres&password=qwe123QWE" up
model
- keeps all database models
Store - kind of black-box instance, which provides public methods to work with the data. It can contain multiple repositories:
- User repository (create user / find in DB by parameters)
- To be updated
Store -> config.go
- config for the store
Models - contains models of data representation.