mirror of https://github.com/rails/rails
[FIX] Sqlite3 Should create db for missing parent directories as well
This commit is contained in:
parent
0a3a578801
commit
fd94a129d1
|
@ -112,13 +112,9 @@ module ActiveRecord
|
|||
dirname = File.dirname(@config[:database])
|
||||
unless File.directory?(dirname)
|
||||
begin
|
||||
Dir.mkdir(dirname)
|
||||
rescue Errno::ENOENT => error
|
||||
if error.message.include?("No such file or directory")
|
||||
raise ActiveRecord::NoDatabaseError.new(connection_pool: @pool)
|
||||
else
|
||||
raise
|
||||
end
|
||||
FileUtils.mkdir_p(dirname)
|
||||
rescue SystemCallError
|
||||
raise ActiveRecord::NoDatabaseError.new(connection_pool: @pool)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,12 +23,14 @@ module ActiveRecord
|
|||
)
|
||||
end
|
||||
|
||||
def test_bad_connection
|
||||
error = assert_raise ActiveRecord::NoDatabaseError do
|
||||
connection = SQLite3Adapter.new(adapter: "sqlite3", database: "/tmp/should/_not/_exist/-cinco-dog.db")
|
||||
def test_database_should_get_created_when_missing_parent_directories_for_database_path
|
||||
dir = Dir.mktmpdir
|
||||
db_path = File.join(dir, "_not_exist/-cinco-dog.sqlite3")
|
||||
assert_nothing_raised do
|
||||
connection = SQLite3Adapter.new(adapter: "sqlite3", database: db_path)
|
||||
connection.drop_table "ex", if_exists: true
|
||||
end
|
||||
assert_kind_of ActiveRecord::ConnectionAdapters::NullPool, error.connection_pool
|
||||
assert SQLite3Adapter.database_exists?(adapter: "sqlite3", database: db_path)
|
||||
end
|
||||
|
||||
def test_database_exists_returns_false_when_the_database_does_not_exist
|
||||
|
|
Loading…
Reference in New Issue