graphile / migrate

Opinionated SQL-powered productive roll-forward migration tool for PostgreSQL.
MIT License
751 stars 58 forks source link

fix: preserve sslrootcert when rewriting URLs #89

Closed jacobwgillespie closed 4 years ago

jacobwgillespie commented 4 years ago

Hey, it looks like as a side effect of makeRootDatabaseConnectionString() passing through pg-connection-string is that it fails to preserve some more complex connection string parameters, for instance sslrootcert. When that option is specified, it actually loads the certificate data, so parsed.ssl becomes {ca: '...'} rather than true.

This means that when makeRootDatabaseConnectionString() converts it back into a connection string, it adds ?ssl=%5Bobject%20Object%5D.

This PR switches to use the url module to just swap out the pathname, which in theory should be less disruptive than attempting to handle every possible connection parameter, as it preserves the connection URL that the user has provided (as a plus, this removes the // TODO: factor in other connection parameter). I'm not 100% familiar with why this was the way it was before, so I may be missing something, but hopefully this is more robust.

There are two commits in this PR, one to add a failing test, and one to modify makeRootDatabaseConnectionString(). I'm opening the PR with only the first so that Travis CI will start a build, then I'll push the 2nd.

benjie commented 4 years ago

I'm not 100% familiar with why this was the way it was before, so I may be missing something, but hopefully this is more robust

Honestly, I can't figure out what would have possessed me to write so much unnecessary (and less correct) code; I'm going to blame it on lack of sleep :yawning_face:

benjie commented 4 years ago

Released in v1.0.1