Skip to content

Commit

Permalink
fix(#28): provide make commands for running and migrating db
Browse files Browse the repository at this point in the history
  • Loading branch information
saylerb committed Apr 24, 2024
1 parent fc4a494 commit 49ffb52
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 32 deletions.
25 changes: 14 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmd/migrate/main.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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")

Expand Down
19 changes: 0 additions & 19 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 49ffb52

Please sign in to comment.