ilyakatz / data-migrate

Migrate and update data alongside your database structure.
MIT License
1.4k stars 192 forks source link

fix for `rails g data_migration` with multiple data migration paths #315

Open braindeaf opened 2 months ago

braindeaf commented 2 months ago

The proposed solution for Rails engines with multiple data migration paths causes a side-effect.

https://github.com/ilyakatz/data-migrate/issues/314

module EngineName
  class Engine < ::Rails::Engine
    initializer :engine_name do |app|
      ::DataMigrate.configure do |data_migrate|
        default_path = ::DataMigrate::Config.new.data_migrations_path
        data_migrate.data_migrations_path = [default_path, root.join('db', 'data')]
      end
    end
  end
end

The resulting migration file path is made up of all of the paths names so in our case it was ./db/data/engines/db/data/engines/something/db/data. This fix just picks the first path ie. the application's db/data path.

Hope this is helpful.