change_column_null method is missing for activerecord-jdbcderby-adapter
-----------------------------------------------------------------------

                 Key: JRUBY-4719
                 URL: http://jira.codehaus.org/browse/JRUBY-4719
             Project: JRuby
          Issue Type: Bug
          Components: JRuby-extras
    Affects Versions: JRuby 1.4
         Environment: osx 10.6.3
JRuby 1.4.0
activerecord-jdbc-adapter 0.9.4

            Reporter: Uwe Kubosch


The migration method change_column_null is missing form the derby adapter.  
Here is an implementation:

{noformat}
module ::JdbcSpec::Derby  
  def change_column_null(table_name, column_name, null, default = nil)
    unless null || default.nil?
      execute("UPDATE #{quote_table_name(table_name)} SET 
#{quote_column_name(column_name)}=#{quote(default)} WHERE 
#{quote_column_name(column_name)} IS NULL")
    end
    execute("ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN 
#{quote_column_name(column_name)} #{'NOT ' unless null}NULL")
  end
end
{noformat}


Please add.

Here is a testcase to verify.  Just modify to alter a non-nullable column:

{noformat}
class ActiveRecordTest < Test::Unit::TestCase
  class TestMigrateChangeColumnNull < ActiveRecord::Migration
    def self.up
      change_column_null :assignments, :order_id, true
      change_count = execute "UPDATE assignments SET order_id = NULL WHERE id = 
'started'"
      raise "update failure" unless change_count == 1
    end
    
    def self.down
      change_count = execute "UPDATE assignments SET order_id = 'started' WHERE 
id = 'started'"
      raise "update failure" unless change_count == 1
      change_column_null :assignments, :order_id, false
      begin
        execute "UPDATE assignments SET order_id = NULL WHERE id = 'started'"
        raise "Should raise exception"
      rescue
        # expected
      end
    end
  end
  
  def test_migrate_change_column_null
    TestMigrateChangeColumnNull.up
    TestMigrateChangeColumnNull.down
  end
  
end
{noformat}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to