提交 b2d70782 编写于 作者: J José Valim

Merge pull request #11763 from schneems/schneems/create-sqlite3db

Create sqlite3 directory if not present
* Create a directory for sqlite3 file if not present on the system.
*Richard Schneeman*
* Removed redundant override of `xml` column definition for PG,
in order to use `xml` column type instead of `text`.
......
......@@ -17,12 +17,14 @@ def sqlite3_connection(config)
# 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
)
......
# encoding: utf-8
require "cases/helper"
require 'models/owner'
module ActiveRecord
module ConnectionAdapters
class SQLite3CreateFolder < ActiveRecord::TestCase
def test_sqlite_creates_directory
Dir.mktmpdir do |dir|
dir = Pathname.new(dir)
@conn = Base.sqlite3_connection :database => dir.join("db/foo.sqlite3"),
:adapter => 'sqlite3',
:timeout => 100
assert Dir.exists? dir.join('db')
assert File.exist? dir.join('db/foo.sqlite3')
end
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册