enable reading server uri from env var#3891
Conversation
|
@joelklint the URI can be templated with environment variables. Does that solve your issue? |
|
@kyleconroy I need to derive the host part of the connection string through I find that solution less clean in a way, while at the same time more clean since it enables me to own the mapping of sqlc to the environment. I however find it a bit odd that some config supports environment variables in one way ( Is there a roadmap item regarding configuration through environment variables and/or flags? |
Nope. The default will continue to be the configuration file with exceptions made when needed. Glad that this worked out! |
The managed database configuration is a nice feature for further improving the value provided by sqlc. The server connection string however must be specified in
sqlc.yaml, which limits the flexibility of an sqlc project to adapt to multiple environments.I have a project which utilizes sqlc in local development. I would like to also utilize sqlc in Continuous Integration of that project. The CI server in question is configured in a way which makes me unable to provide a connection string which can be reused in both local development and CI.
Many other populate cli tools accepts configuration through environment variables or flags, making them more flexible and therefore easier to integrate into situations like mine. One example being
atlas migrate lintwhich operates in much the same way assqlc verifyandsqlc vet, where a database server is used to validate sql.This PR adds the possibility to configure the server uri through an environment variable if the
sqlc.yamlcontains only one server.I am happy to receive feedback or alternative solutions.
Thanks 🙏
Expand me if you'd like to learn why I am unable to provide a static connection string
The CI server is configured such that jobs is executed in docker containers. One invocation of my CI pipeline is executed in one such container. The docker socket of the host is mounted into that docker container. My CI pipeline starts by starting a postgres database server in a docker container and mounts the container port 5432 onto port 55432 on the host, such that
sqlcshould be able to connect tolocalhost:55432. The problem is that the host of the container is the CI server and not the container my CI pipeline is executing in.sqlcis therefore unable to connect to the database server.