- Build go-application
- Start DB (for exmaple with Docker)
- Install go-migrate
- Run go-application and migration
Change this variable in source: UrlExample
After: go build main.go
sudo docker run --name=ProductsDB -e POSTGRES_PASSWORD='qwerty' -p 5436:5432 -d postgres
Check this repository https://github.com/golang-migrate/migrate
- Migration examples
- Initialization of table "products"
migrate -path ./shema/ -database 'postgres://postgres:qwerty@localhost:5436/postgres?sslmode=disable' up
- Add column "rating" (transition to the second version)
migrate -path ./shema/ -database 'postgres://postgres:qwerty@localhost:5436/postgres?sslmode=disable' up 2
- Rollback to first version
migrate -path ./shema/ -database 'postgres://postgres:qwerty@localhost:5436/postgres?sslmode=disable' down 1
- Run application
./main &