When using a connection string managed by a hosted database, the provider might use either postgres:// or postgresql:// as the scheme identifier in the URL. DigitalOcean for example uses the latter with their managed databases.
This is explicitly allowed in other clients like libpq:
The URI scheme designator can be either postgresql:// or postgres://.
However, the SQLPostgresConfiguration struct only accepts the shorter version, causing an URLError to be thrown.
To Reproduce
Clone a template project that has postgres set up.
git clone git@github.com:vapor/template-fluent-postgres-leaf.git postgres-url-test
cd postgres-url-test
xed Package.swift
Change the database configuration in configure.swift to take a postgresql:// URL instead of separate fields.
Manually replacing postgresql:// in the URL with postgres:// works around the issue ā either by changing the connection string by hand, or replacing the URL scheme in code. The latter approach works best if the service provider rotates the credentials automatically.
Describe the bug
When using a connection string managed by a hosted database, the provider might use either
postgres://
orpostgresql://
as the scheme identifier in the URL. DigitalOcean for example uses the latter with their managed databases.This is explicitly allowed in other clients like libpq:
However, the SQLPostgresConfiguration struct only accepts the shorter version, causing an URLError to be thrown.
To Reproduce
Clone a template project that has postgres set up.
Change the database configuration in configure.swift to take a
postgresql://
URL instead of separate fields.Run the project and observe the crash.
Expected behavior
The URL should be parsed successfully.
Environment
Workaround
Manually replacing
postgresql://
in the URL withpostgres://
works around the issue ā either by changing the connection string by hand, or replacing the URL scheme in code. The latter approach works best if the service provider rotates the credentials automatically.