Module: Switchman::ActiveRecord::MigrationContext

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

Instance Method Summary collapse

Instance Method Details

#migrateObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/switchman/active_record/migration.rb', line 53

def migrate(...)
  connection = ::ActiveRecord::Base.connection
  schema_cache_holder = ::ActiveRecord::Base.connection_pool
  schema_cache_holder = schema_cache_holder.schema_reflection if ::Rails.version >= "7.1"
  previous_schema_cache = if ::Rails.version < "7.1"
                            schema_cache_holder.get_schema_cache(connection)
                          else
                            schema_cache_holder.instance_variable_get(:@cache)
                          end

  if ::Rails.version < "7.1"
    temporary_schema_cache = ::ActiveRecord::ConnectionAdapters::SchemaCache.new(connection)

    reset_column_information
    schema_cache_holder.set_schema_cache(temporary_schema_cache)
  else
    schema_cache_holder.instance_variable_get(:@cache)

    reset_column_information
    schema_cache_holder.clear!
  end

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

#migrationsObject



83
84
85
86
87
88
89
# File 'lib/switchman/active_record/migration.rb', line 83

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