widefix / actual_db_schema

Wipe out inconsistent DB and schema.rb when switching branches. To do that, install this gem and use the standard rake db:migrate command.
https://blog.widefix.com/actual-db-schema/
MIT License
295 stars 6 forks source link

Support latest edge rails refactor of connection -> connection_pool #58

Closed tvongaza closed 3 months ago

tvongaza commented 4 months ago

Running rails db:migrate when on edge rails gives the following trace:

rails db:migrate --trace           
** Invoke db:migrate (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke db:load_config 
** Invoke db:rollback_branches (first_time)
** Invoke db:load_config 
** Execute db:rollback_branches
bin/rails aborted!
NoMethodError: undefined method `migration_context' for an instance of ActiveRecord::ConnectionAdapters::PostgreSQLAdapter (NoMethodError)

          ActiveRecord::Base.connection.migration_context.tap do |c|
                                       ^^^^^^^^^^^^^^^^^^
/Users/tvongaza/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/actual_db_schema-0.7.3/lib/actual_db_schema/commands/base.rb:23:in `context'

https://github.com/rails/rails/pull/51162 refactors some of the inner workings of how database connections are handled, moving from a connection to a connection_pool. An example of this is the migration_context call, which this gem uses.

Prior to rails#51162 ActiveRecord::Base.connection.migration_context to after ActiveRecord::Base.connection_pool.migration_context.

The code in question (maybe more places): https://github.com/widefix/actual_db_schema/blob/main/lib/actual_db_schema/commands/base.rb#L23

This gem will need to be updated to support the new connection_pool, maybe worth considering adding edge rails to the Appraisals testing matrix as well.