datamapper / dm-migrations

DataMapper plugin for writing and speccing migrations
http://datamapper.org/
MIT License
66 stars 42 forks source link

AutoUpgrades fail on STI models. #25

Open solnic opened 13 years ago

solnic commented 13 years ago

It appears that DataMapper.auto_upgrade! is attempting to re-create the columns of a base STI model, for every descendent of that base model. This results in duplicate column errors when calling auto_upgrade!. This error does not occurr when running DataMapper.auto_migrate!.

Gemfile

source 'http://rubygems.org'
datamapper = 'git://github.com/datamapper'

gem 'activesupport',    '~> 3.0.0.beta3'
gem 'dm-do-adapter',        '~> 1.0.0.rc2', :git => "#{datamapper}/dm-do-adapter.git"
gem 'dm-sqlite-adapter',    '~> 1.0.0.rc2', :git => "#{datamapper}/dm-sqlite-adapter.git"
gem 'dm-core',      '~> 1.0.0.rc2', :git => "#{datamapper}/dm-core.git"
gem 'dm-migrations',    '~> 1.0.0.rc2', :git => "#{datamapper}/dm-migrations.git"

test.rb

require 'dm-core'
require 'dm-migrations'

class BaseModel

  include DataMapper::Resource
  include DataMapper::Migrations

  property :id, Serial

  property :type, Discriminator

  property :x, Integer

end

class ModelOne < BaseModel

  property :y, Integer

end

class ModelTwo < BaseModel

  property :z, Integer

end

DataMapper.setup(:default, "sqlite3://test.db")
DataMapper.auto_upgrade!

Created by Postmodern - 2010-05-24 01:54:27 UTC

Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1289

