Testing Rails Blocks with MyISAM Tables

I have an application that requires the use of MyISAM on several tables, but the rest is the traditional type of InnoDB. The application itself is not transactional, where it is applied to these records, but performance is a problem.

In the Rails testing environment, it is assumed that the engine used is transactional, so when the test database is created from schema.rb, it is imported with the same engine. Is excessive behavior of this behavior possible?

I resorted to a terrible hack to provide the correct type of tables by adding 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 model that supports MyISAM validation?

+3
source share
4 answers

You can edit your schema.rb and modify the create_table call to include the following flag:

create_table(:suppliers, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8')

When you create your migrations, try adding this to the migration. I don't know if this will work when you run rake db: schema: dump. Given your experience that the test environment does not seem to copy the development environment correctly, it may not be: (

More about create_table options here:

http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#M001901

+4
source

you can set

self.use_transactional_fixtures = false

in test_helper.rb

+2
source

application.rb:

config.active_record.schema_format = :sql

db rake db:test:prepare. ( InnoDB MyISAM), up:

execute("ALTER TABLE your_table ENGINE=MyISAM")
+2

You can add this Monkeypatch SchemaDumper to add the engine explicitly to your schema.rb

https://gist.github.com/1374003

This is monkeypatched from Rails 2.3.14, so no guarantees with Rails 3

+1
source

Source: https://habr.com/ru/post/1740627/


All Articles