public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fix for SQLite's db creation warnings [status:committed #614]

Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
acangiano (author)
Sun Jul 13 08:49:05 -0700 2008
dhh (committer)
Tue Sep 09 21:56:37 -0700 2008
commit  854cf3d7213a62792051b58032a3a9a1b2ebc45d
tree    7db9c0d27a76767893894b129e8293fee7fb7a93
parent  567392bff32acd5cf357565415d33c2662004cf5
...
28
29
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
34
35
...
52
53
54
55
56
57
58
59
60
61
...
28
29
30
 
 
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
...
68
69
70
 
 
 
 
71
72
73
0
@@ -28,8 +28,24 @@ namespace :db do
0
 
0
   def create_database(config)
0
     begin
0
-      ActiveRecord::Base.establish_connection(config)
0
-      ActiveRecord::Base.connection
0
+      if config['adapter'] =~ /sqlite/
0
+        if File.exist?(config['database'])
0
+          $stderr.puts "#{config['database']} already exists"
0
+        else
0
+          begin
0
+            # Create the SQLite database
0
+            ActiveRecord::Base.establish_connection(config)
0
+            ActiveRecord::Base.connection
0
+          rescue
0
+            $stderr.puts $!, *($!.backtrace)
0
+            $stderr.puts "Couldn't create database for #{config.inspect}"
0
+          end
0
+        end
0
+        return # Skip the else clause of begin/rescue    
0
+      else
0
+        ActiveRecord::Base.establish_connection(config)
0
+        ActiveRecord::Base.connection
0
+      end
0
     rescue
0
       case config['adapter']
0
       when 'mysql'
0
@@ -52,10 +68,6 @@ namespace :db do
0
           $stderr.puts $!, *($!.backtrace)
0
           $stderr.puts "Couldn't create database for #{config.inspect}"
0
         end
0
-      when 'sqlite'
0
-        `sqlite "#{config['database']}"`
0
-      when 'sqlite3'
0
-        `sqlite3 "#{config['database']}"`
0
       end
0
     else
0
       $stderr.puts "#{config['database']} already exists"

Comments