SetupListener implementation for MySQL.
Creates database and grants privileges (via grant_privileges) on it via ActiveRecord connection based on admin_configuration.
# File lib/deep_test/database/mysql_setup_listener.rb, line 27 def create_database admin_connection do |connection| connection.create_database worker_database grant_privileges connection end end
Drops database via ActiveRecord connection based on admin_configuration
# File lib/deep_test/database/mysql_setup_listener.rb, line 52 def drop_database admin_connection do |connection| connection.drop_database worker_database end end
Location to store dumpfile. The default assumes you are testing a Rails project. You should override this if you are not using Rails or would like the dump file to be something other than the default
# File lib/deep_test/database/mysql_setup_listener.rb, line 81 def dump_file_name "#{RAILS_ROOT}/db/deep_test_schema.sql" end
Dumps schema from master database using mysqldump command
# File lib/deep_test/database/mysql_setup_listener.rb, line 61 def dump_schema config = command_line_config(master_database_config) system "mysqldump -R #{config} > #{dump_file_name}" raise "Error Dumping schema" unless $?.success? end
Grants 'all' privilege on worker database to username and password specified by worker database config. If your application has special database privilege needs beyond 'all', you should override this method and grant them.
# File lib/deep_test/database/mysql_setup_listener.rb, line 40 def grant_privileges(connection) sql = %{grant all on #{worker_database}.* to %s@'localhost' identified by %s;} % [ connection.quote(worker_database_config[:username]), connection.quote(worker_database_config[:password]) ] connection.execute sql end
Loads dumpfile into worker database using mysql command
# File lib/deep_test/database/mysql_setup_listener.rb, line 70 def load_schema config = command_line_config(worker_database_config) system "mysql #{config} < #{dump_file_name}" raise "Error Loading schema" unless $?.success? end
Generated with the Darkfish Rdoc Generator 2.