diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-04-03 11:12:06 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-04-03 11:12:54 -0300 |
commit | 7e6630329ec071d921b831f379364329ff6916e0 (patch) | |
tree | c6bcd9e6d752017e5ad99fd4da665e0937fc42c6 /activerecord/lib/active_record | |
parent | 3fafc1cc425b6e372cb372acf16d3d5bc8e1422d (diff) | |
parent | 0a99fddc140d8aa54a8922e745624a250877658b (diff) | |
download | rails-7e6630329ec071d921b831f379364329ff6916e0.tar.gz rails-7e6630329ec071d921b831f379364329ff6916e0.tar.bz2 rails-7e6630329ec071d921b831f379364329ff6916e0.zip |
Merge pull request #14569 from matthewd/sqlite_relative_deprecated
Revise 'sqlite3:' URL handling for smoother upgrades
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/connection_specification.rb | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index d60d31eda4..e0715f7ce9 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -35,7 +35,12 @@ module ActiveRecord @uri = URI.parse(url) @adapter = @uri.scheme @adapter = "postgresql" if @adapter == "postgres" - @query = @uri.query || '' + + if @uri.opaque + @uri.opaque, @query = @uri.opaque.split('?', 2) + else + @query = @uri.query + end end # Converts the given URL to a full connection hash. @@ -65,30 +70,38 @@ module ActiveRecord # "localhost" # # => {} def query_hash - Hash[@query.split("&").map { |pair| pair.split("=") }] + Hash[(@query || '').split("&").map { |pair| pair.split("=") }] end def raw_config - query_hash.merge({ - "adapter" => @adapter, - "username" => uri.user, - "password" => uri.password, - "port" => uri.port, - "database" => database, - "host" => uri.host }) + if uri.opaque + query_hash.merge({ + "adapter" => @adapter, + "database" => uri.opaque }) + else + query_hash.merge({ + "adapter" => @adapter, + "username" => uri.user, + "password" => uri.password, + "port" => uri.port, + "database" => database_from_path, + "host" => uri.host }) + end end # Returns name of the database. - # Sqlite3 expects this to be a full path or `:memory:`. - def database + def database_from_path if @adapter == 'sqlite3' - if '/:memory:' == uri.path - ':memory:' - else - uri.path - end + # 'sqlite3:/foo' is absolute, because that makes sense. The + # corresponding relative version, 'sqlite3:foo', is handled + # elsewhere, as an "opaque". + + uri.path else - uri.path.sub(%r{^/},"") + # Only SQLite uses a filename as the "database" name; for + # anything else, a leading slash would be silly. + + uri.path.sub(%r{^/}, "") end end end |