Skip to content

Schema dumps turn primary keys that are non-auto-increment or string into auto-increment integers #395

@neongrau

Description

@neongrau

I just recently upgraded to Rails 4.2 and using activerecord-sqlserver-adapter 4.2.2 (updated to 4.2.3 today but no changes here).
One issue is with a couple of Models that are using string based primary keys. The primary key column is named "guid" and is holding a UID22 string.
old schema.rb from Rails 3.2 had it this way:

  create_table "connector_feeds", :id => false, :force => true do |t|
    t.string   "guid",        :limit => 22,                    :null => false
    t.string   "name",                                         :null => false
    t.string   "url",                                          :null => false
    t.string   "path"
    t.boolean  "deactivated",               :default => false, :null => false
    t.datetime "created_at",                                   :null => false
    t.datetime "updated_at",                                   :null => false
    t.text     "actors"
  end

while the current version dumps this:

  create_table "connector_feeds", primary_key: "guid", force: :cascade do |t|
    t.string   "name",        limit: 255,                        null: false
    t.string   "url",         limit: 255,                        null: false
    t.string   "path",        limit: 255
    t.boolean  "deactivated",                    default: false, null: false
    t.datetime "created_at",                                     null: false
    t.datetime "updated_at",                                     null: false
    t.text     "actors",      limit: 2147483647
  end

When i try to load fixtures that each have a guid defined it'll end up trying to put a zero as primary key into the db which of course fails on the second record with a identity insert problem. Which happens because the guid column isn't a string but auto-increment integer which at the same time prevents me from inserting the string guid.

sample fixture:

connector_feeds_001:
  guid: aj1c6K_LDFgyNqVq4SGeUi
  name: sz
  url: http://rss.sueddeutsche.de/rss/Topthemen
  path: rss/channel/item
  deactivated: false
  created_at: 2012-06-14 10:46:00.937000000 +02:00
  updated_at: 2012-06-14 10:46:00.937000000 +02:00
  actors: 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions