Skip to content
Browse files

Don't set "NULL" as a constraint on nullable columns [#398 state:reso…

…lved]

This is already the default and adding it breaks SQL standards compatibility.

Conflicts:

	activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
  • Loading branch information...
1 parent 482e8fe commit ddb8c9c92ed09d33ae573891a4ef0d566622f317 @tarmo tarmo committed Aug 24, 2008
View
10 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -383,13 +383,9 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
def add_column_options!(sql, options) #:nodoc:
sql << " DEFAULT #{quote(options[:default], options[:column])}" if options_include_default?(options)
- # must explcitly check for :null to allow change_column to work on migrations
- if options.has_key? :null
- if options[:null] == false
- sql << " NOT NULL"
- else
- sql << " NULL"
- end
+ # must explicitly check for :null to allow change_column to work on migrations
+ if options[:null] == false
+ sql << " NOT NULL"
end
end
View
8 activerecord/test/cases/column_definition_test.rb
@@ -9,21 +9,21 @@ def @adapter.native_database_types
end
# Avoid column definitions in create table statements like:
- # `title` varchar(255) DEFAULT NULL NULL
+ # `title` varchar(255) DEFAULT NULL
def test_should_not_include_default_clause_when_default_is_null
column = ActiveRecord::ConnectionAdapters::Column.new("title", nil, "varchar(20)")
column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new(
@adapter, column.name, "string",
column.limit, column.precision, column.scale, column.default, column.null)
- assert_equal "title varchar(20) NULL", column_def.to_sql
+ assert_equal "title varchar(20)", column_def.to_sql
end
def test_should_include_default_clause_when_default_is_present
column = ActiveRecord::ConnectionAdapters::Column.new("title", "Hello", "varchar(20)")
column_def = ActiveRecord::ConnectionAdapters::ColumnDefinition.new(
@adapter, column.name, "string",
column.limit, column.precision, column.scale, column.default, column.null)
- assert_equal %Q{title varchar(20) DEFAULT 'Hello' NULL}, column_def.to_sql
+ assert_equal %Q{title varchar(20) DEFAULT 'Hello'}, column_def.to_sql
end
def test_should_specify_not_null_if_null_option_is_false
@@ -33,4 +33,4 @@ def test_should_specify_not_null_if_null_option_is_false
column.limit, column.precision, column.scale, column.default, column.null)
assert_equal %Q{title varchar(20) DEFAULT 'Hello' NOT NULL}, column_def.to_sql
end
-end
+end

0 comments on commit ddb8c9c

Please sign in to comment.
Something went wrong with that request. Please try again.