Skip to content

Commit

Permalink
feat(db): get db endpoint by env
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhiran authored Nov 14, 2023
2 parents 26a4b6a + 9a23d96 commit 84ddd54
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
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"

0 comments on commit 84ddd54

Please sign in to comment.