Add an option to terminate all existing connections to the database when resetting a database#239
Add an option to terminate all existing connections to the database when resetting a database#239AustinShelby wants to merge 2 commits intographile:mainfrom
Conversation
| ); | ||
| if (force) { | ||
| await pgClient.query( | ||
| `DROP DATABASE IF EXISTS ${escapeIdentifier(databaseName)} WITH (FORCE);`, |
There was a problem hiding this comment.
Introduced in PG13, so this is technically supported by all supported versions of PostgreSQL now. Interesting.
|
Thanks for the PR... I shall search my feelings 🤔 |
|
Sorry for the delay... Even now, as I write this comment, I'm going back and forth on how I feel about it. It makes me feel uncomfortable... I don't really like the idea behind it. But also, it's for the I guess my main concern is that this opens up a can of worms and may result in people raising further PRs after this (e.g. "lock the DB after reset to prevent X, Y and Z", "create the database with a different name and then rename it", etc) when really they shouldn't be running their application against a DB that's being reset - and if they weren't, they wouldn't need this PR. |
|
Given your use case, I'd just recommend that you teach your test suite to be better at closing lingering connections (or you use A technique that works really well for PostGraphile's test suite is to create a template test DB, then each test creates a clone of this template using a random name to use for that test and drops it at the end. The best part of this is it allows all my tests to run in parallel, the only downside of which is that the fans on my PC suddenly sound like a hurricane as all 32 cores are maxed out! (Cloning a template DB, assuming it doesn't have loads of data, is generally a sub-second operation.) |
Description
This PR introduces a new
--forceoption for thegraphile-migrate resetcommand, which allows terminating existing connections to the database when dropping it.I often face a case during end-to-end testing when before each test case I want to reset the database. Unfortunately due to some lingering connections from previous tests, the
graphile-migrate resetcommand sometimes throws an error as expected. This change allows to bypass that limitation.Performance impact
Unknown.
Security impact
Unknown.
Checklist
yarn lint:fixpasses.yarn testpasses.RELEASE_NOTES.mdfile (if one exists).