This project is archived and is in readonly mode.

#6523 new
Todd Huss

SQLite3 incorrectly reports database already exists on db:create

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

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.

Comments and changes to this ticket

  • Todd Huss

    Todd Huss March 4th, 2011 @ 07:09 PM

    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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages