#353 ✓not-applicable
Ana Nelson

auto_upgrade! and string field length

Reported by Ana Nelson | June 6th, 2008 @ 10:16 AM

When you create a String field which defaults to a length of 50 characters, and you later change the field length by adding :length => 100 to the property statement, auto_upgrade! doesn't react to this change.

Validations will restrict the field to less than the new value of 100 characters, but attempting to commit 80 characters into a 50 character database field results in a database error.

I am using 0.9.1 from trunk (via sake), and postgres for the db.

It would be really nice to be able to resize fields using auto_upgrade! so there's no data loss (except for truncation if you go shorter obviously).

Comments and changes to this ticket

  • Jonathan Stott (namelessjon)

    Jonathan Stott (namelessjon) November 30th, 2008 @ 07:26 AM

    • Assigned user cleared.
    • Tag set to auto_upgrade, migrations, suggestion
    • Milestone cleared.
    • State changed from “new” to “open”
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) January 8th, 2009 @ 02:14 PM

    • State changed from “open” to “not-applicable”

    Closing this ticket as per: http://is.gd/eOHY

    I actually think this is a great idea, and think it would be better to open a thread on the mailing list to discuss this and similar approaches to auto_upgrade where non-destructive changes can be done.

    Ana: Do you mind opening a thread on the mailing list and referencing this ticket?

    I think things like adding/removing indexes, lengthening columns, loosening constraints (like changing NOT NULL to allow null), adding/changing default values could all be done by auto_upgrade.

    In fact given some planning I think it might be possible to do destructive changes safely. Consider a case when the field length is reduced from 100 to 50 characters max. We could do a SELECT MAX(LENGTH(column)) FROM table to see if anything exceeds the 50 character max.. if not, then we know we can safely change the table.

    To make some of this work, I would like to discuss on the mailing list a sort of dm-reflection plugin that would know how to reflect on the state of the 3 databases we support, so we can know stuff about the table structure, and table contents (like knowing the maximum length value stored in a column), and make decisions about how to safely alter the table. We could even use dm-reflection to generate models from an existing database. Lots of possibilities here.

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 »

People watching this ticket

Pages