Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Migration timestamp clash problems with generators

#487

Hello,

Creating multiple migrations automatically from a generate script causes problems with the new timestamp based migration filenames as they occur at the same second.

e.g.

m.migration_template "db/migrate/add_session_table.rb", "db/migrate", :migration_file_name => 'add_session_table'

m.migration_template "db/migrate/create_casein_users.rb", "db/migrate", :migration_file_name => 'create_casein_users'

creates:

20080625170543_add_session_table.rb

20080625170543_create_casein_users.rb

Obviously there's problems with autodetecting this and just incrementing the last digit, but maybe it's worth suffixing these clashes with a further qualifying digit? i.e. There's another level of granularity to mark up to 10 migrations created in the same second.

Russell.

Reported by Russell Quinn · June 25th, 2008 @ 06:26 PM

State: wontfix
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Ben Scofield
    Ben Scofield

    Here's a patch for the issue; it appends the microsecond time to the timestamp. Unfortunately, however, it appears that this area of railties is entirely untested, and I was sure that it would be wise to launch into a whole new suite of unit tests (though I can add those if it would help)

    September 2nd, 2008 @ 10:35 PM

  2. Ben Scofield
    Ben Scofield

    OK, ignore the previous patch :)

    After consulting with bitsweat, I've expanded the patch for the issue by adding a new test file (rails_migration_generator_test.rb) that shows the problem.

    September 3rd, 2008 @ 06:53 PM

  3. Brian Landau
    Brian Landau

    +1 This is a common issue for anyone developing new plugins/gems that use generators, or when creating personal generators.

    September 3rd, 2008 @ 07:07 PM

  4. Russell Quinn
    Russell Quinn

    +1 Good work! It certainly seems bad that migrations are now bound to a "rate" of one per second. If the whole purpose of 2.0 migrations were to ensure uniqueness then it seems to fail usage tests.

    September 4th, 2008 @ 08:31 AM

  5. Ben Scofield
    Ben Scofield

    OK, after chatting with DHH and bitsweat, it appears that the appropriate action is to consolidate migrations in generators instead of trying to make the timestamps more granular. (There's also a concern that microseconds may lengthen the timestamp so that it overflows some database column constraints.)

    This can be closed.

    September 4th, 2008 @ 01:48 PM

  6. Jeremy Kemper
    Jeremy Kemper
    • State changed from new to wontfix

    Cheers :) Thanks Ben.

    September 6th, 2008 @ 03:49 AM

  7. Mark Bates
    Mark Bates

    I am now just running into this problem with a gem of mine, and I can't disagree more that just 'consolidating' migrations is a good idea.

    Here's an example:

    v1 of the gem has a migration.
    v2 of the gem has a migration that updates the tables from the first migration.

    If you consolidate them into one, then the people who are upgrading from v1 - v2 will have a second migration that will raise errors on them because the tables already exist from the first migration. You can just comment it out, either because you might be adding new columns to the existing tables.

    Of course you could right insane amounts of checks in your migrations that check to see what version you are on and hopefully run the correct schema changes, but isn't that why we have migrations?

    I implore you to re-open this ticket. It's just not a good solution.

    July 29th, 2009 @ 08:23 PM

  8. Kevin Elliott
    Kevin Elliott

    I strongly agree with Mark Bates that this ticket should be re-opened and evaluated. His example is a good case for why a compressed migration will not work.

    Expecting to follow the ticket's current solution would be similar to forcing all rails apps to abandon migrations and only use a schema file.

    I, too, am requesting that this be looked at for an alternative solution.

    September 15th, 2009 @ 06:38 AM

  9. Basel Farah
    Basel Farah

    I have had the same problem trying to copy migrations with a generator, the only way I could do it is to add some delay between the creation of migrations, smply by adding:

    m.migration_template "db/migrate/add_session_table.rb", "db/migrate", :migration_file_name => 'add_session_table'
    m.sleep 1 #adds a delay of 1 second between creating these 2 migrations
    m.migration_template "db/migrate/create_casein_users.rb", "db/migrate", :migration_file_name => 'create_casein_users'

    result:
    .rb

    .rb

    this solved my problem for the moment, hope this helps.

    September 29th, 2009 @ 04:23 PM

  10. adlongwell
    adlongwell

    I was about to agree with Mark Bates on this ticket, but I think Basel's solution (m.sleep 1) is an excellent alternative. It works well for my purposes.

    October 6th, 2009 @ 02:04 AM

  11. Russell Quinn
    Russell Quinn

    m.sleep 1 might work, but it feels dark.

    October 6th, 2009 @ 08:31 AM

  12. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 9th, 2010 @ 10:03 PM

  13. kevinwu007
    kevinwu007

    I love 1 saints super bowl jersey!Below 2 the authentic nfl jerseys trees, I saw 3 some [link=http://www.pickson.com/indianapolis-colts-jerseys-c-40.html]peyton manning jersey[/link] balloons and butterflies in the sky. we went 4 to [url=http://www.pickson.com/indianapolis-colts-jerseys-c-40.html]colts nfl jerseys[/url] the zoo. In the afternoon, we went 5 to [colts nfl jerseys->http://www.pickson.com/indianapolis-colts-jerseys-c-40.html] the zoo. I visited the birds, mice, cats, dogs, budgies, hamsters, rabbits and so on.

    February 26th, 2011 @ 08:23 AM

  14. bingbing
  15. bingbing