From 269ad9711ddc179e72cc7da3176893a1dcca1b26 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 28 Jan 2007 15:45:06 +0000 Subject: 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 --- .../lib/active_record/connection_adapters/mysql_adapter.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'activerecord/lib') 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 -- cgit v1.2.3