Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error that undefined method `schema_format' in AR 7.1 #2300

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

matsubara0507
Copy link

Error occurred when invoke ar:migrate:redo in AR 7.1:

% bundle exec rake ar:migrate:redo MIGRATION_VERSION=1234
...
rake aborted!
NoMethodError: undefined method `schema_format' for ActiveRecord::Base:Class (NoMethodError)
/path/to/vendor/gems/ruby/3.2.0/gems/activerecord-7.1.5.1/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/path/to/vendor/gems/ruby/3.2.0/gems/padrino-gen-0.16.0.pre3/lib/padrino-gen/padrino-tasks/activerecord.rb:412:in `dump_schema'
/path/to/vendor/gems/ruby/3.2.0/gems/padrino-gen-0.16.0.pre3/lib/padrino-gen/padrino-tasks/activerecord.rb:394:in `migrate_as'
/path/to/vendor/gems/ruby/3.2.0/gems/padrino-gen-0.16.0.pre3/lib/padrino-gen/padrino-tasks/activerecord.rb:165:in `block (3 levels) in <top (required)>'
/path/to/vendor/gems/ruby/3.2.0/gems/padrino-gen-0.16.0.pre3/lib/padrino-gen/padrino-tasks/activerecord.rb:150:in `block (3 levels) in <top (required)>'
/path/to/vendor/gems/ruby/3.2.0/gems/rake-13.2.1/exe/rake:27:in `<top (required)>'
...

So I fixed it the same way as #2275

@jkowens
Copy link
Collaborator

jkowens commented Feb 5, 2025

It might be worth considering adding a method schema_format_ruby?:

def schema_format_ruby?
  schema_format = if less_than_active_record_7_0?
      ActiveRecord::Base.schema_format
  else
    ActiveRecord.schema_format
  end
  schema_format == :ruby
end

Then dump_schema would be:

def dump_schema
  Rake::Task["ar:schema:dump"].invoke if schema_format_ruby?
end

@matsubara0507
Copy link
Author

I Added schema_format_ruby?.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants