Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6074

Show
Ignore:
Timestamp:
01/28/07 15:45:06 (2 years ago)
Author:
bitsweat
Message:

MySQL: blob and text columns may not have defaults in 5.x. Update fixtures schema for strict mode. Closes #6695.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r6073 r6074  
    11*SVN* 
     2 
     3* MySQL: blob and text columns may not have defaults in 5.x. Update fixtures schema for strict mode.  #6695 [Dan Kubb] 
    24 
    35* 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] 
  • trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

    r6064 r6074  
    8686  module ConnectionAdapters 
    8787    class MysqlColumn < Column #:nodoc: 
    88       TYPES_ALLOWING_EMPTY_STRING_DEFAULT = Set.new([:binary, :string, :text]) 
     88      TYPES_DISALLOWING_DEFAULT = Set.new([:binary, :text]) 
     89      TYPES_ALLOWING_EMPTY_STRING_DEFAULT = Set.new([:string]) 
    8990 
    9091      def initialize(name, default, sql_type = nil, null = true) 
    9192        @original_default = default 
    9293        super 
    93         @default = nil if missing_default_forged_as_empty_string? 
     94        @default = nil if no_default_allowed? || missing_default_forged_as_empty_string? 
    9495      end 
    9596 
     
    103104        # MySQL misreports NOT NULL column default when none is given. 
    104105        # We can't detect this for columns which may have a legitimate '' 
    105         # default (string, text, binary) but we can for others (integer
    106         # datetime, boolean, and the rest). 
     106        # default (string) but we can for others (integer, datetime, boolean
     107        # and the rest). 
    107108        # 
    108109        # Test whether the column has default '', is not null, and is not 
     
    110111        def missing_default_forged_as_empty_string? 
    111112          !null && @original_default == '' && !TYPES_ALLOWING_EMPTY_STRING_DEFAULT.include?(type) 
     113        end 
     114 
     115        # MySQL 5.0 does not allow text and binary columns to have defaults 
     116        def no_default_allowed? 
     117          TYPES_DISALLOWING_DEFAULT.include?(type) 
    112118        end 
    113119    end 
  • trunk/activerecord/test/fixtures/db_definitions/mysql.sql

    r5749 r6074  
    177177CREATE TABLE `tasks` ( 
    178178  `id` int(11) NOT NULL auto_increment, 
    179   `starting` datetime NOT NULL default '0000-00-00 00:00:00', 
    180   `ending` datetime NOT NULL default '0000-00-00 00:00:00', 
     179  `starting` datetime NOT NULL default '1000-01-01 00:00:00', 
     180  `ending` datetime NOT NULL default '1000-01-01 00:00:00', 
    181181  PRIMARY KEY  (`id`) 
    182182) TYPE=InnoDB; 
  • trunk/activerecord/test/migration_test.rb

    r5937 r6074  
    693693        assert_nothing_raised { 
    694694          Person.connection.create_table :binary_testings do |t| 
    695             t.column "data", :binary, :default => "", :null => false 
     695            t.column "data", :binary, :null => false 
    696696          end 
    697697        } 
     
    703703          assert_equal "empty_blob()", data_column.default 
    704704        else 
    705           assert_equal "", data_column.default 
     705          assert_nil data_column.default 
    706706        end 
    707707 
  • trunk/activerecord/test/schema_dumper_test.rb

    r5520 r6074  
    9090    end 
    9191 
     92    if current_adapter?(:MysqlAdapter) 
     93      def test_schema_dump_should_not_add_default_value_for_mysql_text_field 
     94        output = standard_dump 
     95        assert_match %r{t.column "body",\s+:text,\s+:null => false$}, output 
     96      end 
     97    end 
     98 
    9299    def test_schema_dump_includes_decimal_options 
    93100      stream = StringIO.new