Skip to content

Commit

Permalink
Merge pull request #682 from 0xPolygonID/optimize_variables_check_in_…
Browse files Browse the repository at this point in the history
…db_migrations

Optimize variables checking in db migrations proccess
  • Loading branch information
martinsaporiti authored Jun 27, 2024
2 parents 7e67052 + beff4c3 commit befbf9e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions cmd/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@ import (
"context"
"os"

"github.com/polygonid/sh-id-platform/internal/config"
"github.com/joho/godotenv"

"github.com/polygonid/sh-id-platform/internal/db/schema"
"github.com/polygonid/sh-id-platform/internal/log"

_ "github.com/lib/pq"
)

// IssuerDatabaseUrl is the environment variable for the issuer database URL
const IssuerDatabaseUrl = "ISSUER_DATABASE_URL"

func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

cfg, err := config.Load("")
if err != nil {
log.Error(ctx, "cannot load config", "err", err)
if os.Getenv(IssuerDatabaseUrl) == "" {
err := godotenv.Load(".env-issuer")
if err != nil {
log.Error(ctx, "Error loading .env-issuer file")
}
}

log.Config(cfg.Log.Level, cfg.Log.Mode, os.Stdout)
log.Debug(ctx, "database", "url", cfg.Database.URL)
databaseUrl := os.Getenv(IssuerDatabaseUrl)
log.Config(log.LevelDebug, log.LevelDebug, os.Stdout)
log.Debug(ctx, "database", "url", databaseUrl)

if err := schema.Migrate(cfg.Database.URL); err != nil {
if err := schema.Migrate(databaseUrl); err != nil {
log.Error(ctx, "error migrating database", "err", err)
return
}
Expand Down

0 comments on commit befbf9e

Please sign in to comment.