dino d.
2008-Apr-04 20:23 UTC
in a migration, how to specify ''self.down'' if self.up drops a table
Hi- I no longer need a join table and want to drop it, but I want to be able to recover if I''ve made a mistake. Is there an easy way to capture the current state of the table and incorporate it into my self.down? Also, is there a way to flatten my migrations to one master? Like, to say, "take the current state of my tables and commit them to one migration?" Thanks, Dino --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ar Chron
2008-Apr-04 20:48 UTC
Re: in a migration, how to specify ''self.down'' if self.up dr
dino d. wrote:> Hi- > > I no longer need a join table and want to drop it, but I want to be > able to recover if I''ve made a mistake. Is there an easy way to > capture the current state of the table and incorporate it into my > self.down? > > Also, is there a way to flatten my migrations to one master? Like, to > say, "take the current state of my tables and commit them to one > migration?" > > Thanks, > DinoI use the annotate_models rake task (google it on the web) to keep my model commented with the latest state of that table in the db. Your "undo" on the down would be to simply create the table in its current state. Flattening your migration depends on whether you''ve gone live or not. Cool in dev as long as you comunicate with your team, risky/inadvisable in live. You can certainly move the net of all your migrations into a single one, but you need to be sure your schema version matches your last migration. I do this periodically in dev, along the lines of: I have 28 migrations, and the schema is settled (for now). rake db:migrate VERSION=0 combine/edit my migrations into to the 1, 5, or 16 I want (you wanted just one, which is equally possible. IIRC, Danimal does this as well.) Once you''re set with your 1 migration: rake db:migrate Schema version 1 now has all your tables in one shot. If version 1 goes live, and you have users data in your DB, that migration becomes sacrosanct. You shouldn''t ever alter that migration, but can add new migrations on top of it in dev, and tinker with as you want. When it''s time to produce your uber migration for version 2, in dev, rake to version 1, edit/combine migrations 2 through whatever into just migration 2, then rake up again. That can be safely deployed to live on top of your 001 migration. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2008-Apr-04 20:52 UTC
Re: in a migration, how to specify ''self.down'' if self.up drops a table
> I no longer need a join table and want to drop it, but I want to be > able to recover if I''ve made a mistake. Is there an easy way to > capture the current state of the table and incorporate it into my > self.down?Look at db/schema.rb and find the table...> Also, is there a way to flatten my migrations to one master? Like, to > say, "take the current state of my tables and commit them to one > migration?"again, db/schema.rb... - backup everything - be careful - wipe out all your migrations - make schema.rb your 001 migration - reset the schema_info.version field in the database. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---