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
|
|
|
|
|
2017-08-07 05:11:11 -04:00
|
|
|
def reset_column_in_migration_models
|
|
|
|
described_class.constants.sort.each do |name|
|
|
|
|
const = described_class.const_get(name)
|
|
|
|
|
|
|
|
if const.is_a?(Class) && const < ActiveRecord::Base
|
|
|
|
const.reset_column_information
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-05 05:07:10 -04:00
|
|
|
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
|