Skip to content

Instantly share code, notes, and snippets.

@duncanbeevers
Created July 30, 2008 17:24
Show Gist options
  • Save duncanbeevers/3298 to your computer and use it in GitHub Desktop.
Save duncanbeevers/3298 to your computer and use it in GitHub Desktop.
namespace :db do
namespace :schema do
task :load => :alias_create_table
task :alias_create_table do
# WTF!
if /_test$/ === ActiveRecord::Base.connection.instance_variable_get('@connection_options')[3]
max_heap_table_size = 180 # Mb
ActiveRecord::Base.connection.execute("SET max_heap_table_size = #{max_heap_table_size} * 1024 * 1024")
module ActiveRecord::ConnectionAdapters::SchemaStatements
def create_table_with_memory_engine(table_name, options = {}, &block)
begin
new_options = options.merge(:options => 'ENGINE=MEMORY')
create_table_without_memory_engine(table_name, new_options, &block)
rescue
# Oops, try again
create_table_without_memory_engine(table_name, options, &block)
end
end
alias_method_chain :create_table, :memory_engine
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment