[v2] Different databases.yaml based on the provided endpoint #10773
-
|
Hey, Is it possible to have different databases.yaml configs based on the endpoint? Should i create two separate configs using Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Good question. Hasura v2 does not have built-in support for conditional metadata based on the endpoint or environment, but there are a few battle-tested approaches: 1. Environment variables in metadata You can use env vars in databases.yaml for the connection string itself, but unfortunately read_replicas as a block cannot be conditionally included/excluded via env vars. 2. Separate metadata directories (recommended) The approach you mentioned is the way most teams handle this. Use hasura init to create two project directories (e.g. hasura-prod and hasura-dev), and share common table/relationship/permission definitions between them via symlinks or the !include tag. Then apply with hasura metadata apply --project hasura-dev or hasura-prod. 3. Script-based approach Some teams keep a single metadata directory and use a small script that generates the final databases.yaml from a template before running hasura metadata apply. You keep databases.prod.yaml and databases.dev.yaml side by side, and a shell script copies the right one based on an ENVIRONMENT variable before applying metadata. This keeps your CI/CD simple and avoids the manual commenting/uncommenting. Option 2 is the most maintainable long-term since it keeps everything declarative. |
Beta Was this translation helpful? Give feedback.
Good question. Hasura v2 does not have built-in support for conditional metadata based on the endpoint or environment, but there are a few battle-tested approaches:
1. Environment variables in metadata
You can use env vars in databases.yaml for the connection string itself, but unfortunately read_replicas as a block cannot be conditionally included/excluded via env vars.
2. Separate metadata directories (recommended)
The approach you mentioned is the way most teams handle this. Use hasura init to create two project directories (e.g. hasura-prod and hasura-dev), and share common table/relationship/permission definitions between them via symlinks or the !include tag. Then apply with hasura …