solnic commented 13 years ago
 ~ (0.000052) PRAGMA table_info("ronin_addresses")
 ~ (0.000307) CREATE TABLE "ronin_addresses" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "type" VARCHAR NOT NULL, "address" VARCHAR(50) NOT NULL, "created_at" TIMESTAMP NOT NULL, "frozen_tag_list" TEXT, "organization_id" INTEGER, "version" INTEGER NOT NULL)
 ~ (0.000117) CREATE INDEX "index_ronin_addresses_organization" ON "ronin_addresses" ("organization_id")
 ~ (0.000113) CREATE UNIQUE INDEX "unique_ronin_addresses_address" ON "ronin_addresses" ("address")
 ~ (0.000078) PRAGMA table_info("ronin_addresses")
 ~ (0.000143) PRAGMA table_info("ronin_addresses")
 ~ duplicate column name: id (code: 1, sql state: , query: ALTER TABLE "ronin_addresses" ADD COLUMN "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, uri: sqlite3://:memory:)
/home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-migrations-10e2a03514bd272776b61444593ff4b4fe608269-master/lib/dm-migrations/adapters/dm-do-adapter.rb:70:in `execute_non_query&rsquo;: duplicate column name: id (DataObjects::SyntaxError)
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-migrations-10e2a03514bd272776b61444593ff4b4fe608269-master/lib/dm-migrations/adapters/dm-do-adapter.rb:70:in `block (2 levels) in upgrade_model_storage&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-migrations-10e2a03514bd272776b61444593ff4b4fe608269-master/lib/dm-migrations/adapters/dm-do-adapter.rb:64:in `map&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-migrations-10e2a03514bd272776b61444593ff4b4fe608269-master/lib/dm-migrations/adapters/dm-do-adapter.rb:64:in `block in upgrade_model_storage&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-do-adapter-1d52cea8904d4da687c2fddabd5bf999c94cd21e-master/lib/dm-do-adapter/adapter.rb:260:in `with_connection&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-migrations-10e2a03514bd272776b61444593ff4b4fe608269-master/lib/dm-migrations/adapters/dm-do-adapter.rb:63:in `upgrade_model_storage&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-migrations-10e2a03514bd272776b61444593ff4b4fe608269-master/lib/dm-migrations/auto_migration.rb:71:in `upgrade_model_storage&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-migrations-10e2a03514bd272776b61444593ff4b4fe608269-master/lib/dm-migrations/auto_migration.rb:143:in `auto_upgrade!&rsquo;
    from /vault/1/code/ronin/ronin/lib/ronin/model/lazy_upgrade.rb:63:in `auto_upgrade!&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-migrations-10e2a03514bd272776b61444593ff4b4fe608269-master/lib/dm-migrations/auto_migration.rb:145:in `auto_upgrade!&rsquo;
    from /vault/1/code/ronin/ronin/lib/ronin/model/lazy_upgrade.rb:63:in `auto_upgrade!&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-migrations-10e2a03514bd272776b61444593ff4b4fe608269-master/lib/dm-migrations/auto_migration.rb:45:in `block in repository_execute&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-core-37b4bd22b9e3842977cf83d32baba459607e900a-master/lib/dm-core/model/descendant_set.rb:33:in `block in each&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-core-37b4bd22b9e3842977cf83d32baba459607e900a-master/lib/dm-core/model/descendant_set.rb:33:in `each&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-core-37b4bd22b9e3842977cf83d32baba459607e900a-master/lib/dm-core/model/descendant_set.rb:33:in `each&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-migrations-10e2a03514bd272776b61444593ff4b4fe608269-master/lib/dm-migrations/auto_migration.rb:44:in `repository_execute&rsquo;
    from /home/hal/.bundle/ruby/1.9.1/bundler/gems/dm-migrations-10e2a03514bd272776b61444593ff4b4fe608269-master/lib/dm-migrations/auto_migration.rb:27:in `auto_upgrade!&rsquo;
    from /vault/1/code/ronin/ronin/lib/ronin/database/database.rb:190:in `block in upgrade&rsquo;
    from /vault/1/code/ronin/ronin/lib/ronin/database/database.rb:189:in `each_key&rsquo;
    from /vault/1/code/ronin/ronin/lib/ronin/database/database.rb:189:in `upgrade&rsquo;
    from /vault/1/code/ronin/ronin/lib/ronin/database/database.rb:215:in `setup&rsquo;
    from /vault/1/code/ronin/ronin/spec/spec_helper.rb:25:in `block (2 levels) in <top (required)>&rsquo;
    from /usr/lib/ruby/gems/1.9.1/gems/rspec-1.3.0/lib/spec/runner/options.rb:146:in `call&rsquo;
    from /usr/lib/ruby/gems/1.9.1/gems/rspec-1.3.0/lib/spec/runner/options.rb:146:in `block in run_examples&rsquo;
    from /usr/lib/ruby/gems/1.9.1/gems/rspec-1.3.0/lib/spec/runner/options.rb:146:in `each&rsquo;
    from /usr/lib/ruby/gems/1.9.1/gems/rspec-1.3.0/lib/spec/runner/options.rb:146:in `run_examples&rsquo;
    from /usr/lib/ruby/gems/1.9.1/gems/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run&rsquo;
    from /usr/lib/ruby/gems/1.9.1/gems/rspec-1.3.0/bin/spec:5:in `<main>&rsquo;
rake aborted!
Command /usr/bin/ruby19 -I"lib:lib:spec"  "/usr/lib/ruby/gems/1.9.1/gems/rspec-1.3.0/bin/spec" "spec/author_spec.rb" "spec/os_spec.rb" "spec/installation_spec.rb" "spec/ronin_spec.rb" "spec/ui/command_line/command_spec.rb" "spec/ui/output_spec.rb" "spec/model/has_name_spec.rb" "spec/model/has_description_spec.rb" "spec/model/has_license_spec.rb" "spec/model/model_spec.rb" "spec/model/lazy_upgrade_spec.rb" "spec/license_spec.rb" "spec/platform/overlay_spec.rb" "spec/platform/extension_cache_spec.rb" "spec/platform/overlay_cache_spec.rb" "spec/platform/maintainer_spec.rb" "spec/platform/extension_spec.rb" "spec/platform/cached_file_spec.rb" "spec/platform/platform_spec.rb" "spec/platform/cacheable_spec.rb" "spec/software_spec.rb" "spec/database_spec.rb" "spec/arch_spec.rb" "spec/vendor_spec.rb" "spec/url_spec.rb" --options .specopts failed

(See full trace by running task with --trace)

by Postmodern

solnic commented 13 years ago

I did some research into this test today, but I haven’t been able to narrow down the cause. I think it’s something inside DO or SQLite causing the problem. Here’s what I do know:

At this point I am unsure what the solution is. I think this will require more research, so I am removing it from the 1.0.0 milestone.

@Dirkjan: Can you think of anything that would cause this behaviour?

by Dan Kubb (dkubb)

solnic commented 13 years ago

A user who was testing Ronin edge and DataMapper 1.0.0.rc3 on Ruby 1.8.7 and OpenSolaris (libsqlite3 3.6.17) was able to reproduce the error:

~> ronin-web
/var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/adapters/dm-do-adapter.rb:70:in `execute_non_query&rsquo;: duplicate column name: id (DataObjects::SyntaxError)
from /var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/adapters/dm-do-adapter.rb:70:in `upgrade_model_storage&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/adapters/dm-do-adapter.rb:64:in `map&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/adapters/dm-do-adapter.rb:64:in `upgrade_model_storage&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-do-adapter-1.0.0.rc3/lib/dm-do-adapter/adapter.rb:260:in `with_connection&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/adapters/dm-do-adapter.rb:63:in `upgrade_model_storage&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/auto_migration.rb:71:in `upgrade_model_storage&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/auto_migration.rb:143:in `auto_upgrade!&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin/model/lazy_upgrade.rb:63:in `auto_upgrade!&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/auto_migration.rb:145:in `auto_upgrade!&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin/model/lazy_upgrade.rb:63:in `auto_upgrade!&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/auto_migration.rb:45:in `send&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/auto_migration.rb:45:in `repository_execute&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-core-1.0.0.rc3/lib/dm-core/model/descendant_set.rb:33:in `each&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-core-1.0.0.rc3/lib/dm-core/model/descendant_set.rb:33:in `each&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/auto_migration.rb:44:in `repository_execute&rsquo;
from /var/ruby/1.8/gem_home/gems/dm-migrations-1.0.0.rc3/lib/dm-migrations/auto_migration.rb:27:in `auto_upgrade!&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin/database/database.rb:190:in `upgrade&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin/database/database.rb:189:in `each_key&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin/database/database.rb:189:in `upgrade&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin/database/database.rb:215:in `setup&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin/environment.rb:37
from /usr/ruby/1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require&rsquo;
from /usr/ruby/1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin.rb:21
from /usr/ruby/1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require&rsquo;
from /usr/ruby/1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin/ui/console.rb:171:in `start&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin/ui/console.rb:170:in `instance_eval&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin/ui/console.rb:170:in `start&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-0.4.0/lib/ronin/ui/command_line/commands/console.rb:60:in `execute&rsquo;
from /var/ruby/1.8/gem_home/gems/thor-0.13.6/lib/thor/task.rb:33:in `send&rsquo;
from /var/ruby/1.8/gem_home/gems/thor-0.13.6/lib/thor/task.rb:33:in `run&rsquo;
from /var/ruby/1.8/gem_home/gems/thor-0.13.6/lib/thor/invocation.rb:109:in `invoke&rsquo;
from /usr/ruby/1.8/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `map&rsquo;
from /var/ruby/1.8/gem_home/gems/thor-0.13.6/lib/thor/core_ext/ordered_hash.rb:73:in `each&rsquo;
from /var/ruby/1.8/gem_home/gems/thor-0.13.6/lib/thor/invocation.rb:118:in `map&rsquo;
from /var/ruby/1.8/gem_home/gems/thor-0.13.6/lib/thor/invocation.rb:118:in `invoke&rsquo;
from /var/ruby/1.8/gem_home/gems/thor-0.13.6/lib/thor/group.rb:36:in `start&rsquo;
from /var/ruby/1.8/gem_home/gems/thor-0.13.6/lib/thor/base.rb:378:in `start&rsquo;
from /var/ruby/1.8/gem_home/gems/thor-0.13.6/lib/thor/group.rb:29:in `start&rsquo;
from /var/ruby/1.8/gem_home/gems/ronin-web-0.2.2/bin/ronin-web:14
from /var/ruby/1.8/gem_home/bin/ronin-web:19:in `load&rsquo;
from /var/ruby/1.8/gem_home/bin/ronin-web:19

Note: Ronin by default uses the sqlite3 "~/.ronin/database.sqlite3".

by Postmodern

solnic commented 13 years ago

I am able to reproduce this bug on JRuby 1.5.1:

$ DEBUG=true rake spec
(in /vault/1/code/ronin/ronin)
You don&rsquo;t have tzinfo installed in your application. Please add it to your Gemfile and run bundle install
You don&rsquo;t have tzinfo installed in your application. Please add it to your Gemfile and run bundle install
 ~ (0.000) SELECT sqlite_version(*)
 ~ (0.057) CREATE TABLE "ronin_vendors" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50) NOT NULL)
 ~ (0.018) CREATE UNIQUE INDEX "unique_ronin_vendors_name" ON "ronin_vendors" ("name")
 ~ (0.028) CREATE TABLE "ronin_arches" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50) NOT NULL, "endian" VARCHAR(50) NOT NULL, "address_length" INTEGER NOT NULL)
 ~ (0.019) CREATE UNIQUE INDEX "unique_ronin_arches_name" ON "ronin_arches" ("name")
 ~ (0.037) CREATE TABLE "taggings" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "taggable_id" INTEGER NOT NULL, "taggable_type" VARCHAR NOT NULL, "tag_context" VARCHAR(50) NOT NULL, "tag_id" INTEGER NOT NULL)
 ~ (0.032) CREATE INDEX "index_taggings_tag" ON "taggings" ("tag_id")
 ~ (0.024) CREATE TABLE "tags" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50) NOT NULL)
 ~ (0.024) CREATE UNIQUE INDEX "unique_tags_name" ON "tags" ("name")
 ~ (0.029) CREATE TABLE "ronin_organizations" ("name" VARCHAR(50) NOT NULL, "description" VARCHAR(65535), "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "created_at" TIMESTAMP NOT NULL, "frozen_tag_list" TEXT)
 ~ (0.035) CREATE INDEX "index_ronin_organizations_name" ON "ronin_organizations" ("name")
 ~ (0.031) CREATE TABLE "ronin_addresses" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "type" VARCHAR NOT NULL, "address" VARCHAR(50) NOT NULL, "created_at" TIMESTAMP NOT NULL, "frozen_tag_list" TEXT, "organization_id" INTEGER, "version" INTEGER NOT NULL)
 ~ (0.037) CREATE INDEX "index_ronin_addresses_organization" ON "ronin_addresses" ("organization_id")
 ~ (0.032) CREATE UNIQUE INDEX "unique_ronin_addresses_address" ON "ronin_addresses" ("address")
 ~ (0.000) PRAGMA table_info("ronin_addresses")
 ~ (0.000) PRAGMA table_info("ronin_addresses")
 ~ (0.000) PRAGMA table_info("ronin_addresses")
 ~ (0.000) PRAGMA table_info("ronin_addresses")
 ~ (0.000) PRAGMA table_info("ronin_addresses")
 ~ (0.000) PRAGMA table_info("ronin_addresses")
 ~ (0.000) PRAGMA table_info("ronin_addresses")
 ~ (0.000) PRAGMA table_info("ronin_addresses")
 ~ (0.025) CREATE TABLE "ronin_ip_address_mac_addresses" ("created_at" TIMESTAMP NOT NULL, "ip_address_id" INTEGER NOT NULL, "mac_address_id" INTEGER NOT NULL, PRIMARY KEY("ip_address_id", "mac_address_id"))
 ~ (0.025) CREATE INDEX "index_ronin_ip_address_mac_addresses_ip_address" ON "ronin_ip_address_mac_addresses" ("ip_address_id")
 ~ (0.030) CREATE INDEX "index_ronin_ip_address_mac_addresses_mac_address" ON "ronin_ip_address_mac_ad/home/hal/.rvm/gems/jruby-1.5.1/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:64:in `map&rsquo;: duplicate column name: id (code: 0, sql state: , query: , uri: ) (DataObjects::SQLError)
    from /home/hal/.rvm/gems/jruby-1.5.1/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:64:in `upgrade_model_storage&rsquo;
    from /home/hal/.rvm/gems/jruby-1.5.1/gems/dm-do-adapter-1.0.0/lib/dm-do-adapter/adapter.rb:260:in `with_connection&rsquo;
    from /home/hal/.rvm/gems/jruby-1.5.1/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:63:in `upgrade_model_storage&rsquo;
    from /home/hal/.rvm/gems/jruby-1.5.1/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:71:in `upgrade_model_storage&rsquo;
    from /home/hal/.rvm/gems/jruby-1.5.1/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:143:in `auto_upgrade!&rsquo;
    from /vault/1/code/ronin/ronin/lib/ronin/model/lazy_upgrade.rb:63:in `auto_upgrade!&rsquo;
    from /home/hal/.rvm/gems/jruby-1.5.1/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migratidresses" ("mac_address_id")
 ~ (0.018) CREATE TABLE "ronin_credentials" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "user" VARCHAR(50), "password" VARCHAR(50))
 ~ (0.000) PRAGMA table_info("ronin_credentials")
 ~ duplicate column name: id (code: 0, sql state: , query: , uri: )
on.rb:145:in `auto_upgrade!&rsquo;
    from /vault/1/code/ronin/ronin/lib/ronin/model/lazy_upgrade.rb:63:in `auto_upgrade!&rsquo;
     ... 13 levels...
    from /home/hal/.rvm/gems/jruby-1.5.1/gems/rspec-1.3.0/lib/spec/runner/options.rb:146:in `run_examples&rsquo;
    from /home/hal/.rvm/gems/jruby-1.5.1/gems/rspec-1.3.0/lib/spec/runner/command_line.rb:9:in `run&rsquo;
    from /home/hal/.rvm/gems/jruby-1.5.1/gems/rspec-1.3.0/bin/spec:5
rake aborted!
Command /home/hal/.rvm/rubies/jruby-1.5.1/bin/jruby -I"lib:lib:spec"  "/home/hal/.rvm/gems/jruby-1.5.1/gems/rspec-1.3.0/bin/spec" "spec/installation_spec.rb" "spec/vendor_spec.rb" "spec/arch_spec.rb" "spec/os_spec.rb" "spec/database_spec.rb" "spec/license_spec.rb" "spec/author_spec.rb" "spec/software_spec.rb" "spec/url_spec.rb" "spec/ronin_spec.rb" "spec/ui/output_spec.rb" "spec/ui/command_line/command_spec.rb" "spec/model/model_spec.rb" "spec/model/lazy_upgrade_spec.rb" "spec/model/has_name_spec.rb" "spec/model/has_description_spec.rb" "spec/model/has_license_spec.rb" "spec/platform/cacheable_spec.rb" "spec/platform/extension_cache_spec.rb" "spec/platform/overlay_spec.rb" "spec/platform/maintainer_spec.rb" "spec/platform/overlay_cache_spec.rb" "spec/platform/extension_spec.rb" "spec/platform/platform_spec.rb" "spec/platform/cached_file_spec.rb" --options .specopts failed

