Skip to content

1kan0bi/go-simple-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple REST API with DB migrations

Steps to run application and migrations

  1. Build go-application
  2. Start DB (for exmaple with Docker)
  3. Install go-migrate
  4. Run go-application and migration

1.Build go-application

Change this variable in source: UrlExample After: go build main.go

2. Start DB (for exmaple with Docker)

sudo docker run --name=ProductsDB -e POSTGRES_PASSWORD='qwerty' -p 5436:5432 -d postgres

3. Install go-migrate

Check this repository https://github.com/golang-migrate/migrate

4. Run go-application and migration

  1. 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
  1. Run application ./main &

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages