2017-05-26 04:36:01 -04:00
|
|
|
module MigrationsHelpers
|
|
|
|
def table(name)
|
|
|
|
Class.new(ActiveRecord::Base) { self.table_name = name }
|
|
|
|
end
|
|
|
|
|
|
|
|
def migrations_paths
|
|
|
|
ActiveRecord::Migrator.migrations_paths
|
|
|
|
end
|
|
|
|
|
2017-05-26 08:46:45 -04:00
|
|
|
def table_exists?(name)
|
|
|
|
ActiveRecord::Base.connection.table_exists?(name)
|
|
|
|
end
|
|
|
|
|
2017-06-05 05:07:10 -04:00
|
|
|
def migrations
|
|
|
|
ActiveRecord::Migrator.migrations(migrations_paths)
|
|
|
|
end
|
|
|
|
|
|
|
|
def previous_migration
|
|
|
|
migrations.each_cons(2) do |previous, migration|
|
|
|
|
break previous if migration.name == described_class.name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-26 04:36:01 -04:00
|
|
|
def migrate!
|
|
|
|
ActiveRecord::Migrator.up(migrations_paths) do |migration|
|
|
|
|
migration.name == described_class.name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|