Re: Repairing migrations

Pat Maddox
Thu, 19 Jul 2007 21:17:54 -0000

On 7/19/07, Eric Anderson <eric-ANzg6odk14w@public.gmane.org>
wrote:
>
> magic_hat wrote:
> > So occassionally my migrations go...uh... off the rails. One of them
> > fails, and then I start getting errors about fields already existing,
> > etc. Or I make some changes to a database by hand, and then need to
> > bring the migration back in synch with the db without nuking the db
> > contents.
> >
> > Sometimes I can turn the schema into a migration to accomplish this.
> > But other times the errors continue. Is there a better way to bring a
> > migration and existing db into synch?
>
> The biggest thing is to test your migration in the development
> environment. That will get rid of many problems. But if for some reason
> your migration get''s an error in the production environment you
can just
> comment out the part of the migration it has already done (you can tell
> by where the error occured) then run again. That migration has not be
> checked off yet it will just skip your commented section and pick up
> where it left off.
>
> Alternatively you can make the rest of the changes manually and then
> just bump the version in the schema table to make rails think you ran it.
>
> Eric

Or you could use a real database that supports transactional DDL.

Pat