mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Support any mysql-like adapter
This commit is contained in:
parent
2eaae1f50b
commit
b07e6fdaa0
1 changed files with 7 additions and 7 deletions
|
@ -57,7 +57,7 @@ namespace :db do
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
case config['adapter']
|
case config['adapter']
|
||||||
when 'mysql'
|
when /mysql/
|
||||||
@charset = ENV['CHARSET'] || 'utf8'
|
@charset = ENV['CHARSET'] || 'utf8'
|
||||||
@collation = ENV['COLLATION'] || 'utf8_unicode_ci'
|
@collation = ENV['COLLATION'] || 'utf8_unicode_ci'
|
||||||
creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
|
creation_options = {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)}
|
||||||
|
@ -224,7 +224,7 @@ namespace :db do
|
||||||
task :charset => :environment do
|
task :charset => :environment do
|
||||||
config = ActiveRecord::Base.configurations[Rails.env || 'development']
|
config = ActiveRecord::Base.configurations[Rails.env || 'development']
|
||||||
case config['adapter']
|
case config['adapter']
|
||||||
when 'mysql'
|
when /mysql/
|
||||||
ActiveRecord::Base.establish_connection(config)
|
ActiveRecord::Base.establish_connection(config)
|
||||||
puts ActiveRecord::Base.connection.charset
|
puts ActiveRecord::Base.connection.charset
|
||||||
when 'postgresql'
|
when 'postgresql'
|
||||||
|
@ -242,7 +242,7 @@ namespace :db do
|
||||||
task :collation => :environment do
|
task :collation => :environment do
|
||||||
config = ActiveRecord::Base.configurations[Rails.env || 'development']
|
config = ActiveRecord::Base.configurations[Rails.env || 'development']
|
||||||
case config['adapter']
|
case config['adapter']
|
||||||
when 'mysql'
|
when /mysql/
|
||||||
ActiveRecord::Base.establish_connection(config)
|
ActiveRecord::Base.establish_connection(config)
|
||||||
puts ActiveRecord::Base.connection.collation
|
puts ActiveRecord::Base.connection.collation
|
||||||
else
|
else
|
||||||
|
@ -343,7 +343,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"
|
||||||
|
@ -391,7 +391,7 @@ 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|
|
||||||
|
@ -425,7 +425,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"], abcs["test"])
|
ActiveRecord::Base.connection.recreate_database(abcs["test"]["database"], abcs["test"])
|
||||||
when "postgresql"
|
when "postgresql"
|
||||||
|
@ -481,7 +481,7 @@ task 'test:prepare' => 'db:test:prepare'
|
||||||
|
|
||||||
def drop_database(config)
|
def drop_database(config)
|
||||||
case config['adapter']
|
case config['adapter']
|
||||||
when 'mysql'
|
when /mysql/
|
||||||
ActiveRecord::Base.establish_connection(config)
|
ActiveRecord::Base.establish_connection(config)
|
||||||
ActiveRecord::Base.connection.drop_database config['database']
|
ActiveRecord::Base.connection.drop_database config['database']
|
||||||
when /^sqlite/
|
when /^sqlite/
|
||||||
|
|
Loading…
Reference in a new issue