Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primary key is of type integer in test environment. #45

Closed
agirorn opened this issue Sep 9, 2014 · 12 comments
Closed

Primary key is of type integer in test environment. #45

agirorn opened this issue Sep 9, 2014 · 12 comments

Comments

@agirorn
Copy link

agirorn commented Sep 9, 2014

When I run my rails specs I see that the primary key is of type int(11) instead of being binary(16) and then the id field is of type int instead of being an uuid.

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products, :id => false do |t|
      t.uuid :id, :primary_key => true
    end
  end
end
ActiveRecord::Schema.define(version: 201570707070) do
  create_table "products", force: true do |t|
    t.datetime "created_at"
    t.datetime "updated_at"
  end
end

Development version of MySql

CREATE TABLE `products` (
  `id` binary(16) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Test version of MySql

CREATE TABLE `products` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Dose any body have a clue on what is going on hear?

@pyromaniac
Copy link
Collaborator

That's because you are creating test db from schema and not from migrations. Use sql schema, schema.rb doesn't support uuid fields

@agirorn
Copy link
Author

agirorn commented Sep 9, 2014

I use standard rails conventions when running my tests / specks.

Check out the repo then run

git clone PROJECT && 
cd PROJECT_DIR
bundle
rake db:create
rake db:migrate
rake

I like keeping things consistent and I'd prefer this to just work like all my other projects.
Do you have any suggestions and / or is there no way to fix this isssue withe schema.rb ?

@pyromaniac
Copy link
Collaborator

Yeah, fixing schema dumper will help. But it is too much work

@agirorn
Copy link
Author

agirorn commented Sep 9, 2014

You mean fixing schema dumber in ActiveRecord or some part of it as part of this gem?

@pyromaniac
Copy link
Collaborator

Exactly

@agirorn
Copy link
Author

agirorn commented Sep 10, 2014

No I mean do you have any idea where the base place for this fix is?

@pyromaniac
Copy link
Collaborator

If I'd had, I'd perform this by myself. Unfortunately, the source of schema dumper is so shitty, so I'm afraid there is no place to do this and we have to patch big pieces of code for every rails version specifically. Which version do you use?

@agirorn
Copy link
Author

agirorn commented Sep 10, 2014

The project I'm working on is a green field rails 4 project.

@agirorn
Copy link
Author

agirorn commented Sep 10, 2014

Yes this is so strange the schema dumber total assumes that the id column is an auto increment integer column and just skips the definition entirely:
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/schema_dumper.rb#L134

@pyromaniac
Copy link
Collaborator

schema dumber

exactly

So if you want to fix this rather then use sql schema - you have to dig through all this mess

@agirorn
Copy link
Author

agirorn commented Sep 11, 2014

I guess I'll have to live with it ASIS and just work around it.

@agirorn agirorn closed this as completed Sep 11, 2014
@valscion
Copy link

The schema dumper will hopefully be much better for handling these sorts of ID fields in Rails 5: rails/rails@3628025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants