Rails Unit Testing with MyISAM Tables

Posted by tadman on Stack Overflow See other posts from Stack Overflow or by tadman
Published on 2010-04-11T05:49:15Z Indexed on 2010/04/11 5:53 UTC
Read the original article Hit count: 313

I've got an application that requires the use of MyISAM on a few tables, but the rest are the traditional InnoDB type. The application itself is not concerned with transactions where it applies to these records, but performance is a concern.

The Rails testing environment assumes the engine used is transactional, though, so when the test database is generated from the schema.rb it is imported with the same engine. Is it possible to over-ride this behaviour in a simple manner?

I've resorted to an awful hack to ensure the tables are the correct type by appending this to test_helper.rb:

(ActiveRecord::Base.connection.select_values("SHOW TABLES") - %w[ schema_info ]).each do |table_name|
  ActiveRecord::Base.connection.execute("ALTER TABLE `#{table_name}` ENGINE=InnoDB")
end

Is there a better way to make a MyISAM-backed model be testable?

© Stack Overflow or respective owner

Related posts about myisam

Related posts about unit-testing