rubyforgood / human-essentials

Human Essentials is an inventory management system for diaper, incontinence, and period-supply banks. It supports them in distributing to partners, tracking inventory, and reporting stats and analytics.
https://humanessentials.app
MIT License
436 stars 449 forks source link

Changes to fetch_latest_db process to address issues after 7.1.3.2 #4388

Closed cielf closed 3 weeks ago

cielf commented 4 weeks ago

Description

fetch_latest_db started failing on the drop database after a recent upgrade, or possibly as a result of changes that were made to fix bin/setup after that upgrade -- though it is not failing for everyone, it is failing for the person who uses it the most!

Here is what was happening:
... Recreating databases... PG::ObjectInUse: ERROR: database "diaper_dev" is being accessed by other users DETAIL: There is 1 other session using the database. Couldn't drop database 'diaper_dev' bin/rails aborted! ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR: database "diaper_dev" is being accessed by other users (ActiveRecord::StatementInvalid) DETAIL: There is 1 other session using the database.

Caused by: PG::ObjectInUse: ERROR: database "diaper_dev" is being accessed by other users (PG::ObjectInUse) DETAIL: There is 1 other session using the database.

Tasks: TOP => db:drop:_unsafe (See full trace by running task with --trace)

We worked through the issue in the Sunday office hours. Removing the => :environment got by the initial issue, but we also had to split the password setup into its own rake. If there is a way to keep them in one task, that would be grand - but this at least allows it to be used.

A quick check of the project does not indicate any mention of fetch_latest_db, but we should check any external docs.

Type of change

How Has This Been Tested?

ran fetch_latest_db and rest_passwords on my local, then signed in. Seems ok.

dorner commented 4 weeks ago

@cielf "Object in use" means there might be another process that's accessing the DB. I got that as well, but it was because I had the server running. Once I stopped it, the rake task seemed to work fine (albeit with a lot of errors reported, like usual). Did you try that?

cielf commented 4 weeks ago

I did a hard reboot, navigated to the directory, and ran it (just in case something in RubyMine was interfering)-- still got the ObjectInUse. It is strange.

dorner commented 4 weeks ago

Have you tried this? https://stackoverflow.com/questions/2369744/rails-postgres-drop-error-database-is-being-accessed-by-other-users

cielf commented 4 weeks ago

The kill_postgres_connections tactic works with a little application of the accompanying comments. I can submit a second PR with that in place, unless it working tells you something!

dorner commented 3 weeks ago

Closing in favor of #4389 .