Sha256: 968fb7b2c8d1315b27e6c25833ad39a36b7938d5ab9553169bcf566a0a574449
Contents?: true
Size: 1.94 KB
Versions: 31
Compression:
Stored size: 1.94 KB
Contents
def create_database(config) begin if config['adapter'] =~ /sqlite/ if File.exist?(config['database']) $stderr.puts "#{config['database']} already exists" else begin # Create the SQLite database ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection rescue $stderr.puts $!, *($!.backtrace) $stderr.puts "Couldn't create database for #{config.inspect}" end end return # Skip the else clause of begin/rescue else ActiveRecord::Base.establish_connection(config) ActiveRecord::Base.connection end rescue case config['adapter'] when 'mysql' @charset = ENV['CHARSET'] || 'utf8' @collation = ENV['COLLATION'] || 'utf8_unicode_ci' begin ActiveRecord::Base.establish_connection(config.merge('database' => nil)) ActiveRecord::Base.connection.create_database(config['database'], :charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)) ActiveRecord::Base.establish_connection(config) 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)" end when 'postgresql' @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8' begin ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public')) ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding)) ActiveRecord::Base.establish_connection(config) rescue $stderr.puts $!, *($!.backtrace) $stderr.puts "Couldn't create database for #{config.inspect}" end end else $stderr.puts "#{config['database']} already exists" end end
Version data entries
31 entries across 31 versions & 1 rubygems