Module: Switchman::ActiveRecord::MigrationContext

Defined in:
lib/switchman/active_record/migration.rb

Instance Method Summary collapse

Instance Method Details

#migrateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/switchman/active_record/migration.rb', line 49

def migrate(...)
  connection = ::ActiveRecord::Base.connection
  connection_pool = ::ActiveRecord::Base.connection_pool
  previous_schema_cache = connection_pool.get_schema_cache(connection)
  temporary_schema_cache = ::ActiveRecord::ConnectionAdapters::SchemaCache.new(connection)

  reset_column_information
  connection_pool.set_schema_cache(temporary_schema_cache)

  begin
    super(...)
  ensure
    connection_pool.set_schema_cache(previous_schema_cache)
    reset_column_information
  end
end

#migrationsObject



66
67
68
69
70
71
72
# File 'lib/switchman/active_record/migration.rb', line 66

def migrations
  return @migrations if instance_variable_defined?(:@migrations)

  migrations_cache = Thread.current[:migrations_cache] ||= {}
  key = Digest::MD5.hexdigest(migration_files.sort.join(","))
  @migrations = migrations_cache[key] ||= super
end