Permalink
Browse files

Merge pull request #14579 from senny/pg/remove_string_limit

PostgreSQL, remove varchar limit.

Conflicts:
	activerecord/CHANGELOG.md
  • Loading branch information...
2 parents f79881e + 80f4a65 commit 8d1c7037278f7f0ca94d47bca7de9922d5b8a4e9 @rafaelfranca rafaelfranca committed Apr 4, 2014
@@ -1,3 +1,9 @@
+* PostgreSQL and SQLite string columns no longer have a default limit of 255.
+
+ Fixes #13435, #9153.
+
+ *Vladimir Sazhin*, *Toms Mikoss*, *Yves Senn*
+
* Make possible to have an association called `records`.
Fixes #11645.
@@ -209,7 +209,7 @@ class Table < ActiveRecord::ConnectionAdapters::Table
NATIVE_DATABASE_TYPES = {
primary_key: "serial primary key",
- string: { name: "character varying", limit: 255 },
+ string: { name: "character varying" },
text: { name: "text" },
integer: { name: "integer" },
float: { name: "float" },
@@ -63,7 +63,7 @@ class SQLite3Adapter < AbstractAdapter
NATIVE_DATABASE_TYPES = {
primary_key: 'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL',
- string: { name: "varchar", limit: 255 },
+ string: { name: "varchar" },
text: { name: "text" },
integer: { name: "integer" },
float: { name: "float" },
@@ -25,7 +25,7 @@ def setup
def test_column
assert_equal :string, @column.type
- assert_equal "character varying(255)", @column.sql_type
+ assert_equal "character varying", @column.sql_type
assert @column.array
assert_not @column.text?
assert_not @column.number?
@@ -35,6 +35,14 @@ def test_add_remove_single_field_using_symbol_arguments
assert_no_column TestModel, :last_name
end
+ def test_add_column_without_limit
+ # TODO: limit: nil should work with all adapters.
+ skip "MySQL wrongly enforces a limit of 255" if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
+ add_column :test_models, :description, :string, limit: nil
+ TestModel.reset_column_information
+ assert_nil TestModel.columns_hash["description"].limit
+ end
+
if current_adapter?(:MysqlAdapter, :Mysql2Adapter)
def test_unabstracted_database_dependent_types
add_column :test_models, :intelligence_quotient, :tinyint
@@ -63,7 +63,7 @@ def test_content_columns
def test_column_string_type_and_limit
assert_equal :string, @first.column_for_attribute("title").type
- assert_equal 255, @first.column_for_attribute("title").limit
+ assert_equal 250, @first.column_for_attribute("title").limit
end
def test_column_null_not_null
@@ -677,7 +677,7 @@ def create_table(*args, &block)
end
create_table :topics, force: true do |t|
- t.string :title
+ t.string :title, limit: 250
t.string :author_name
t.string :author_email_address
if mysql_56?

0 comments on commit 8d1c703

Please sign in to comment.