Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

SQLite3 incorrectly reports database already exists on db:create

#6523

The problem I'm seeing is that rake db:create always reports "database already exists" on sqlite3 regardless of whether it does or not:

> rails new rails-test
> cd rails-test
> rake db:create
(in /Users/me/src/rails-test)
db/test.sqlite3 already exists
db/development.sqlite3 already exists
> rake db:drop
(in /Users/me/src/rails-test)
> rake db:create
db/test.sqlite3 already exists
db/development.sqlite3 already exists

The problem lies in databases.rake because all the other database attempt to connect and then actually create the database in the rescue clause thereby skipping the final else clause. Whereas SQLite3 is handled before the rescue clause so even when it successfully creates the database it still drops into the else clause on the last line of the create_databases method which prints database already exists. My suggested fix would be to put an unless on the puts:

    else
      $stderr.puts "#{config['database']} already exists" unless config['adapter'] =~ /sqlite/
    end

I'm on a Mac running Ruby 1.9.2p0.

Reported by Todd Huss · March 4th, 2011 @ 06:02 PM

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Todd Huss
    Todd Huss

    I should add that this issue is specific to all versions of Ruby 1.9.2 that I tested (including the latest 1.9.2p136). To see the problem in action:

    def return_still_calls_else 
      begin
        return
      rescue
        puts 'rescue'
      else
        puts 'else'
      end
    end
    
    return_still_calls_else
    

    In ruby 1.8 when you call this nothing gets printed but in ruby 1.9.2 it prints 'else' when you run it.

    March 4th, 2011 @ 07:09 PM