2 desc 'Build the MySQL test databases'
3 task :build_databases => :load_connection do
4 puts File.join(SCHEMA_PATH, 'mysql.sql')
5 options_str = ENV['cpk_adapter_options_str']
6 # creates something like "-u#{username} -p#{password} -S#{socket}"
7 sh %{ mysqladmin #{options_str} create "#{GEM_NAME}_unittest" }
8 sh %{ mysql #{options_str} "#{GEM_NAME}_unittest" < #{File.join(SCHEMA_PATH, 'mysql.sql')} }
11 desc 'Drop the MySQL test databases'
12 task :drop_databases => :load_connection do
13 options_str = ENV['cpk_adapter_options_str']
14 sh %{ mysqladmin #{options_str} -f drop "#{GEM_NAME}_unittest" }
17 desc 'Rebuild the MySQL test databases'
18 task :rebuild_databases => [:drop_databases, :build_databases]
20 task :load_connection do
21 require File.join(PROJECT_ROOT, %w[lib adapter_helper mysql])
22 spec = AdapterHelper::MySQL.load_connection_from_env
24 options['u'] = spec[:username] if spec[:username]
25 options['p'] = spec[:password] if spec[:password]
26 options['S'] = spec[:sock] if spec[:sock]
27 options_str = options.map { |key, value| "-#{key}#{value}" }.join(" ")
28 ENV['cpk_adapter_options_str'] = options_str