Changeset 9183
- Timestamp:
- 04/01/08 05:01:33 (6 months ago)
- Files:
-
- trunk/railties/lib/tasks/databases.rake (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/railties/lib/tasks/databases.rake
r9170 r9183 6 6 # Skip entries that don't have a database key, such as the first entry here: 7 7 # 8 # defaults: &defaults 9 # adapter: mysql 8 # defaults: &defaults 9 # adapter: mysql 10 10 # username: root 11 # password: 11 # password: 12 12 # host: localhost 13 # 14 # development: 13 # 14 # development: 15 15 # database: blog_development 16 16 # <<: *defaults … … 37 37 @collation = ENV['COLLATION'] || 'utf8_general_ci' 38 38 begin 39 ActiveRecord::Base.establish_connection(config.merge( {'database' => nil}))40 ActiveRecord::Base.connection.create_database(config['database'], {:charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)})39 ActiveRecord::Base.establish_connection(config.merge('database' => nil)) 40 ActiveRecord::Base.connection.create_database(config['database'], :charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)) 41 41 ActiveRecord::Base.establish_connection(config) 42 42 rescue … … 44 44 end 45 45 when 'postgresql' 46 `createdb "#{config['database']}" -E utf8` 46 @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8' 47 begin 48 ActiveRecord::Base.establish_connection(config.merge('database' => nil)) 49 ActiveRecord::Base.connection.create_database(config['database'], :encoding => @encoding) 50 ActiveRecord::Base.establish_connection(config) 51 rescue 52 $stderr.puts $!, *($!.backtrace) 53 $stderr.puts "Couldn't create database for #{config.inspect}" 54 end 47 55 when 'sqlite' 48 56 `sqlite "#{config['database']}"` … … 51 59 end 52 60 else 53 p"#{config['database']} already exists"61 $stderr.puts "#{config['database']} already exists" 54 62 end 55 63 end … … 99 107 desc 'Resets your database using your migrations for the current environment' 100 108 task :reset => ["db:drop", "db:create", "db:migrate"] 101 109 102 110 desc 'Runs the "up" for a given migration VERSION.' 103 111 task :up => :environment do … … 114 122 ActiveRecord::Migrator.run(:down, "db/migrate/", version) 115 123 Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby 116 end 124 end 117 125 end 118 126 … … 180 188 end 181 189 end 182 190 183 191 desc "Search for a fixture given a LABEL or ID." 184 192 task :identify => :environment do … … 187 195 label, id = ENV["LABEL"], ENV["ID"] 188 196 raise "LABEL or ID required" if label.blank? && id.blank? 189 197 190 198 puts %Q(The fixture ID for "#{label}" is #{Fixtures.identify(label)}.) if label 191 199 192 200 Dir["#{RAILS_ROOT}/test/fixtures/**/*.yml"].each do |file| 193 201 if data = YAML::load(ERB.new(IO.read(file)).result) 194 202 data.keys.each do |key| 195 203 key_id = Fixtures.identify(key) 196 204 197 205 if key == label || key_id == id.to_i 198 206 puts "#{file}: #{key} (#{key_id})" … … 366 374 FileUtils.rm(File.join(RAILS_ROOT, config['database'])) 367 375 when 'postgresql' 368 ActiveRecord::Base. clear_active_connections!369 `dropdb "#{config['database']}"`376 ActiveRecord::Base.establish_connection(config.merge('database' => nil)) 377 ActiveRecord::Base.connection.drop_database config['database'] 370 378 end 371 379 end