1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Revert "Change all databases.rake adapter 'when' statements to use regexes."

This reverts commit 3d2512d38d2e28b3ea669139f7c7b0307522aa72.
This commit is contained in:
Nick Sieger 2008-05-08 20:01:57 -07:00
parent 37b0b36918
commit 3151d96663

View file

@ -32,7 +32,7 @@ namespace :db do
ActiveRecord::Base.connection ActiveRecord::Base.connection
rescue rescue
case config['adapter'] case config['adapter']
when /mysql/ when 'mysql'
@charset = ENV['CHARSET'] || 'utf8' @charset = ENV['CHARSET'] || 'utf8'
@collation = ENV['COLLATION'] || 'utf8_general_ci' @collation = ENV['COLLATION'] || 'utf8_general_ci'
begin begin
@ -42,7 +42,7 @@ namespace :db do
rescue rescue
$stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation} (if you set the charset manually, make sure you have a matching collation)" $stderr.puts "Couldn't create database for #{config.inspect}, charset: #{config['charset'] || @charset}, collation: #{config['collation'] || @collation} (if you set the charset manually, make sure you have a matching collation)"
end end
when /postgresql/ when 'postgresql'
@encoding = config[:encoding] || ENV['CHARSET'] || 'utf8' @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
begin begin
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public')) ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
@ -52,9 +52,9 @@ namespace :db do
$stderr.puts $!, *($!.backtrace) $stderr.puts $!, *($!.backtrace)
$stderr.puts "Couldn't create database for #{config.inspect}" $stderr.puts "Couldn't create database for #{config.inspect}"
end end
when /sqlite$/ when 'sqlite'
`sqlite "#{config['database']}"` `sqlite "#{config['database']}"`
when /sqlite3$/ when 'sqlite3'
`sqlite3 "#{config['database']}"` `sqlite3 "#{config['database']}"`
end end
else else
@ -239,7 +239,7 @@ namespace :db do
task :dump => :environment do task :dump => :environment do
abcs = ActiveRecord::Base.configurations abcs = ActiveRecord::Base.configurations
case abcs[RAILS_ENV]["adapter"] case abcs[RAILS_ENV]["adapter"]
when /mysql/, /oci/, /oracle/ when "mysql", "oci", "oracle"
ActiveRecord::Base.establish_connection(abcs[RAILS_ENV]) ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump } File.open("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
when "postgresql" when "postgresql"
@ -250,13 +250,13 @@ namespace :db do
search_path = "--schema=#{search_path}" if search_path search_path = "--schema=#{search_path}" if search_path
`pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}` `pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}`
raise "Error dumping database" if $?.exitstatus == 1 raise "Error dumping database" if $?.exitstatus == 1
when /sqlite/ when "sqlite", "sqlite3"
dbfile = abcs[RAILS_ENV]["database"] || abcs[RAILS_ENV]["dbfile"] dbfile = abcs[RAILS_ENV]["database"] || abcs[RAILS_ENV]["dbfile"]
`#{abcs[RAILS_ENV]["adapter"]} #{dbfile} .schema > db/#{RAILS_ENV}_structure.sql` `#{abcs[RAILS_ENV]["adapter"]} #{dbfile} .schema > db/#{RAILS_ENV}_structure.sql`
when /sqlserver/ when "sqlserver"
`scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r` `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r`
`scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r` `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r`
when /firebird/ when "firebird"
set_firebird_env(abcs[RAILS_ENV]) set_firebird_env(abcs[RAILS_ENV])
db_string = firebird_db_string(abcs[RAILS_ENV]) db_string = firebird_db_string(abcs[RAILS_ENV])
sh "isql -a #{db_string} > #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql" sh "isql -a #{db_string} > #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql"
@ -285,13 +285,13 @@ namespace :db do
task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do task :clone_structure => [ "db:structure:dump", "db:test:purge" ] do
abcs = ActiveRecord::Base.configurations abcs = ActiveRecord::Base.configurations
case abcs["test"]["adapter"] case abcs["test"]["adapter"]
when /mysql/ when "mysql"
ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0') ActiveRecord::Base.connection.execute('SET foreign_key_checks = 0')
IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table| IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split("\n\n").each do |table|
ActiveRecord::Base.connection.execute(table) ActiveRecord::Base.connection.execute(table)
end end
when /postgresql/ when "postgresql"
ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"] ENV['PGHOST'] = abcs["test"]["host"] if abcs["test"]["host"]
ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"] ENV['PGPORT'] = abcs["test"]["port"].to_s if abcs["test"]["port"]
ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"] ENV['PGPASSWORD'] = abcs["test"]["password"].to_s if abcs["test"]["password"]
@ -301,12 +301,12 @@ namespace :db do
`#{abcs["test"]["adapter"]} #{dbfile} < #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql` `#{abcs["test"]["adapter"]} #{dbfile} < #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql`
when "sqlserver" when "sqlserver"
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql` `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
when /oci/, /oracle/ when "oci", "oracle"
ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.establish_connection(:test)
IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl| IO.readlines("#{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql").join.split(";\n\n").each do |ddl|
ActiveRecord::Base.connection.execute(ddl) ActiveRecord::Base.connection.execute(ddl)
end end
when /firebird/ when "firebird"
set_firebird_env(abcs["test"]) set_firebird_env(abcs["test"])
db_string = firebird_db_string(abcs["test"]) db_string = firebird_db_string(abcs["test"])
sh "isql -i #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{db_string}" sh "isql -i #{RAILS_ROOT}/db/#{RAILS_ENV}_structure.sql #{db_string}"
@ -319,7 +319,7 @@ namespace :db do
task :purge => :environment do task :purge => :environment do
abcs = ActiveRecord::Base.configurations abcs = ActiveRecord::Base.configurations
case abcs["test"]["adapter"] case abcs["test"]["adapter"]
when /mysql/ when "mysql"
ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"]) ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"])
when "postgresql" when "postgresql"
@ -329,16 +329,16 @@ namespace :db do
when "sqlite","sqlite3" when "sqlite","sqlite3"
dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"] dbfile = abcs["test"]["database"] || abcs["test"]["dbfile"]
File.delete(dbfile) if File.exist?(dbfile) File.delete(dbfile) if File.exist?(dbfile)
when /sqlserver/ when "sqlserver"
dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-') dropfkscript = "#{abcs["test"]["host"]}.#{abcs["test"]["database"]}.DP1".gsub(/\\/,'-')
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}` `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{dropfkscript}`
`osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql` `osql -E -S #{abcs["test"]["host"]} -d #{abcs["test"]["database"]} -i db\\#{RAILS_ENV}_structure.sql`
when /oci/, /oracle/ when "oci", "oracle"
ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl| ActiveRecord::Base.connection.structure_drop.split(";\n\n").each do |ddl|
ActiveRecord::Base.connection.execute(ddl) ActiveRecord::Base.connection.execute(ddl)
end end
when /firebird/ when "firebird"
ActiveRecord::Base.establish_connection(:test) ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.recreate_database! ActiveRecord::Base.connection.recreate_database!
else else
@ -372,9 +372,9 @@ end
def drop_database(config) def drop_database(config)
case config['adapter'] case config['adapter']
when /mysql/ when 'mysql'
ActiveRecord::Base.connection.drop_database config['database'] ActiveRecord::Base.connection.drop_database config['database']
when /sqlite/ when /^sqlite/
FileUtils.rm(File.join(RAILS_ROOT, config['database'])) FileUtils.rm(File.join(RAILS_ROOT, config['database']))
when 'postgresql' when 'postgresql'
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public')) ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))