hasura / hasura/graphql-engine
Support environment variables in migrations
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
I want to add one or more users to postgresql as part of a feature I'm working on. I'am using Hasura for handling migrations. I want to provide the users' password as a environment variable, and in that way configure the password differently between different systems using the same Hasura image (with the migrations scripts included in the hasura image)
### Describe the solution you'd like
1. Create a migration (ie. up.sql) e.g `CREATE USER readOnlyUser WITH ENCRYPTED PASSWORD :readOnlyUserPassword`
2. Add a variable configuration for the migration that inserts the password parameter above from an environment variable. e.g in up_config.yaml:
```yaml
variables:
readOnlyUserPassword:
fromEnvVar: "READ_ONLY_USER_PASSWORD"
someOtherVariable:
value: "some value"
someSecret:
fromDockerSecret: "/run/secrets/someSecret"
```
3. When hasura applies the migration, it reads the up_config.yaml, and specifies the variables described in the config file as if the `psql` command is called using the `-v` flag with the variables' key as the variable name, and the value as specified in the yaml config file (see [psql docs](https://www.postgresql.org/docs/14/app-psql.html) -v flag) e.g `psql -v someOtherVariable="some value"` which can then be used in up.sql script using variable interpolation (as described [here](https://www.postgresql.org/docs/current/app-psql.html#APP-PSQL-INTERPOLATION)) e.g `select :'someOtherVariable';`
### Describe alternatives you've considered
using psql syntax (\\SET and similar), this seemingly does not work, since the up/down files are .sql, not .psql files
### If the feature is approved, would you be willing to submit a PR?
Unsure, probably no, since I by then might have found a work-around.
Contributor guide
Assessment
This issue has not been assessed yet.