Skip to content

Commit

Permalink
fix: allow using a different connection string for migrations (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop authored May 22, 2024
1 parent 6d2fcaf commit 1553573
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion go/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
flagLogFormatTEXT = "log-format-text"
flagTrustedProxies = "trusted-proxies"
flagPostgresConnection = "postgres"
flagPostgresMigrationsConnection = "postgres-migrations"
flagNodeServerPath = "node-server-path"
flagDisableSignup = "disable-signup"
flagConcealErrors = "conceal-errors"
Expand Down Expand Up @@ -110,11 +111,17 @@ func CommandServe() *cli.Command { //nolint:funlen,maintidx
},
&cli.StringFlag{ //nolint: exhaustruct
Name: flagPostgresConnection,
Usage: "PostgreSQL connection URI: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING. Required to inject the `auth` schema into the database.",
Usage: "PostgreSQL connection URI: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING",
Value: "postgres://postgres:postgres@localhost:5432/local?sslmode=disable",
Category: "postgres",
EnvVars: []string{"POSTGRES_CONNECTION", "HASURA_GRAPHQL_DATABASE_URL"},
},
&cli.StringFlag{ //nolint: exhaustruct
Name: flagPostgresMigrationsConnection,
Usage: "PostgreSQL connection URI for running migrations: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING. Required to inject the `auth` schema into the database. If not specied, the `postgres connection will be used",
Category: "postgres",
EnvVars: []string{"POSTGRES_MIGRATIONS_CONNECTION"},
},
&cli.StringFlag{ //nolint: exhaustruct
Name: flagNodeServerPath,
Usage: "Path to the node server",
Expand Down Expand Up @@ -461,6 +468,16 @@ func getNodeServer(cCtx *cli.Context) *exec.Cmd {
env = append(env, "NODE_ENV=development")
}

if cCtx.String(flagPostgresMigrationsConnection) != "" {
for i, v := range env {
if strings.HasPrefix(v, "HASURA_GRAPHQL_DATABASE_URL=") {
env[i] = "HASURA_GRAPHQL_DATABASE_URL=" + cCtx.String(
flagPostgresMigrationsConnection,
)
}
}
}

cmd := exec.CommandContext(cCtx.Context, "node", "./dist/start.js")
cmd.Dir = cCtx.String(flagNodeServerPath)
cmd.Stdout = os.Stdout
Expand Down

0 comments on commit 1553573

Please sign in to comment.