main ← fix-restore-db-reconnect
merged 11:24AM - 07 Oct 26 UTC
A restore opens one database connection at the start. `psql` and `rake db:migrat…e` run in separate processes, which can take a long time. If Rails' connection is dropped for some reason while `psql`/`migrate` are running, then the restore will fail on the first query after the migration.
We already had a "Reconnecting to the database..." step, but this step did not actually open a new connection. On a single-site install it did nothing, and on a multisite install it used the cached connection again. Rails automatic reconnection does not take effect because Discourse's `DB.*` uses the raw_connection.
- `reconnect_database` now calls `reconnect!`, so the restore continues on a new connection.
- A new spec ends the restore's connection while the dump is restored, and checks that the restore still saves its date.
- `execute_stubbed_restore` stubs `reconnect!` by default, because a real reconnect drops the test transaction. The multisite spec uses a real reconnect, because its second database is not in a test transaction.
https://meta.discourse.org/t/413615