Class/Module Index [+]

Quicksearch

DeepTest::Database::MysqlSetupListener

SetupListener implementation for MySQL.

Attributes

admin_configuration[RW]

ActiveRecord configuration to use when connecting to MySQL to create databases, drop database, and grant privileges. By default, connects to information_schema on localhost as root with no password.

Public Instance Methods

create_database() click to toggle source

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
drop_database() click to toggle source

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
dump_file_name() click to toggle source

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
dump_schema() click to toggle source

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
grant_privileges(connection) click to toggle source

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
load_schema() click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.