Skip to content

Add postres env vars config#48

Merged
Billuc merged 8 commits intoBilluc:mainfrom
enderdwt:main
Feb 16, 2026
Merged

Add postres env vars config#48
Billuc merged 8 commits intoBilluc:mainfrom
enderdwt:main

Conversation

@enderdwt
Copy link
Contributor

@enderdwt enderdwt commented Feb 8, 2026

This is a first pass for #47. Waiting on to see if you are open to adding this feature before continuing on docs and unit tests.

@@ -86,6 +105,7 @@ fn connect(
envoy.get("DATABASE_URL")
|> result.replace_error(EnvVarUnset("DATABASE_URL"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this error should never get returned due to the try_recover but it was needed to compile the code. I am not sure if there is a better way to do this.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe one way to do this would be to try to get the "DATABASE_URL" envvar. Then if it is ok -> use connection_from_url. Otherwise, try to get Postgres environment variables. If none is set, return an error similar to EnvVarUnset. Otherwise, use connection_from_config.
What do you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can certainly implement more complex error handling here. However, should we align this with the Squirrel pattern? Specifically, we would prioritize DATABASE_URL if available, and otherwise fall back to standard Postgres environment variables or their default values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go the path of using default values instead of error if the Postgres env vars do not exist do not need the EnvVarUnset error.

@Billuc
Copy link
Owner

Billuc commented Feb 10, 2026

Hello, I think this would make a good addition ! The code in itself looks good. I would maybe refactor it to avoid some code duplication. I haven't given this too much thought, I'll review more in detail later ;)

Comment on lines +87 to +98
let procname = process.new_name("cigogne")
let config =
pog.default_config(procname)
|> apply_if_some(user, pog.user)
|> pog.password(password)
|> apply_if_some(host, pog.host)
|> apply_if_some(port, pog.port)
|> apply_if_some(name, pog.database)
pog.start(config)
|> result.map_error(ActorStartError)
|> result.map(fn(actor) { actor.data })
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to a connection_from_config function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 112 to 122
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to a connection_from_config function

@@ -86,6 +105,7 @@ fn connect(
envoy.get("DATABASE_URL")
|> result.replace_error(EnvVarUnset("DATABASE_URL"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe one way to do this would be to try to get the "DATABASE_URL" envvar. Then if it is ok -> use connection_from_url. Otherwise, try to get Postgres environment variables. If none is set, return an error similar to EnvVarUnset. Otherwise, use connection_from_config.
What do you think ?

@enderdwt enderdwt requested a review from Billuc February 12, 2026 03:45
Copy link
Owner

@Billuc Billuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this locally and it works fine ! I am fine with the fact that we don't have an error if we don't have any envvar set. I think it is quite consistent with how Postgres works. However, The error message we get in case of a bad config is really not helping (Database error: CONNECTION UNAVAILABLE) ^^'

@Billuc
Copy link
Owner

Billuc commented Feb 16, 2026

I tested this locally and it works fine ! I am fine with the fact that we don't have an error if we don't have any envvar set. I think it is quite consistent with how Postgres works. However, The error message we get in case of a bad config is really not helping (Database error: CONNECTION UNAVAILABLE) ^^'

I think I will create another issue for this.

@Billuc Billuc merged commit 3b5ed21 into Billuc:main Feb 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants