Repository navigation
Closed
Labels
Description
I am using tmp-postgres for Haskell which creates a Unix socket with a connection string like host=/tmp/tmp-postgres-socket-33d7937af9c67679 dbname=postgres port=49905.
I want to use refinery-cli to apply my migrations to such a database.
According to the postgres docs, the connection string can be in several formats, which do support Unix sockets: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
However, it seems that Refinery parses them itself:
refinery/refinery_core/src/config.rs
Lines 225 to 243 in 36e2c21
| Ok(Self { | |
| main: Main { | |
| db_type, | |
| db_path: Some( | |
| url.as_str()[url.scheme().len()..] | |
| .trim_start_matches(':') | |
| .trim_start_matches("//") | |
| .to_string() | |
| .into(), | |
| ), | |
| db_host: url.host_str().map(|r| r.to_string()), | |
| db_port: url.port().map(|r| r.to_string()), | |
| db_user: Some(url.username().to_string()), | |
| db_pass: url.password().map(|r| r.to_string()), | |
| db_name: Some(url.path().trim_start_matches('/').to_string()), | |
| #[cfg(feature = "tiberius-config")] | |
| trust_cert, | |
| }, | |
| }) |
It seems like I need to generate a connection string like so, but this was obtained largely by guessing:
{- | Serializes a 'PG.Options' into the right format for Refinery CLI, which is
> postgres://user:pass@(urlencoded host)/db
See <https://github.com/rust-db/refinery/blob/36e2c219de236c95853a0aa6cd606a2d52d255f8/refinery_core/src/config.rs#L225-L243>
-}
optionsToUri :: PG.Options -> Maybe (URIRef Absolute)
optionsToUri PG.Options {host, user, password, dbname, port} = do
host' <- getLastBS host
dbname' <- getLastBS dbname
port' <- getLast port
-- Postgres will be grumpy if you don't give it a user, so there's not any
-- reasonable default here
user' <- getLastBS user
pure $
URI
{ uriScheme = Scheme "postgres"
, uriAuthority =
Just $
Authority
{ authorityUserInfo =
Just $ UserInfo user' (fromMaybe "" $ getLastBS password)
, authorityHost = Host (cs . toLazyByteString $ urlEncode [] host')
, authorityPort = Just $ Port port'
}
, uriPath = "/" <> cs dbname'
, uriQuery = Query []
, uriFragment = Nothing
}
where
getLastBS :: Last String -> Maybe ByteString
getLastBS s = cs <$> getLast s
Activity
jxs commentedon Nov 25, 2022
Hi, and thanks for the Interest! So, yeah
refineryassumes you pass a connection uri, defined in the doc you linked above .If I understand correctly it worked after you did so right? Would you be willing to submit a PR improving the documentation to make users aware of it?
Thanks!
lf- commentedon Nov 25, 2022
that's the thing: it does not parse those as far as i can tell. it only takes the one format that i guessed by reading the code since it does the parsing itself rather than giving the whole thing to postgres.
if i remember, I'll look into filing a pr on Monday
jxs commentedon Nov 25, 2022
yeah, but it then returns a connection string to postgres, see here should have the same format as the input doesn't it on your case?
lf- commentedon Nov 25, 2022
Ah. Yes, but most of the formats supported by postgres are thus unsupported. For instance refinery seemingly discards query parameters.
jxs commentedon Nov 25, 2022
Ah, I see. I will gladly support them for the drivers that support them for the input urls, if you want to submit a PR :)
github-actions commentedon Mar 31, 2026
This issue has been automatically marked as stale due to inactivity.
lf- commentedon Mar 31, 2026
I HATE STALE BOT. but also, yeah no this is still a bug, i wrote a very dubious socat workaround for this last week. unfortunately i have no time to fix it properly :(
github-actions commentedon May 3, 2026
This issue has been automatically marked as stale due to inactivity.
lf- commentedon May 3, 2026
MISCLICKED. This is still a bug.
jxs commentedon May 5, 2026
Hi, I feel this is more of a lack of feature and not a bug.
The issue was closed as it didn't have progress, but you very welcome to submit a PR to address this.
Thanks