hasura / hasura/graphql-engine
Full metadata query is required to update a database URL
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Is your proposal related to a problem?
The metadata API `pg_update_source` does not merge with existing values like `pool_settings` and will reset to the defaults when not provided. A note in the API is probably a good idea there, this can lead to interrupted database connections.
Heroku changes database URLs after a maintenance window. It is ideal to automate the update in Hasura to minimize down-time. It is pretty straight forward to send the DATABASE_URL when a dyno starts in the event that there is a change. There is a complication though. The `pg_update_source` does not do a deeper merge with existing settings. Instead the settings will revert back to default settings if this information is not provided. I would like to update just some of the information but leave the rest untouched.
For example, if `pg_update_source` is called only with `{configuration: {connection_info: {database_url: ""}}}` the `pool_settings` are reset to the default. Heroku limits connections so if the value was tuned to avoid exceeding the pool size, an unexpected reset back to the default pool size of 50 can cause an unexpected database connection interruptions.
[pg_update_source](https://hasura.io/docs/latest/api-reference/metadata-api/source/#metadata-pg-update-source)
```json
"configuration": {
"connection_info": {
"database_url": {
"from_env": ""
},
"pool_settings": {
"max_connections": 50,
"idle_timeout": 180,
"retries": 1,
"pool_timeout": 360,
"connection_lifetime": 600
},
"use_prepared_statements": true,
"isolation_level": "read-committed",
}
}
```
### Describe the solution you'd like
Merge with existing values. A `merge` boolean can provide backwards comparability or `null` can indicate that the setting should be reset to its default. Or, you may provide more value if another API call like `pg_get_source` to query a subset of this information so the client can do the merge.
### Describe alternatives you've considered
Query the entire metadata set and and merge it. Along these lines, fortunately, I was able to make an update without re-sending the `customization` data (customization settings were kept). So this should be a viable work-around even if more configurations sections are added in the future so it appears that this merging can be limited to the `configuration` only.
```js
// hsMeta is my own code (pseudo-code here)
const curMeta = await hsMeta('export_metadata')
const curSource = curMeta.sources.find(s => s.name === )
const {configuration, customization} = curSource
configuration.connection_info.database_url =
const result = await hsMeta('pg_update_source', {
name: ,
configuration // , customization // was not necessary to merge customization
})
```
### If the feature is approved, would you be willing to submit a PR?
I learned go, not yet
Contributor guide
Assessment
This issue has not been assessed yet.