-
Notifications
You must be signed in to change notification settings - Fork 21.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19978 from kamipo/collation_option_support_for_po…
…stgresql PostgreSQL: `:collation` support for string and text columns
- Loading branch information
Showing
10 changed files
with
116 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
activerecord/test/cases/adapters/postgresql/collation_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require "cases/helper" | ||
require 'support/schema_dumping_helper' | ||
|
||
class PostgresqlCollationTest < ActiveRecord::TestCase | ||
include SchemaDumpingHelper | ||
|
||
def setup | ||
@connection = ActiveRecord::Base.connection | ||
@connection.create_table :postgresql_collations, force: true do |t| | ||
t.string :string_c, collation: 'C' | ||
t.text :text_posix, collation: 'POSIX' | ||
end | ||
end | ||
|
||
def teardown | ||
@connection.drop_table :postgresql_collations, if_exists: true | ||
end | ||
|
||
test "string column with collation" do | ||
column = @connection.columns(:postgresql_collations).find { |c| c.name == 'string_c' } | ||
assert_equal :string, column.type | ||
assert_equal 'C', column.collation | ||
end | ||
|
||
test "text column with collation" do | ||
column = @connection.columns(:postgresql_collations).find { |c| c.name == 'text_posix' } | ||
assert_equal :text, column.type | ||
assert_equal 'POSIX', column.collation | ||
end | ||
|
||
test "add column with collation" do | ||
@connection.add_column :postgresql_collations, :title, :string, collation: 'C' | ||
|
||
column = @connection.columns(:postgresql_collations).find { |c| c.name == 'title' } | ||
assert_equal :string, column.type | ||
assert_equal 'C', column.collation | ||
end | ||
|
||
test "change column with collation" do | ||
@connection.add_column :postgresql_collations, :description, :string | ||
@connection.change_column :postgresql_collations, :description, :text, collation: 'POSIX' | ||
|
||
column = @connection.columns(:postgresql_collations).find { |c| c.name == 'description' } | ||
assert_equal :text, column.type | ||
assert_equal 'POSIX', column.collation | ||
end | ||
|
||
test "schema dump includes collation" do | ||
output = dump_table_schema("postgresql_collations") | ||
assert_match %r{t.string\s+"string_c",\s+collation: "C"$}, output | ||
assert_match %r{t.text\s+"text_posix",\s+collation: "POSIX"$}, output | ||
end | ||
end |