
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:
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) 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 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 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) 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.
-
-
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Attachments
Tags
Referenced by
-
1305 auto_upgrade! fails for mysq + mongo adapter I wonder if this is related to #1306 ? Can you confirm th...
-
1320 Using default values with Enum Dup of http://datamapper.lighthouseapp.com/projects/20609...
-
1356 Defaults in enums don't work with ORACLE [#1306 state:resolved] [#1320 state:resolved] [#1356 stat...
-
1320 Using default values with Enum [#1306 state:resolved] [#1320 state:resolved] [#1356 stat...
-
1306 auto_upgrade for Enum/Flag proporties fails [#1306 state:resolved] [#1320 state:resolved] [#1356 stat...