]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/composite_primary_keys-2.2.2/tasks/databases/mysql.rake
While we don't have the sanitizing backend to safely solve ticket
[rails.git] / vendor / gems / composite_primary_keys-2.2.2 / tasks / databases / mysql.rake
1 namespace :mysql do
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')} }
9   end
10
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" }
15   end
16
17   desc 'Rebuild the MySQL test databases'
18   task :rebuild_databases => [:drop_databases, :build_databases]
19   
20   task :load_connection do
21     require File.join(PROJECT_ROOT, %w[lib adapter_helper mysql])
22     spec = AdapterHelper::MySQL.load_connection_from_env
23     options = {}
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
29   end
30 end