aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-01-28 15:45:06 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-01-28 15:45:06 +0000
commit269ad9711ddc179e72cc7da3176893a1dcca1b26 (patch)
tree0536f985e974993471ed726193b3e609856eda25 /activerecord
parent5acea7fc9ca19848733c0a81e0c018bc7388af5e (diff)
downloadrails-269ad9711ddc179e72cc7da3176893a1dcca1b26.tar.gz
rails-269ad9711ddc179e72cc7da3176893a1dcca1b26.tar.bz2
rails-269ad9711ddc179e72cc7da3176893a1dcca1b26.zip
MySQL: blob and text columns may not have defaults in 5.x. Update fixtures schema for strict mode. Closes #6695.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6074 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/connection_adapters/mysql_adapter.rb14
-rwxr-xr-xactiverecord/test/fixtures/db_definitions/mysql.sql4
-rw-r--r--activerecord/test/migration_test.rb4
-rw-r--r--activerecord/test/schema_dumper_test.rb7
5 files changed, 23 insertions, 8 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index b6994bbf62..100333c88c 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* MySQL: blob and text columns may not have defaults in 5.x. Update fixtures schema for strict mode. #6695 [Dan Kubb]
+
* update_all can take a Hash argument. sanitize_sql splits into two methods for conditions and assignment since NULL values and delimiters are handled differently. #6583, #7365 [sandofsky, Assaf]
* MySQL: SET SQL_AUTO_IS_NULL=0 so 'where id is null' doesn't select the last inserted id. #6778 [Jonathan Viney, timc]
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index 842258f1ea..c0a09d7a54 100755
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -85,12 +85,13 @@ module ActiveRecord
module ConnectionAdapters
class MysqlColumn < Column #:nodoc:
- TYPES_ALLOWING_EMPTY_STRING_DEFAULT = Set.new([:binary, :string, :text])
+ TYPES_DISALLOWING_DEFAULT = Set.new([:binary, :text])
+ TYPES_ALLOWING_EMPTY_STRING_DEFAULT = Set.new([:string])
def initialize(name, default, sql_type = nil, null = true)
@original_default = default
super
- @default = nil if missing_default_forged_as_empty_string?
+ @default = nil if no_default_allowed? || missing_default_forged_as_empty_string?
end
private
@@ -102,14 +103,19 @@ module ActiveRecord
# MySQL misreports NOT NULL column default when none is given.
# We can't detect this for columns which may have a legitimate ''
- # default (string, text, binary) but we can for others (integer,
- # datetime, boolean, and the rest).
+ # default (string) but we can for others (integer, datetime, boolean,
+ # and the rest).
#
# Test whether the column has default '', is not null, and is not
# a type allowing default ''.
def missing_default_forged_as_empty_string?
!null && @original_default == '' && !TYPES_ALLOWING_EMPTY_STRING_DEFAULT.include?(type)
end
+
+ # MySQL 5.0 does not allow text and binary columns to have defaults
+ def no_default_allowed?
+ TYPES_DISALLOWING_DEFAULT.include?(type)
+ end
end
# The MySQL adapter will work with both Ruby/MySQL, which is a Ruby-based MySQL adapter that comes bundled with Active Record, and with
diff --git a/activerecord/test/fixtures/db_definitions/mysql.sql b/activerecord/test/fixtures/db_definitions/mysql.sql
index 93b7fada3c..8a56ab2172 100755
--- a/activerecord/test/fixtures/db_definitions/mysql.sql
+++ b/activerecord/test/fixtures/db_definitions/mysql.sql
@@ -176,8 +176,8 @@ CREATE TABLE `authors` (
CREATE TABLE `tasks` (
`id` int(11) NOT NULL auto_increment,
- `starting` datetime NOT NULL default '0000-00-00 00:00:00',
- `ending` datetime NOT NULL default '0000-00-00 00:00:00',
+ `starting` datetime NOT NULL default '1000-01-01 00:00:00',
+ `ending` datetime NOT NULL default '1000-01-01 00:00:00',
PRIMARY KEY (`id`)
) TYPE=InnoDB;
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index 825244d88e..0757c6a0c9 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -692,7 +692,7 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_nothing_raised {
Person.connection.create_table :binary_testings do |t|
- t.column "data", :binary, :default => "", :null => false
+ t.column "data", :binary, :null => false
end
}
@@ -702,7 +702,7 @@ if ActiveRecord::Base.connection.supports_migrations?
if current_adapter?(:OracleAdapter)
assert_equal "empty_blob()", data_column.default
else
- assert_equal "", data_column.default
+ assert_nil data_column.default
end
Person.connection.drop_table :binary_testings rescue nil
diff --git a/activerecord/test/schema_dumper_test.rb b/activerecord/test/schema_dumper_test.rb
index 8cbcbb39e5..576c2cebc3 100644
--- a/activerecord/test/schema_dumper_test.rb
+++ b/activerecord/test/schema_dumper_test.rb
@@ -89,6 +89,13 @@ if ActiveRecord::Base.connection.respond_to?(:tables)
end
end
+ if current_adapter?(:MysqlAdapter)
+ def test_schema_dump_should_not_add_default_value_for_mysql_text_field
+ output = standard_dump
+ assert_match %r{t.column "body",\s+:text,\s+:null => false$}, output
+ end
+ end
+
def test_schema_dump_includes_decimal_options
stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = [/^[^n]/]