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
65
66
67
68
69
# File 'lib/switchman/active_record/migration.rb', line 49

def migrate(...)
  schema_cache_holder = ::ActiveRecord::Base.connection_pool
  schema_cache_holder = schema_cache_holder.schema_reflection
  previous_schema_cache = schema_cache_holder.instance_variable_get(:@cache)

  schema_cache_holder.instance_variable_get(:@cache)

  reset_column_information
  schema_cache_holder.clear!

  begin
    super
  ensure
    if ::Rails.version < "7.2"
      schema_cache_holder.set_schema_cache(previous_schema_cache)
    else
      schema_cache_holder.instance_variable_set(:@cache, previous_schema_cache)
    end
    reset_column_information
  end
end

#migrationsObject



71
72
73
74
75
76
77
# File 'lib/switchman/active_record/migration.rb', line 71

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