Skip to content

Commit

Permalink
Deprecate use of whitespace to split schema/table name
Browse files Browse the repository at this point in the history
Addresses rails#26721
  • Loading branch information
Jerph committed Oct 6, 2016
1 parent bf5876a commit b129fe2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Expand Up @@ -69,7 +69,21 @@ def extract_schema_qualified_name(string)
table = schema
schema = nil
end
PostgreSQL::Name.new(schema, table)

name = PostgreSQL::Name.new(schema, table)

if schema
# split happened, did it happen because of spaces in an unquoted string? See #26721
if !string.include?(".") && string =~ /\s/
ActiveSupport::Deprecation.warn(<<-MSG.squish)
Specifying schema with a space is deprecated.
Please use dot syntax: #{"'\"#{name.schema}\".\"#{name.identifier}\"'"}
To use spaces in a table name, use quotes: #{"'\"#{string}\"'"}
MSG
end
end

name
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion activerecord/test/cases/adapters/postgresql/utils_test.rb
Expand Up @@ -15,10 +15,20 @@ def test_extract_schema_qualified_name
%("schema"."table_name") => %w{schema table_name},
%("even spaces".table) => ["even spaces","table"],
%(schema."table.name") => ["schema", "table.name"]

}.each do |given, expect|
assert_equal Name.new(*expect), extract_schema_qualified_name(given)
assert_not_deprecated {
assert_equal Name.new(*expect), extract_schema_qualified_name(given)
}
end
end

def test_extract_schema_qualified_name_deprecated
assert_deprecated {
assert_equal Name.new("schema", "table_name"), extract_schema_qualified_name("schema table_name")
assert_equal Name.new("schema", "table_name"), extract_schema_qualified_name("schema \t table_name")
}
end
end

class PostgreSQLNameTest < ActiveRecord::PostgreSQLTestCase
Expand Down

0 comments on commit b129fe2

Please sign in to comment.