This project is archived and is in readonly mode.
Migration timestamp clash problems with generators
Reported by Russell Quinn | June 25th, 2008 @ 06:26 PM
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.
Comments and changes to this ticket
-
Ben Scofield September 2nd, 2008 @ 10:35 PM
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)
-
Ben Scofield September 3rd, 2008 @ 06:53 PM
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.
-
Brian Landau September 3rd, 2008 @ 07:07 PM
+1 This is a common issue for anyone developing new plugins/gems that use generators, or when creating personal generators.
-
Russell Quinn September 4th, 2008 @ 08:31 AM
+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.
-
Ben Scofield September 4th, 2008 @ 01:48 PM
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.
-
Jeremy Kemper September 6th, 2008 @ 03:49 AM
- State changed from new to wontfix
Cheers :) Thanks Ben.
-
Mark Bates July 29th, 2009 @ 08:23 PM
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.
-
Kevin Elliott September 15th, 2009 @ 06:38 AM
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.
-
Basel Farah September 29th, 2009 @ 04:23 PM
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.
-
adlongwell October 6th, 2009 @ 02:04 AM
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.
-
kevinwu007 February 26th, 2011 @ 08:23 AM
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>