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

fix(#4373): remove legacy postgres initializer #4376

Closed elasticspoon closed 1 month ago

elasticspoon commented 1 month ago

Fixes #4373

Application had a legacy hack to forcefully drop DB connections that was needed with pow.cx.

That is no longer used and the hack no longer work with Rails 7.1 so the initializer can be removed.

Can confirm it happens on main for me without the fix:

$ > rails db:reset
undefined local variable or method `establish_master_connection' for #<ActiveRecord::Tasks::PostgreSQLDatabaseTasks:0x00007f1e4e8619b0 @db_config=#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007f1e4ee59930 @env_name="development", @name="primary", @configuration_hash={:adapter=>"postgresql", :encoding=>"unicode", :host=>"localhost", :database=>"diaper_dev", :username=>"postgres", :password=>"postgres", :pool=>5, :timeout=>5000}>, @configuration_hash={:adapter=>"postgresql", :encoding=>"unicode", :host=>"localhost", :database=>"diaper_dev", :username=>"postgres", :password=>"postgres", :pool=>5, :timeout=>5000}>
Couldn't drop database 'diaper_dev'
bin/rails aborted!
NameError: undefined local variable or method `establish_master_connection' for #<ActiveRecord::Tasks::PostgreSQLDatabaseTasks:0x00007f1e4e8619b0 @db_config=#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007f1e4ee59930 @env_name="development", @name="primary", @configuration_hash={:adapter=>"postgresql", :encoding=>"unicode", :host=>"localhost", :database=>"diaper_dev", :username=>"postgres", :password=>"postgres", :pool=>5, :timeout=>5000}>, @configuration_hash={:adapter=>"postgresql", :encoding=>"unicode", :host=>"localhost", :database=>"diaper_dev", :username=>"postgres", :password=>"postgres", :pool=>5, :timeout=>5000}> (NameError)

          establish_master_connection
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Did you mean?  establish_connection
/home/bandito/Projects/rfg-human-essentials-fork/config/initializers/postgres.rb:7:in `drop'
Tasks: TOP => db:drop:_unsafe
(See full trace by running task with --trace)

and works fine with the fix:

$ > rails db:reset
Dropped database 'diaper_dev'
Dropped database 'diaper_test'
Created database 'diaper_dev'
Created database 'diaper_test'
loading US counties and equivalents.
dorner commented 1 month ago

Thanks!

github-actions[bot] commented 1 month ago

@elasticspoon: Your PR fix(#4373): remove legacy postgres initializer is part of today's Human Essentials production release: 2024.05.26. Thank you very much for your contribution!