Skip to content

Commit 9efdd03

Browse files
zdennisicorson3
authored andcommitted
Update lib/migration_tools/tasks to work with Rails 6
which introduces a new way to pass around the SchemaMigration reference.
1 parent 2ebda86 commit 9efdd03

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

lib/migration_tools/tasks.rb

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,25 @@ def migrations_paths
2828
end
2929

3030
def migrator(target_version = nil)
31-
if ActiveRecord::VERSION::MAJOR > 3
32-
migrations = if defined?(::ActiveRecord::MigrationContext)
33-
ActiveRecord::MigrationContext.new(migrations_paths).migrations
34-
else
35-
ActiveRecord::Migrator.migrations(migrations_paths)
36-
end
37-
ActiveRecord::Migrator.new(:up, migrations, target_version)
31+
if ActiveRecord::VERSION::MAJOR >= 6
32+
migrate_up(ActiveRecord::MigrationContext.new(
33+
migrations_paths,
34+
ActiveRecord::SchemaMigration
35+
).migrations, target_version)
36+
elsif ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR == 2
37+
migrate_up(ActiveRecord::MigrationContext.new(migrations_paths).migrations, target_version)
38+
elsif ActiveRecord::VERSION::MAJOR > 3
39+
migrate_up(ActiveRecord::Migrator.migrations(migrations_paths), target_version)
3840
else
39-
ActiveRecord::Migrator.new(:up, migrations_paths, target_version)
41+
migrate_up(migrations_paths, target_version)
42+
end
43+
end
44+
45+
def migrate_up(migrations, target_version)
46+
if ActiveRecord::VERSION::MAJOR >= 6
47+
ActiveRecord::Migrator.new(:up, migrations, ActiveRecord::SchemaMigration, target_version)
48+
else
49+
ActiveRecord::Migrator.new(:up, migrations, target_version)
4050
end
4151
end
4252

0 commit comments

Comments
 (0)