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.

Sqlite errors when using dbfile directive in database.yml

#2363

Hi there!

So, after many hours of debugging why my script/dbconsole wouldn't run, I've discovered that I was using the dbfile directive in my database.yml. eg:


development:
  adapter: sqlite3
  dbfile: db/development.db

This makes script/dbconsole crash with the following message:


/opt/local/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/dbconsole.rb:80:in `exec': can't convert nil into String (TypeError)
	from /opt/local/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/commands/dbconsole.rb:80
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
	from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
	from script/dbconsole:3

Changing to use the 'database' directive fixes this problem. Is there any reason the 'dbfile' directive is still around? Is this really a bug in the sqlite-ruby gem?

First time bug reporting, so I'm sure I'm doing things wrong. Let me know where to start if I need to do tests/patches/whatnot.

david

Reported by David Kelso · March 27th, 2009 @ 08:40 PM

State: resolved
Milestone: 2.3.4
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. Paul Hinze
    Paul Hinze
    • Assigned user set to Jeremy Kemper
    • Tag changed from 2.3.2, database, database.yml, sqlite to 2-3-stable, 2.3.2, database, database.yml, dbfile, railties, sqlite, sqlite3

    I just found a related issue with using rake db:drop given a SQLite database.

    The related block of code from railties/lib/tasks/databases.rake:

      def drop_database(config)
        case config['adapter']
        # ...
        when /^sqlite/
          FileUtils.rm(File.join(RAILS_ROOT, config['database']))
        # ...
        end
      end
    

    If this is called when only the dbfile config option is provided, you get an error as you'd expect:

    Couldn't drop : #<TypeError: can't convert nil into String>

    Looked in 2-3-stable and it seems like there are some places where both are supported and others (like the two mentioned here) where only the database key is used.

    The way forward it seems it to be one of these two options:

    1. officially deprecate dbfile and therefore include code to warn users of this fact
    2. ensure support for dbfile everywhere the database config option is used

    I've attached a patch against 2-3-stable that should fix the two issues mentioned in this ticket, but making the above decision is more important for this ticket.

    Assigning to the last committer to the line in question for databases.rake just to have someone listed.

    May 13th, 2009 @ 03:51 PM

  2. Jeremy Kemper
  3. David Kelso
    David Kelso

    Great! Thanks for solving this!

    August 4th, 2009 @ 01:08 AM