Skip to content

schema.rb not correct for SQLite #27

@patrick-minton

Description

@patrick-minton

Given a migration such as:

class CreateSomeObject < ActiveRecord::Migration
  def change
    create_table :some_objects, :id => false do |t|
      t.uuid   :id, :primary_key => true
      t.string :name
    end
  end
end

You get in an entry in schema.rb such as:

create_table "some_objects", :force => true do |t|
  t.string "name"
end

Notice it looks EXACTLY like a normal table with an ID. I believe, because of this, your sqlite test database does not use UUIDs:

class SomeObjectTest < ActiveSupport::TestCase
  test "Has a UUID primary key" do
    o = SomeObject.create(:name => "FooBar")
    assert_equal UUIDTools::UUID, o.id.class
  end
end

gets:

  1) Failure:
  test_Has_a_UUID_primary_key(SomeObjectTest) [/Users/patrick/src/someobjecttest/test/unit/someobject_test.rb:6]:
  <UUIDTools::UUID> expected but was
  <Fixnum>.

If I edit the schema.rb file to look like:

 create_table :some_objects, :id => false do |t|
    t.uuid   :id, :primary_key => true
    t.string :name
 end

The same test now outputs:

 Finished tests in 0.273841s, 3.6518 tests/s, 3.6518 assertions/s.

 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips

However, clearly, editing the schema.rb file by hand after every migration is not an option.

Is this a bug? Something I am missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions