Skip to content
This repository was archived by the owner on May 2, 2024. It is now read-only.

feat: moves transaction-db driver into repo. #44

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
PG_USER=
PG_PASSWORD=
PG_DATABASE=
API_KEYS=

# CloudSQL DB var
DB_INSTANCE_CONNECTION_NAME=
API_KEYS=aaaa

# Local DB Vars
PG_HOST=
PG_PORT=

# Prod DB vars
DB_INSTANCE_CONNECTION_NAME=

# Optional vars (will be set to default if not set)
PORT=8080
MAX_RELAY_BATCH_SIZE=1000
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ jobs:
restore-keys: |
${{ runner.os }}-go-

- name: Run Unit tests
run: go test ./...
- name: Run tests
run: make test
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repos:
- id: go-critic
- id: go-build
- id: go-mod-tidy
- id: go-unit-tests
- repo: https://github.com/Yelp/detect-secrets
rev: v1.4.0
hooks:
Expand Down
4 changes: 4 additions & 0 deletions Dockerfile.testdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This Dockerfile used to build the image used for testing TxDB
FROM postgres:14.3

COPY ./postgres-driver/sqlc/schema.sql /docker-entrypoint-initdb.d/
35 changes: 34 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
SHELL := /bin/bash

gen: gen_sql gen_mocks

gen_sql:
sqlc generate -f ./postgres-driver/sqlc/sqlc.yaml

gen_mocks:
mockery --name=Driver --recursive --inpkg --case=underscore
mockery --name=RelayWriter --recursive --inpkg --case=underscore
mockery --name=ServiceRecordWriter --recursive --inpkg --case=underscore

test: test_unit test_env_up run_driver_tests test_env_down

test_unit:
@echo "🛠 Running Unit tests..."
@go test ./... -short || true
@echo "✅ Unit tests completed!"

test_env_up:
@echo "🧪 Starting up Transaction DB test database ..."
@docker-compose -f ./testdata/docker-compose.test.yml up -d --remove-orphans --build
@echo "⏳ Waiting for test DB to be ready ..."
@attempts=0; while ! pg_isready -h localhost -p 5432 -U postgres -d postgres >/dev/null && [[ $$attempts -lt 5 ]]; do sleep 1; attempts=$$(($$attempts + 1)); done
@[[ $$attempts -lt 5 ]] && echo "🐘 Test Transaction DB is up ..." || (echo "❌ Test Transaction DB failed to start" && make test_env_down >/dev/null && exit 1)
@sleep 2;
@echo "🚀 Test environment is up ..."
test_env_down:
@echo "🧪 Shutting down Portal HTTP DB test environment ..."
@docker-compose -f ./testdata/docker-compose.test.yml down --remove-orphans >/dev/null
@echo "✅ Test environment is down."

run_driver_tests:
@echo "🚗 Running PGDriver tests..."
@go test ./... -run Test_RunPGDriverSuite -count=1 || true
@echo "✅ PGDriver tests completed!"
run_driver_tests_ci:
go test ./... -run Test_RunPGDriverSuite -count=1

init-pre-commit:
wget https://github.com/pre-commit/pre-commit/releases/download/v2.20.0/pre-commit-2.20.0.pyz
python3 pre-commit-2.20.0.pyz install
python3 pre-commit-2.20.0.pyz autoupdate
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install -v github.com/go-critic/go-critic/cmd/gocritic@latest
Expand Down
2 changes: 1 addition & 1 deletion batch/batch_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package batch
import (
context "context"

types "github.com/pokt-foundation/transaction-db/types"
types "github.com/pokt-foundation/transaction-http-db/types"
mock "github.com/stretchr/testify/mock"
)

Expand Down
2 changes: 1 addition & 1 deletion batch/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/pokt-foundation/transaction-db/types"
"github.com/pokt-foundation/transaction-http-db/types"
mock "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ module github.com/pokt-foundation/transaction-http-db
go 1.21

require (
cloud.google.com/go/cloudsqlconn v1.3.0
github.com/gorilla/mux v1.8.0
github.com/pokt-foundation/transaction-db v1.23.0
github.com/jackc/pgx/v5 v5.4.3
github.com/pokt-foundation/utils-go v0.11.1
github.com/stretchr/testify v1.8.2
go.uber.org/zap v1.24.0
golang.org/x/sync v0.3.0
google.golang.org/grpc v1.59.0
)

require (
cloud.google.com/go/cloudsqlconn v1.3.0 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -24,9 +25,9 @@ require (
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
Expand All @@ -42,7 +43,6 @@ require (
google.golang.org/api v0.126.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231009173412-8bfb1ae86b6c // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XP
github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -109,8 +110,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pokt-foundation/transaction-db v1.23.0 h1:b848mUg6AkpYqLL8yDDz6cQX/oqcqdCxYE3Sc3nS81c=
github.com/pokt-foundation/transaction-db v1.23.0/go.mod h1:JEpKrqtjO6b4CiDb70bj7s1gn8cIfwlexE4HosL430U=
github.com/pokt-foundation/utils-go v0.11.1 h1:o/kF4KFaClAz2AvybDrEQR1TpEEx6zwyuGcOlD/aLuY=
github.com/pokt-foundation/utils-go v0.11.1/go.mod h1:YZDpKHum+UINTYIzFJvLdlne2ksnlBonszqZQ7mkKnU=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"syscall"
"time"

postgresdriver "github.com/pokt-foundation/transaction-db/postgres-driver"
"github.com/pokt-foundation/transaction-http-db/batch"
postgresdriver "github.com/pokt-foundation/transaction-http-db/postgres-driver"
"github.com/pokt-foundation/transaction-http-db/router"
"github.com/pokt-foundation/utils-go/environment"
"go.uber.org/zap"
Expand Down
120 changes: 120 additions & 0 deletions postgres-driver/copyfrom.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions postgres-driver/db.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading