class Combustion::Databases::MySQL
Constants
- ACCESS_DENIED_ERROR
Public Instance Methods
reset()
click to toggle source
Calls superclass method
Combustion::Databases::Base#reset
# File lib/combustion/databases/mysql.rb, line 6 def reset establish_connection(configuration.merge(:database => nil)) super end
Private Instance Methods
charset()
click to toggle source
# File lib/combustion/databases/mysql.rb, line 14 def charset configuration[:charset] || ENV["CHARSET"] || "utf8" end
charset_error()
click to toggle source
# File lib/combustion/databases/mysql.rb, line 18 def charset_error return "" unless configuration[:charset] "(if you set the charset manually, make sure you have a matching collation)" end
collation()
click to toggle source
# File lib/combustion/databases/mysql.rb, line 24 def collation configuration[:collation] || ENV["COLLATION"] || "utf8_unicode_ci" end
create()
click to toggle source
# File lib/combustion/databases/mysql.rb, line 28 def create connection.create_database configuration[:database], creation_options establish_connection configuration rescue error_class => error rescue_create_from error end
create_as_root(error)
click to toggle source
# File lib/combustion/databases/mysql.rb, line 35 def create_as_root(error) establish_connection configuration.merge( :database => nil, :username => "root", :password => request_password(error) ) connection.create_database configuration[:database], creation_options connection.execute grant_statement establish_connection configuration end
creation_options()
click to toggle source
# File lib/combustion/databases/mysql.rb, line 48 def creation_options {:charset => charset, :collation => collation} end
drop()
click to toggle source
# File lib/combustion/databases/mysql.rb, line 52 def drop connection.drop_database configuration[:database] end
error_class()
click to toggle source
# File lib/combustion/databases/mysql.rb, line 56 def error_class if configuration[:adapter][/jdbc/] # FIXME: After Jdbcmysql gives this class require "active_record/railties/jdbcmysql_error" ArJdbcMySQL::Error elsif configuration[:adapter][/mysql2/] && defined?(Mysql2) Mysql2::Error elsif configuration[:adapter][/trilogy/] && defined?(Trilogy) Trilogy::Error else Mysql::Error end end
grant_statement()
click to toggle source
# File lib/combustion/databases/mysql.rb, line 70 def grant_statement <<-SQL GRANT ALL PRIVILEGES ON #{configuration["database"]}.* TO '#{configuration[:username]}'@'localhost' IDENTIFIED BY '#{configuration[:password]}' WITH GRANT OPTION; SQL end
request_password(error)
click to toggle source
# File lib/combustion/databases/mysql.rb, line 78 def request_password(error) print <<-TXT.strip #{error.error}. Please provide the root password for your mysql installation > TXT $stdin.gets.strip end
rescue_create_from(error)
click to toggle source
# File lib/combustion/databases/mysql.rb, line 88 def rescue_create_from(error) if error.errno == ACCESS_DENIED_ERROR create_as_root(error) return end warn <<-TXT #{error.error} Couldn't create database for #{configuration.inspect}, charset: #{charset}, collation: #{collation} #{charset_error} TXT end