database_cleaner icon indicating copy to clipboard operation
database_cleaner copied to clipboard

edge rails (future 7.1) no longer has ActiveRecord::SchemaMigration.table_name

Open jrochkind opened this issue 2 years ago • 0 comments

Current edge rails (future Rails 7.1) produces an error from cleaning in :truncation or :deletion strategies, due to ActiveRecord::SchemaMigration.table_name apparently being removed.

eg

Failure/Error: DatabaseCleaner.clean_with(:truncation)

       NoMethodError:
         undefined method `table_name' for ActiveRecord::SchemaMigration:Class
       # /Users/jrochkind/.gem/ruby/3.0.4/gems/database_cleaner-1.99.0/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/base.rb:73:in `migration_table_name'
       # /Users/jrochkind/.gem/ruby/3.0.4/gems/database_cleaner-1.99.0/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/truncation.rb:271:in `migration_storage_names'
       # /Users/jrochkind/.gem/ruby/3.0.4/gems/database_cleaner-1.99.0/lib/database_cleaner/generic/truncation.rb:14:in `initialize'
       # /Users/jrochkind/.gem/ruby/3.0.4/gems/database_cleaner-1.99.0/adapters/database_cleaner-active_record/lib/database_cleaner/active_record/truncation.rb:238:in `initialize'
       # /Users/jrochkind/.gem/ruby/3.0.4/gems/database_cleaner-1.99.0/lib/database_cleaner/base.rb:128:in `new'
       # /Users/jrochkind/.gem/ruby/3.0.4/gems/database_cleaner-1.99.0/lib/database_cleaner/base.rb:128:in `create_strategy'
       # /Users/jrochkind/.gem/ruby/3.0.4/gems/database_cleaner-1.99.0/lib/database_cleaner/base.rb:75:in `clean_with'
       # /Users/jrochkind/.gem/ruby/3.0.4/gems/database_cleaner-1.99.0/lib/database_cleaner/configuration.rb:93:in `block in clean_with'
       # /Users/jrochkind/.gem/ruby/3.0.4/gems/database_cleaner-1.99.0/lib/database_cleaner/configuration.rb:93:in `each'
       # /Users/jrochkind/.gem/ruby/3.0.4/gems/database_cleaner-1.99.0/lib/database_cleaner/configuration.rb:93:in `clean_with'```

It think possibly this this is the commit where it moved, but still wrapping my head around it: https://github.com/rails/rails/commit/436277da88507f9aae0874e62f3e61a8546b9683. Hm, it looks like maybe instead of being a class method, SchemaMigration now has to be initialized as an instance with a particular connection to get a table name... this seems unclear how to patch in DC.

It looks like similar things have happened in the past that effected database_cleaner, eg https://github.com/DatabaseCleaner/database_cleaner/issues/476

I run my CI on edge rails to get early notice of anything that will break it... or in this case, early notice of something that broke database_cleaner, preventing me from running my CI on rails edge at present!

jrochkind avatar Sep 12 '22 18:09 jrochkind