Fix: delegate structure_dump_flags and structure_load_flags to ActiveRecord#371
Open
granti wants to merge 1 commit intoilyakatz:mainfrom
Open
Fix: delegate structure_dump_flags and structure_load_flags to ActiveRecord#371granti wants to merge 1 commit intoilyakatz:mainfrom
granti wants to merge 1 commit intoilyakatz:mainfrom
Conversation
…Record When DataMigrate::DatabaseTasks extends ActiveRecord::Tasks::DatabaseTasks, the mattr_accessor methods (structure_dump_flags and structure_load_flags) are not properly inherited because they store values on the original module. This causes a NameError when db:prepare:with_data calls dump_schema, which internally calls structure_dump_flags_for that tries to access these accessors: NameError: undefined local variable or method 'structure_dump_flags' for module primary This fix adds delegation methods that forward calls to the original ActiveRecord::Tasks::DatabaseTasks module. Fixes issue when using db:prepare:with_data with structure.sql format in Rails 7.2+.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: delegate structure_dump_flags and structure_load_flags to ActiveRecord
Problem
When running
rails db:prepare:with_datawithstructure.sqlformat on Rails 7.2+, the following error occurs:Root Cause
DataMigrate::DatabaseTasksusesextend ActiveRecord::Tasks::DatabaseTasksto copy methods from ActiveRecord. However,structure_dump_flagsandstructure_load_flagsare defined asmattr_accessoron the original module, which stores values onActiveRecord::Tasks::DatabaseTasksitself.When
dump_schemais called fromDataMigrate::DatabaseTasks, it internally callsstructure_dump_flags_for, which tries to accessstructure_dump_flags- but that accessor doesn't exist onDataMigrate::DatabaseTasks.Solution
Add delegation methods that forward calls to the original
ActiveRecord::Tasks::DatabaseTasksmodule:Testing
Reproduction Steps
config.active_record.schema_format = :sqldata_migrategemrails db:prepare:with_dataAfter this fix, the command completes successfully.