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

#Integer ignores options (without raising an error) #483

Closed
chrisberkhout opened this issue May 16, 2012 · 3 comments
Closed

#Integer ignores options (without raising an error) #483

chrisberkhout opened this issue May 16, 2012 · 3 comments

Comments

@chrisberkhout
Copy link

e.g.

Sequel.migration do
  change do
    create_table(:some_table) do
      column :rating, :integer, :unsigned => true, :size => 10 # <- works
      Integer :score, :unsigned => true, :size => 10 # <- is created without options
    end
  end
end

# SQL
CREATE TABLE `some_table` (`rating` integer(10) UNSIGNED, `score` integer)

I had a look, but I can't see any reason why #Integer shouldn't just delegate to #column and work.

I've been using the MySQL adapter.

Any ideas?

@jeremyevans
Copy link
Owner

:size and :unsigned have never been a recognized options for the Integer generic type. :size only works by accident with column :integer, though for backwards compatibility it will still be recognized. Use column :rating, 'integer(10) unsigned' going forward.

The idea here is that using when generic types (ruby class names), the options recognized are specific to the generic type. Unless it is specifically documented as supported in http://sequel.rubyforge.org/rdoc/files/doc/schema_modification_rdoc.html or in the database adapter RDoc, you should not assume other options will affect the database type used.

With the specific type support (column :integer), there is some generic options handling that is done for all options types, and for backwards compatibility cannot change (as it would break old migrations). I do not encourage relying on this behavior in new code. For database specific types like the ones you are using, I recommend using a string for the type name.

@jeremyevans
Copy link
Owner

I think there is a bug on that documentation page, as it indicates that :size and :unsigned are universally usable, when that isn't the case. I'll fix that.

@chrisberkhout
Copy link
Author

Thanks Jeremy!

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

2 participants