Skip to content

Commit

Permalink
feat: apply pesticides
Browse files Browse the repository at this point in the history
byebye cockroaches
  • Loading branch information
Candinya committed Aug 16, 2024
1 parent 22679fd commit 5cb3735
Show file tree
Hide file tree
Showing 36 changed files with 51 additions and 73 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,13 @@ jobs:
--mode dev-container \
--default-log-level=debug
- name: Start CRDB container
- name: Start PSQL container
run: |
docker run -d --name crdb \
--network ${{ job.container.network }} --network-alias crdb \
-p 8080:8080 -p 26257:26257 \
cockroachdb/cockroach:v23.1.8 \
start-single-node \
--cluster-name=node \
--insecure
docker run -d --name psql \
--network ${{ job.container.network }} --network-alias psql \
-p 5432:5432 \
-e POSTGRES_PASSWORD=dev \
postgres:16-alpine
- name: Setup Go
uses: actions/setup-go@v3
Expand All @@ -82,5 +80,5 @@ jobs:

- name: Stop containers
run: |
docker stop redpanda-0 crdb
docker rm redpanda-0 crdb
docker stop redpanda-0 psql
docker rm redpanda-0 psql
11 changes: 5 additions & 6 deletions atlas.hcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// read internal/database/dialer/cockroachdb/README.md for more information
// read internal/database/dialer/postgresql/README.md for more information

data "external_schema" "gorm" {
program = [
Expand All @@ -7,7 +7,7 @@ data "external_schema" "gorm" {
"-mod=mod",
"ariga.io/atlas-provider-gorm",
"load",
"--path", "./internal/database/dialer/cockroachdb/table",
"--path", "./internal/database/dialer/postgresql/table",
"--dialect", "postgres"
]
}
Expand All @@ -17,14 +17,13 @@ env "dev" {
// pointing to gorm models to generate schemas
src = data.external_schema.gorm.url
// the database which is holding the actual tables
url = "postgres://root:@localhost:26257/defaultdb?sslmode=disable&search_path=public"
# url = "postgres://postgres:password@localhost:5432/postgres?sslmode=disable"
url = "postgres://postgres:dev@localhost:5432/postgres?sslmode=disable"
// a temporary database for Atlas to do migrations
dev = "postgres://root:@localhost:26258/defaultdb?sslmode=disable&search_path=public"
dev = "postgres://postgres:mig@localhost:5433/postgres?sslmode=disable"
# dev = "docker://postgres/16"
// location of migration files
migration {
dir = "file://internal/database/dialer/cockroachdb/migration?format=goose"
dir = "file://internal/database/dialer/postgresql/migration?format=goose"
}
format {
migrate {
Expand Down
4 changes: 2 additions & 2 deletions deploy/config.yaml.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
environment: development

database:
driver: cockroachdb
driver: postgresql
partition: true
uri: postgres://root@localhost:26257/defaultdb
uri: postgres://postgres:password@localhost:5432/postgres

redis:
uri: redis://localhost:6379/0
Expand Down
27 changes: 6 additions & 21 deletions deploy/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
version: "3.9"
name: pp_dev
services:
# CRDB
cockroach:
image: cockroachdb/cockroach:v23.1.8
# Database
postgres:
image: postgres:16-alpine
ports:
- "26257:26257"
command:
- start-single-node
- --cluster-name=rss3-gateway
- --insecure
labels:
- "traefik.http.routers.crdb-console.rule=Host(`crdb-console.docker.localhost`)"
- "traefik.http.services.crdb-console.loadbalancer.server.port=8080"

# # CRDB for Atlas' temporary migration use
# cockroach2:
# image: cockroachdb/cockroach:v23.1.8
# ports:
# - "26258:26257"
# command:
# - start-single-node
# - --cluster-name=rss3-gateway
# - --insecure
- "5432:5432"
environment:
POSTGRES_PASSWORD: dev

# Redis
redis:
Expand Down
13 changes: 5 additions & 8 deletions deploy/docker-compose.migration.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
version: "3.9"
name: pp_mig
services:
# CRDB for Atlas' temporary migration use
cockroach2:
image: cockroachdb/cockroach:v23.1.8
postgres-mig:
image: postgres:16-alpine
ports:
- "26258:26257"
command:
- start-single-node
- --cluster-name=rss3-gateway
- --insecure
- "5433:5432"
environment:
POSTGRES_PASSWORD: mig
4 changes: 2 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type File struct {
}

type Database struct {
Driver database.Driver `mapstructure:"driver" validate:"required" default:"cockroachdb"`
URI string `mapstructure:"uri" validate:"required" default:"postgres://root@localhost:26257/defaultdb"`
Driver database.Driver `mapstructure:"driver" validate:"required" default:"postgresql"`
URI string `mapstructure:"uri" validate:"required" default:"postgres://postgres:password@localhost:5432/postgres"`
}

type Redis struct {
Expand Down
6 changes: 3 additions & 3 deletions internal/database/dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (

"github.com/rss3-network/payment-processor/internal/config"
"github.com/rss3-network/payment-processor/internal/database"
"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql"
)

func Dial(ctx context.Context, config *config.Database) (database.Client, error) {
switch config.Driver {
case database.DriverCockroachDB:
return cockroachdb.Dial(ctx, config.URI)
case database.DriverPostgreSQL:
return postgresql.Dial(ctx, config.URI)
default:
return nil, fmt.Errorf("unsupported driver: %s", config.Driver)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cockroachdb
package postgresql

import (
"context"
Expand All @@ -8,7 +8,7 @@ import (

"github.com/pressly/goose/v3"
"github.com/rss3-network/payment-processor/internal/database"
"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb/table"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql/table"
"go.uber.org/zap"
"gorm.io/driver/postgres"
"gorm.io/gorm"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cockroachdb
package postgresql

import (
"context"
Expand All @@ -8,7 +8,7 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb/table"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql/table"
"github.com/rss3-network/payment-processor/schema"
"go.uber.org/zap"
"gorm.io/gorm"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cockroachdb
package postgresql

import (
"context"
"fmt"

"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb/table"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql/table"
"github.com/rss3-network/payment-processor/schema"
"gorm.io/gorm/clause"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cockroachdb
package postgresql

import (
"context"

"github.com/ethereum/go-ethereum/common"
"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb/table"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql/table"
"gorm.io/gorm"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cockroachdb
package postgresql

import (
"context"
Expand All @@ -7,7 +7,7 @@ import (
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb/table"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql/table"
"github.com/rss3-network/payment-processor/schema"
"github.com/shopspring/decimal"
"go.uber.org/zap"
Expand Down
5 changes: 2 additions & 3 deletions internal/database/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package database
type Driver string

const (
DriverCockroachDB Driver = "cockroachdb"
DriverPostgreSQL Driver = "postgresql"
DriverMySQL Driver = "mysql"
DriverPostgreSQL Driver = "postgresql"
DriverMySQL Driver = "mysql"
)
6 changes: 3 additions & 3 deletions internal/service/hub/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/rss3-network/payment-processor/internal/config"
"github.com/rss3-network/payment-processor/internal/database"
"github.com/rss3-network/payment-processor/internal/database/dialer"
"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb/table"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql/table"
"github.com/rss3-network/payment-processor/internal/service/hub/handlers"
jwtImpl "github.com/rss3-network/payment-processor/internal/service/hub/jwt"
"github.com/rss3-network/payment-processor/internal/service/hub/model"
Expand Down Expand Up @@ -67,8 +67,8 @@ const (
func init() {
// Prepare databaseClient
dbc, err := dialer.Dial(context.Background(), &config.Database{
Driver: database.DriverCockroachDB,
URI: "postgres://root@localhost:26257/defaultdb",
Driver: database.DriverPostgreSQL,
URI: "postgres://postgres:dev@localhost:5432/postgres",
})
if err != nil {
log.Panic(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/hub/handlers/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"

"github.com/labstack/echo/v4"
"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb/table"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql/table"
"github.com/rss3-network/payment-processor/internal/service/hub/gen/oapi"
"github.com/rss3-network/payment-processor/internal/service/hub/model"
"github.com/rss3-network/payment-processor/internal/service/hub/utils"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/hub/handlers/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"

"github.com/labstack/echo/v4"
"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb/table"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql/table"
"github.com/rss3-network/payment-processor/internal/service/hub/gen/oapi"
"github.com/rss3-network/payment-processor/internal/service/hub/model"
"github.com/rss3-network/payment-processor/internal/service/hub/utils"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/hub/model/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/rss3-network/gateway-common/control"
"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb/table"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql/table"
"github.com/rss3-network/payment-processor/schema"
"gorm.io/gorm"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/service/hub/model/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
"github.com/rss3-network/gateway-common/control"
"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb/table"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql/table"
"gorm.io/gorm"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/service/hub/processors/access_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"

"github.com/rss3-network/gateway-common/accesslog"
"github.com/rss3-network/payment-processor/internal/database/dialer/cockroachdb/table"
"github.com/rss3-network/payment-processor/internal/database/dialer/postgresql/table"
"github.com/rss3-network/payment-processor/internal/service/hub/model"
"go.uber.org/zap"
)
Expand Down

0 comments on commit 5cb3735

Please sign in to comment.