On Wed, Sep 9, 2009 at 6:31 PM, Michael Koziarski<[email protected]> wrote:
>
>> Doesn't this same problem exist always - whether you are going down or
>> up, or store your migrations in files or the database?  Some would
>> consider it an antipattern to put any models or app classes in your
>> migrations.
>
> Some would be wrong if they considered that an anti pattern ;).  The
> vast bulk of migrations in my projects are model-dependent for things
> like cleaning up a data problem in production, initialising counter
> fields based on non-sql-calculatable fields (e.g. API calls)

My normal practice when writing migrations which depend on model code
is to put a migration specific model clase in the migration file
itself, scoped inside the migration.  The model mimics a subset of the
one in app/models including only necessary attribute declarations and
methods.

> If you store the migrations in your version control system you can
> recover the state of the migrations at any point in time.  For a
> particularly tricky down migration you can always step back revisiion
> by revision.  The database would have no such history and could never
> provide the same level of fidelity or reliability that your SCM can.

Absolutely true. And the technique I described decouples the running
of migrations from the current state of the models, which facilitates
recovering the state of the migrations without requiring incremental
steps of get a revision, run migrations, get the next revision run
migrations... if that makes sense.

>> I'm still not clear on the original poster's root problem and
>> solution, but I don't think the possibility of outdated non-schema
>> migration code is a good reason to reject the idea.
>
> The specific case mentioned was rolling back when the checkout is at
> an older version and doesn't have the down migration.  The solution
> there is to rollback from the original revision.

I have to say that I never understood the proposed solution, frankly
it scared the bejesus out of me, but maybe that's just me.

> If there's another case I'd be happy to re-evaluate but the power of
> migrations is in their simplicity they're not some darcs-ish patch
> algebra for DDL, they're little scripts that you run in order in which
> you can do whatever you want.
>

Amen



-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to