Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(db): get db endpoint by env #35

Merged
merged 1 commit into from
Nov 14, 2023
Merged
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
3 changes: 2 additions & 1 deletion cmd/node/db_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"github.com/spf13/viper"
)

// TODO use https://github.com/golang-migrate/migrate
Expand All @@ -30,7 +31,7 @@ func dbMigrate() {
create_at TIMESTAMP NOT NULL DEFAULT now()
);`

db, err := sqlx.Connect("postgres", "postgres://test_user:test_passwd@postgres:5432/test?sslmode=disable")
db, err := sqlx.Connect("postgres", viper.Get("DATABASE_URL").(string))
if err != nil {
log.Fatalln(err)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func main() {
viper.MustBindEnv("PROJECT_CONFIG_FILE")
viper.MustBindEnv("CHAIN_ENDPOINT")
viper.MustBindEnv("OPERATOR_PRIVATE_KEY")
viper.MustBindEnv("DATABASE_URL")

vmHandler := vm.NewHandler(
map[vm.Type]string{
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
PROJECT_CONFIG_FILE: "${PROJECT_CONFIG_FILE}"
CHAIN_ENDPOINT: "https://babel-api.testnet.iotex.io"
OPERATOR_PRIVATE_KEY: "${OPERATOR_PRIVATE_KEY}"
DATABASE_URL: postgres://test_user:test_passwd@postgres:5432/test?sslmode=disable
volumes:
- .:/data

Expand Down Expand Up @@ -51,6 +52,4 @@ services:
POSTGRES_DB: test
volumes:
- ./postgres:/var/lib/postgresql/data
ports:
# for manual create db table, will become auto in feature
- "5432:5432"