Skip to content

Commit

Permalink
Merge pull request #12 from RSS3-Network/feat/use-pg
Browse files Browse the repository at this point in the history
feat: use pg
  • Loading branch information
Candinya authored Aug 19, 2024
2 parents 22679fd + 8f961d2 commit 8c125ef
Show file tree
Hide file tree
Showing 38 changed files with 248 additions and 362 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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8c125ef

Please sign in to comment.