Skip to content

Commit

Permalink
Have explicit :text option for a String column take priority over :si…
Browse files Browse the repository at this point in the history
…ze option on PostgreSQL (Fixes #1750)
  • Loading branch information
jeremyevans committed Jan 29, 2021
1 parent 999c9df commit 728ac31
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Have explicit :text option for a String column take priority over :size option on PostgreSQL (jeremyevans) (#1750)

* Support a :skip_invalid option in auto_validations plugin for not adding errors to a column that already has an error (jeremyevans)

* Support a :skip_invalid option in validation_helpers for not adding an error to a column that already has an error (jeremyevans)
Expand Down
6 changes: 4 additions & 2 deletions lib/sequel/adapters/shared/postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1500,9 +1500,11 @@ def type_literal_generic_integer(column)
# disallowed or there is a size specified, use the varchar type.
# Otherwise use the text type.
def type_literal_generic_string(column)
if column[:fixed]
if column[:text]
:text
elsif column[:fixed]
"char(#{column[:size]||255})"
elsif column[:text] == false or column[:size]
elsif column[:text] == false || column[:size]
"varchar(#{column[:size]||255})"
else
:text
Expand Down
5 changes: 5 additions & 0 deletions spec/adapters/postgres_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@
proc{@db.create_table(:some_table, :temp => true, :on_commit => :unsupported){text :name}}.must_raise(Sequel::Error)
end

it "should not use a size for text columns" do
@db.create_table(:tmp_dolls){String :description, text: true, size: :long}
@db.tables.must_include :tmp_dolls
end

it "should create an unlogged table" do
@db.create_table(:unlogged_dolls, :unlogged => true){text :name}
end if DB.server_version >= 90100
Expand Down

0 comments on commit 728ac31

Please sign in to comment.