From f036239447c79843983ee1c0d3dfe68484d63203 Mon Sep 17 00:00:00 2001 From: schneems Date: Mon, 5 Aug 2013 11:12:12 -0400 Subject: Create sqlite3 directory if not present If the `db/` directory is not present on a remote machine it will blow up in unexpected ways with error messages that do not indicate there is a missing directory: ``` SQLite3::CantOpenException: unable to open database file ``` This PR checks to see if a directory exists for the sqlite3 file and if not creates it for you. This PR is an alternative to #11692 as suggested by @josevalim --- .../lib/active_record/connection_adapters/sqlite3_adapter.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters') diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 7d940fe1c9..16306a78cf 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -17,12 +17,14 @@ module ActiveRecord # Allow database path relative to Rails.root, but only if # the database path is not the special path that tells # Sqlite to build a database only in memory. - if defined?(Rails.root) && ':memory:' != config[:database] - config[:database] = File.expand_path(config[:database], Rails.root) + if ':memory:' != config[:database] + config[:database] = Pathname.new(config[:database]) + config[:database] = config[:database].expand_path(Rails.root) if defined?(Rails.root) + config[:database].dirname.mkdir unless config[:database].dirname.directory? end db = SQLite3::Database.new( - config[:database], + config[:database].to_s, :results_as_hash => true ) -- cgit v1.2.3