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.

Add magic encoding comment to generated files

#1722

Subject: [PATCH] Add column_exists and index_exists methods for use in migrations.

Sometimes databases are tinkered with, and then a migration is written to do things the right way. At this point though, if you're writing a migration to add a column and its already in the table, you need to do some manual work to figure out if it already exists (same goes for an index). So, I've wrapped up that logic in a couple helper methods, which should make it even easier to write less brittle migrations.

Reported by jack dempsey (jackdempsey) · January 9th, 2009 @ 07:01 PM

State: wontfix
Milestone: none
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. Pratik
    Pratik
    • Milestone cleared.
    • Assigned user set to Michael Koziarski

    January 13th, 2009 @ 05:36 PM

  2. Jordi Bunster
    Jordi Bunster

    I don't get this. Why would one conditionally create things in migrations?

    Doesn't each one run over a consistent state?

    January 14th, 2009 @ 04:05 AM

  3. jack dempsey (jackdempsey)
    jack dempsey (jackdempsey)

    Jordi,

    I thought the comment I left originally would clarify things. Specifically, I had a situation where I had to quickly add a column to a table in a production system. Later on when I had a chance, I wrote the proper migration for this. I didn't want to drop the table in production, and break things, and then run the migration, so adding some logic like this to the migration takes care of that situation.

    So yeah, sometimes the state isn't consistent...and in general, given that things go poorly if the column/index already exists, I think something like this is helpful for making those strange situations easier to deal with.

    January 14th, 2009 @ 04:38 AM

  4. Michael Koziarski
    Michael Koziarski
    • State changed from new to wontfix

    I agree with Jordi on second thoughts. We should focus on encouraging users to follow the 'right' path with migrations.

    To handle the case where it's already been manually applied in production I think we should perhaps have a rake task which lets you 'fake apply' a particular migration

    February 1st, 2009 @ 02:05 AM

  5. jack dempsey (jackdempsey)
    jack dempsey (jackdempsey)

    Koz,

    While you might want to encourage users to keep things perfect, reality does not work that way. I don't like the idea of a 'fake apply' migration...I'm not even sure what that means...Given that this really doesn't hurt anyone, and helps those trying to fix a particular need, I'm not sure I understand the wontfix. Its not like it adds a huge amount of bloat.

    If you think this would be better served in a plugin, cool, lemme know. But just denying this seems a bit shortsighted with how things happen in the real world.

    February 1st, 2009 @ 06:06 AM

  6. jrom
    jrom

    Adding this kind of syntaxis to the migrations would make things ugly... And really not very useful. If you manually touch the DB, just update the schema_info field and skip that particular migration...

    February 1st, 2009 @ 09:48 AM

  7. jack dempsey (jackdempsey)
    jack dempsey (jackdempsey)

    I'm certainly not tied to the syntax. IRT manually tweaking what's run, what if you don't know or don't have access? Maybe there's more that needs to happen in the migration?

    I think I'll just create a plugin. I can imagine wanting other helper methods and it sounds like they'll have similar criticsm, so, easier to just keep them separate.

    February 1st, 2009 @ 05:00 PM

  8. Michael Koziarski
    Michael Koziarski

    In cases where the migration consists of multiple steps, only one of which has been run. Then you can split it into several steps (after all, they haven't been run in production yet).

    I'm not opposed to adding these helpers, it's more that I feel we need a better reason to make this available. table_exists? is only there because of an implementation detail for supporting AR::Base.inspect. How would we document this in a way that doesn't say "it's expected that you'll manually run things and also run migrations"

    February 1st, 2009 @ 09:51 PM

  9. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 9th, 2010 @ 10:04 PM

  10. Jeff Kreeftmeijer
  11. Jeff Kreeftmeijer
  12. Jeff Kreeftmeijer
  13. bingbing
  14. links london