diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5461efd..472f1ed 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,25 +49,28 @@ Links: ##### Bootstrap database ###### Docker compose -- `docker compose up -d` should automatically create the database and run migration container -- +- `docker compose up -d` will run a postgres container locally + ###### Manual boostrap -If you need to manually run migrations, you can do so by running the following commands: -- `export DATABASE_URL="localhost"` -- `export DATABASE_PORT="5433"` -- Migration script to create initial schemas: `go run cmd/migrate` +If you need to manually run migrations, you can do so by running: -##### Starting teams API -Running the teams api (TODO: update makefile) +```bash +make migrate ``` -go get ./... -go run cmd/lab-api-teams/main.go + +##### Starting teams API +Running the teams api +```bash +make run ``` +##### Testing by adding some records +Try using the `.http` files in the `./test` folder to add some records to the database. + ##### Linting To run fmt, lint, test in one command -``` +```bash make static ``` diff --git a/Makefile b/Makefile index 46fa57b..900a9c1 100644 --- a/Makefile +++ b/Makefile @@ -56,6 +56,15 @@ build: chmod +x $(OUTPUT_DIR)/$(OUTPUT_BIN) docker build -t docker.io/twdps/lab-api-teams:$(REVISION) . +.PHONEY: run +run: + go mod tidy + DATABASE_URL="localhost" DATABASE_PORT="5433" go run ./cmd/lab-api-teams + +.PHONY: migrate +migrate: + DATABASE_URL="localhost" DATABASE_PORT="5433" go run ./cmd/migrate + .PHONY: push push: docker push docker.io/twdps/lab-api-teams:$(REVISION) diff --git a/cmd/migrate/main.go b/cmd/migrate/main.go index 05088c5..0d40e10 100644 --- a/cmd/migrate/main.go +++ b/cmd/migrate/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "github.com/ThoughtWorks-DPS/lab-api-teams/pkg/datastore" "github.com/ThoughtWorks-DPS/lab-api-teams/pkg/domain" ) @@ -10,6 +11,7 @@ import ( // port-forward the yugabyte db // run this go program func main() { + fmt.Println("Running Migrations...") ds_tm := datastore.NewGormDatastore("team") ds_ns := datastore.NewGormDatastore("namespace") diff --git a/docker-compose.yaml b/docker-compose.yaml index f34b0c6..d8e5358 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -15,24 +15,5 @@ services: interval: 5s timeout: 5s retries: 5 - networks: - - teams-api-network ports: - 5433:5432 - - migrate: - build: - context: . - dockerfile: Dockerfile.migrate - depends_on: - db: - condition: service_healthy - environment: - DATABASE_URL: db - DATABASE_PORT: 5432 - networks: - - teams-api-network - -networks: - teams-api-network: - driver: bridge diff --git a/go.mod b/go.mod index a70cde5..d1501b6 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/gobwas/glob v0.2.3 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/google/go-querystring v1.1.0 // indirect - github.com/google/uuid v1.6.0 // indirect + github.com/google/uuid v1.6.0 github.com/gorilla/websocket v1.5.0 // indirect github.com/imkira/go-interpol v1.1.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect diff --git a/go.sum b/go.sum index 0d783ba..b778239 100644 --- a/go.sum +++ b/go.sum @@ -133,7 +133,6 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.48.0 h1:oJWvHb9BIZToTQS3MuQ2R3bJZiNSa2KiNdeI8A+79Tc= github.com/valyala/fasthttp v1.48.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= -github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=