(See full trace by running task with --trace)

by Postmodern

daz commented 13 years ago

I'm getting this issue too.

1.9.2-p290 dm-core 1.2.0 dm-migrations 1.2.0

/Users/darren/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/dm-migrations-1.2.0/lib/dm-migrations/adapters/dm-do-adapter.rb:70:in `execute_non_query': duplicate column name: id (DataObjects::SyntaxError)
    from /Users/darren/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/dm-migrations-1.2.0/lib/dm-migrations/adapters/dm-do-adapter.rb:70:in `block (2 levels) in upgrade_model_storage'

Same deal as you, auto_migrate! works.

charlieschwabacher commented 12 years ago

I was able to work around this issue with this DataMapper::Model.descendants.each {|m| m.auto_upgrade! if m.superclass == Object}

as a replacement for DataMapper.auto_upgrade!

gilbert commented 12 years ago

I'm getting the same issue. It's especially annoying when adding a new index, since it tries to add it twice.

It also seems to happen with DataMapper.auto_migrate! as well:

require 'rubygems'
require 'dm-core'
require 'dm-migrations'

DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'sqlite::memory:')

class Shape
  include DataMapper::Resource

  property :id,    Serial
  property :type,  Discriminator
  property :name,  String, :index => true

end

class Circle < Shape
end

DataMapper.finalize
DataMapper.auto_migrate!

When fresh it runs correctly, but the tables are being created twice:

 ~ (0.000048) SELECT sqlite_version(*)
 ~ (0.000097) DROP TABLE IF EXISTS "shapes"
 ~ (0.000011) PRAGMA table_info("shapes")
 ~ (0.000426) CREATE TABLE "shapes" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "type" VARCHAR NOT NULL, "name" VARCHAR(50))
 ~ (0.000129) CREATE INDEX "index_shapes_name" ON "shapes" ("name")
 ~ (0.000163) DROP TABLE IF EXISTS "shapes"
 ~ (0.000009) PRAGMA table_info("shapes")
 ~ (0.000144) CREATE TABLE "shapes" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "type" VARCHAR NOT NULL, "name" VARCHAR(50))
 ~ (0.000123) CREATE INDEX "index_shapes_name" ON "shapes" ("name")

However, if the table already exists and I run auto_upgrade! instead, I get a duplicate column name error when it tries to add the index the second time.

I'm using data_mapper (1.2.0).

Thanks for the workaround @charlieschwabacher