#1306 ✓resolved
Marcin Kulik

auto_upgrade for Enum/Flag proporties fails

Reported by Marcin Kulik | June 5th, 2010 @ 07:15 AM

Hey, just found out that after property refactor autoupgrading Enum/Flag properties with default value fails. See here:

http://gist.github.com/426546

property_schema_hash method (from dm-do-adapter.rb in dm-migrations) would dump this :new value correctly to integer but property.type is nil which doesn't respond to dump obviosuly so it returns unaltered value (:new).

This generates SQL like:

create table .... status INTEGER DEFAULT 'new' ...

which is wrong.

I've tried to investigate and fix the problem but I don't know if type being nil is good or bad thing so I don't know if it should be fixed in property_schema_hash method or somewhere upstream.

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 6th, 2010 @ 01:44 AM

    • State changed from “new” to “accepted”
    • Assigned user set to “Dan Kubb (dkubb)”

    @Marcin: Can you patch your dm-migrations with the attached patch? This fixes the problem for me, but I want to make sure it works for you too.

  • Marcin Kulik

    Marcin Kulik June 6th, 2010 @ 03:09 AM

    Looks like it works with the patch.

  • Marcin Kulik

    Marcin Kulik June 6th, 2010 @ 06:02 AM

    But the patch actually broke something else. Looks like it sets db default to 0 for Integer properties without default value specified and with required => false.

    I'm trying to reproduce it on single script, I'll post it here if I'll have an example.

  • Marcin Kulik

    Marcin Kulik June 6th, 2010 @ 06:40 AM

    Ok, I got it. Check this out: http://gist.github.com/427531
    Looks like default => 666 is being stored somewhere (maybe on Integer property class) and is used for all following properties of the same type.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) June 7th, 2010 @ 04:41 PM

    @Marcin: Ahh yes. I fixed this problem in the dm-migrations "next" branch.

    When I got the Hash from the type_map, I forgot to dup the value and just used it internally. It gets modified by the caller, and so all further Integer properties would share the same info as the first.

  • Marcin Kulik

    Marcin Kulik June 8th, 2010 @ 03:52 AM

    @dkubb: Great to hear that.

  • Andre Ben Hamou

    Andre Ben Hamou August 10th, 2010 @ 05:11 PM

    • Milestone order changed from “0” to “0”

    I'm assuming the following error on Merb::DataMapperSessionStore.auto_migrate! has the same underlying cause...

    /Users/andre/.bundle/ruby/1.8/gems/data_objects-0.10.2/lib/data_objects/quoting.rb:26:in `quote_value': Don't know how to quote Hash objects ({}) (RuntimeError)
    from /Users/andre/.bundle/ruby/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:232:in `property_schema_statement'
    from /Users/andre/.bundle/ruby/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-mysql-adapter.rb:76:in `property_schema_statement'
    from /Users/andre/.bundle/ruby/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:136:in `create_table_statement'
    from /Users/andre/.bundle/ruby/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:136:in `map'
    from /Users/andre/.bundle/ruby/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:136:in `create_table_statement'
    from /Users/andre/.bundle/ruby/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-mysql-adapter.rb:52:in `create_table_statement'
    from /Users/andre/.bundle/ruby/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:86:in `create_model_storage'
    from /Users/andre/.bundle/ruby/1.8/gems/dm-do-adapter-1.0.0/lib/dm-do-adapter/adapter.rb:260:in `with_connection'
    from /Users/andre/.bundle/ruby/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/adapters/dm-do-adapter.rb:85:in `create_model_storage'
    from /Users/andre/.bundle/ruby/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:79:in `create_model_storage'
    from /Users/andre/.bundle/ruby/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:175:in `auto_migrate_up!'
    from /Users/andre/.bundle/ruby/1.8/gems/dm-migrations-1.0.0/lib/dm-migrations/auto_migration.rb:130:in `auto_migrate!'
    
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) September 2nd, 2010 @ 01:22 PM

    • State changed from “accepted” to “resolved”

    (from [27c750636cbb9eec00fc0b75a0c1735deb4643bd]) Fixed default values to pass through Property#dump for DDL statements

    • This fixes various problems with Flag and Enum properties, among others, where the value that is provided in the :default option was used directly in the DDL statement. While this works when the ruby value maps onto the database column type, it does not work when Property#dump converts the value into another representation.

    [#1306 state:resolved] [#1320 state:resolved] [#1356 state:resolved] http://github.com/datamapper/dm-migrations/commit/27c750636cbb9eec0...

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Attachments

Referenced by

Pages