lib/combustion/database/migrate.rb in combustion-0.7.0 vs lib/combustion/database/migrate.rb in combustion-0.8.0

- old
+ new

@@ -1,12 +1,16 @@ +# frozen_string_literal: true + class Combustion::Database::Migrate def self.call new.call end def call - if ActiveRecord::VERSION::STRING >= '3.1.0' + if ActiveRecord::VERSION::STRING.to_f >= 5.2 + migration_context.migrate + elsif ActiveRecord::VERSION::STRING.to_f >= 3.1 migrator.migrate paths, nil else paths.each { |path| migrator.migrate path, nil } end end @@ -15,26 +19,39 @@ def base_migration_paths if migrator.respond_to?(:migrations_paths) migrator.migrations_paths else - Array('db/migrate/') + Array("db/migrate/") end end + def engine_migration_paths + migration_paths = Rails.application.paths["db/migrate"].to_a + + if engine_paths_exist_in?(migration_paths) + migration_paths + else + base_migration_paths + migration_paths + end + end + + def engine_path + Rails.application.root.sub(::Combustion.path, "") + end + + def engine_paths_exist_in?(paths) + paths.include?(engine_path.join("db/migrate").to_s) + end + + def migration_context + ActiveRecord::MigrationContext.new paths + end + def migrator @migrator ||= ActiveRecord::Migrator end def paths - engine_path = Rails.application.root.sub(::Combustion.path, '') - migration_paths = Rails.application.paths['db/migrate'].to_a - - if migration_paths.include?(engine_path.join('db/migrate').to_s) - paths = [] - else - paths = base_migration_paths - end - - (paths + migration_paths + [File.join(Rails.root, 'db/migrate')]).uniq + (engine_migration_paths + [File.join(Rails.root, "db/migrate")]).uniq end end