Open derekatkins opened 10 years ago
Thanks for the bug report. As you can see this is pre 1.0 software and we are not yet trying to get it to work with all versions of Rails. You are more than welcome to submit a pull if you would like and I will consider it as long as it does not break Rails ~> 3 capabilities.
If I were more a ruby/rails guru I would; I'm very much a novice. Right now I'm not even sure what class/object @base is supposed to refer to. It's clearly nil in this case and the current code doesn't handle that.
FYI, before I found with_uuid I also tried usesguid; I found a bug there (ruby 1.8 v 1.9) but there's no issue tracker to report it (and give you the one-liner patch I came up with to fix the issue, needing .ord to get the string numeric value).
Doing a little research it looks like ActiveRecord::ConnectionAdapters::Table still has the @base in 4.0.2, but ActiveRecord::ConnectionAdapters::TableDefinition has changed and no longer gets the base passed into the initializer. I'm still researching how to find the actual adapter for the TableDefinition extension.
I did a little more research and came up with a potential solution, but it makes an assumption that the various connection adapters define certain data types uniquely. I changed the code in extensions/migrations.rb to read:
column_names.each do |name|
type = 'varchar(36)'
# Handle Table (and TableDefinition in Rails 3)
if @base
case(@base.adapter_name.downcase)
when 'sqlserver'
type = 'uniqueidentifier'
when 'postgresql'
type = 'uuid'
end
# Handle TableDefinition in Rails 4
elsif @native
if @native[:uuid] #postgres in 4.0 already defines uuid
type = @native[:uuid].is_a?(Hash) ? @native[:uuid][:name] : 'uuid'
elsif @native[:ss_timestamp] #sqlserver
type = 'uniqueidentifier'
end
end
What do you think?
Trying to use with_uuid 0.2.0 with rails 4.0.2 and ruby 1.9.3, I built a simple test app model and migration:
But running rake db:migrate results in the following error: