-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the citext data type
The citext module provides a case-insensitive character string type, citext. Essentially, it internally calls lower when comparing values. Otherwise, it behaves almost exactly like text.
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
|
||
describe 'CITEXT migrations' do | ||
let!(:connection) { ActiveRecord::Base.connection } | ||
before(:all) { ActiveRecord::Base.connection.add_extension('citext') if ActiveRecord::Base.connection.supports_extensions? } | ||
after { connection.drop_table :data_types } | ||
it 'creates an citext column' do | ||
lambda do | ||
connection.create_table :data_types do |t| | ||
t.citext :citext_1 | ||
t.citext :citext_2, :citext_3 | ||
t.column :citext_4, :citext | ||
end | ||
end.should_not raise_exception | ||
|
||
columns = connection.columns(:data_types) | ||
citext_1 = columns.detect { |c| c.name == 'citext_1'} | ||
citext_2 = columns.detect { |c| c.name == 'citext_2'} | ||
citext_3 = columns.detect { |c| c.name == 'citext_3'} | ||
citext_4 = columns.detect { |c| c.name == 'citext_4'} | ||
|
||
citext_1.sql_type.should eq 'citext' | ||
citext_2.sql_type.should eq 'citext' | ||
citext_3.sql_type.should eq 'citext' | ||
citext_4.sql_type.should eq 'citext' | ||
end | ||
end |
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,17 @@ | ||
require 'spec_helper' | ||
|
||
describe 'CITEXT schema dump' do | ||
let!(:connection) { ActiveRecord::Base.connection } | ||
after { connection.drop_table :testings } | ||
it 'correctly generates citext column statements' do | ||
stream = StringIO.new | ||
connection.create_table :testings do |t| | ||
t.citext :citext_column | ||
end | ||
|
||
ActiveRecord::SchemaDumper.dump(connection, stream) | ||
output = stream.string | ||
|
||
output.should match /t\.citext/ | ||
end | ||
end |