#877 ✓resolved
Postmodern

auto_upgrade! fails to run on existing STI tables

Reported by Postmodern | June 2nd, 2009 @ 04:27 PM

I noticed that when using STI and running auto-upgrade! the initial upgrade is successful, but subsequent upgrades will raise an exception concerning duplicate columns.

Running the following example (http://gist.github.com/121233), you can see the bug in action:

  gem 'dm-core', '0.10.0'
  require 'dm-core'


module ModelMixin

include DataMapper::Types

def self.included(base)
  base.module_eval do
    include DataMapper::Resource
    include DataMapper::Migrations

   property :type, Discriminator
  end
end



end
class User
include ModelMixin

property :id, Serial

property :name, String



end
class Admin < User
property :level, Integer



end
DataMapper.setup(:default, 'sqlite3:test.db') DataMapper.auto_upgrade!
unless ARGV[0] == 'stop'
system('ruby',File.expand_path(__FILE__),'stop')



end
  /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:139:in   `execute_non_query': duplicate column name: level (Sqlite3Error)
  Query: ALTER TABLE "users" ADD COLUMN "level" INTEGER
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:139:in `upgrade_model_storage'
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:133:in `map'
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:133:in `upgrade_model_storage'
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/adapters/data_objects_adapter.rb:253:in `with_connection'
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:132:in `upgrade_model_storage'
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:667:in `upgrade_model_storage'
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:743:in `auto_upgrade!'
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:745:in `auto_upgrade!'
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:31:in `auto_upgrade!'
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:57:in `with_each_model_and_repository'
    from /usr/lib/ruby/1.8/set.rb:188:in `each'
    from /usr/lib/ruby/1.8/set.rb:188:in `each_key'
    from /usr/lib/ruby/1.8/set.rb:188:in `each'
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:56:in `with_each_model_and_repository'
    from /usr/lib64/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/migrations.rb:30:in `auto_upgrade!'
    from dm_auto_migration_bug.rb:34

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Pages