public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
PostgreSQL: Connect to template1 database when creating or dropping db

 * The template1 database is always available on a PostgreSQL install
 * The previous behavior expected a database with the same name as the
   connecting user, which may not be available

Signed-off-by: Michael Koziarski <michael@koziarski.com>

[#38 state:resolved]
fragility (author)
Tue Apr 22 13:23:17 -0700 2008
NZKoz (committer)
Sat May 03 17:20:14 -0700 2008
commit  205750c8dead2449a23173fab0720b7701231d2a
tree    10e133ee8db1c2e99b304ae6b0e88b178a54f7ea
parent  96980bd561d79824b6cb6efbcbecdcbf8785d452
...
45
46
47
48
 
49
50
51
...
373
374
375
376
 
377
378
379
...
45
46
47
 
48
49
50
51
...
373
374
375
 
376
377
378
379
0
@@ -45,7 +45,7 @@ namespace :db do
0
       when 'postgresql'
0
         @encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
0
         begin
0
-          ActiveRecord::Base.establish_connection(config.merge('database' => nil))
0
+          ActiveRecord::Base.establish_connection(config.merge('database' => 'template1'))
0
           ActiveRecord::Base.connection.create_database(config['database'], :encoding => @encoding)
0
           ActiveRecord::Base.establish_connection(config)
0
         rescue
0
@@ -373,7 +373,7 @@ def drop_database(config)
0
   when /^sqlite/
0
     FileUtils.rm(File.join(RAILS_ROOT, config['database']))
0
   when 'postgresql'
0
-    ActiveRecord::Base.establish_connection(config.merge('database' => nil))
0
+    ActiveRecord::Base.establish_connection(config.merge('database' => 'template1'))
0
     ActiveRecord::Base.connection.drop_database config['database']
0
   end
0
 end

Comments