rename_column method fails with non-integer id for Derby
--------------------------------------------------------

                 Key: JRUBY-4720
                 URL: http://jira.codehaus.org/browse/JRUBY-4720
             Project: JRuby
          Issue Type: Bug
          Components: JRuby-extras
    Affects Versions: JRuby 1.4
            Reporter: Uwe Kubosch


Trying to rename a column in a migration on a table with a non-integer id 
column gives the following error:

{noformat}
Exception: ActiveRecord::ActiveRecordError: Columns of type 'INTEGER' cannot 
hold values of type 'CHAR'. : INSERT INTO altered_transactions (id,...) VALUES 
('one', ...)
/Users/uwe/workspace/aifudis/aifudis.operator/platform/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract_adapter.rb:219:in
 `log'
/Users/uwe/workspace/aifudis/aifudis.operator/platform/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.4-java/lib/active_record/connection_adapters/jdbc_adapter.rb:565:in
 `execute'
/Users/uwe/workspace/aifudis/aifudis.operator/platform/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.4-java/lib/jdbc_adapter/jdbc_derby.rb:232:in
 `execute'
/Users/uwe/workspace/aifudis/aifudis.operator/platform/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.4-java/lib/jdbc_adapter/missing_functionality_helper.rb:83:in
 `copy_table_contents'
/Users/uwe/workspace/aifudis/aifudis.operator/platform/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.4-java/lib/jdbc_adapter/missing_functionality_helper.rb:79:in
 `each'
/Users/uwe/workspace/aifudis/aifudis.operator/platform/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.4-java/lib/jdbc_adapter/missing_functionality_helper.rb:79:in
 `copy_table_contents'
/Users/uwe/workspace/aifudis/aifudis.operator/platform/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.4-java/lib/jdbc_adapter/missing_functionality_helper.rb:43:in
 `copy_table'
/Users/uwe/workspace/aifudis/aifudis.operator/platform/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.4-java/lib/jdbc_adapter/missing_functionality_helper.rb:20:in
 `move_table'
/Users/uwe/workspace/aifudis/aifudis.operator/platform/jruby-1.4.0/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.4-java/lib/jdbc_adapter/missing_functionality_helper.rb:13:in
 `alter_table'
{noformat}

Here is an implementation that fixes the problem.  Works with derby 10.5.3.0:

{noformat}
module ::JdbcSpec::Derby  
  def rename_column(table, old_name, new_name)
    execute "RENAME COLUMN #{table}.#{old_name} TO #{new_name}"
  end
end
{noformat}

Here is a test that verifies the fix:
{noformat}
class ActiveRecordTest < Test::Unit::TestCase
  class TestMigrateRenameColumnWithGuid < ActiveRecord::Migration
    def self.up
      rename_column :transactions, :comment, :command
    end
    
    def self.down
      rename_column :transactions, :command, :comment
    end
  end
  
  def test_migrate_change_column_for_guid
    TestMigrateRenameColumnWithGuid.up
    TestMigrateRenameColumnWithGuid.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