GoodGets
2010-Apr-07 03:10 UTC
Will rake db:migrate:down VERSION=XXX completely remove that migration from Rails?
What exactly does rake db:migrate:down VERSION=XXX do? I understand that it runs the "down" migration, completely removing any columns/ tables that migration may have created, but does this mean that I can can delete these migration files as well? I''d like for Rails to have no knowledge of their existence. (I was allowing user profile pics with Paperclip, but have since decided to just use their Gravatars.) I know you can delete a migration, and even delete those columns from the schema, but Rails still "remembers" these changes and just updates them the next time you rake db:migrate. So, I''d like to completely rid my app of a particular migration, is rake db:migrate:down then deleting that migration from the migrate folder the way to do it? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ryan Waldron
2010-Apr-07 03:29 UTC
Re: Will rake db:migrate:down VERSION=XXX completely remove that migration from Rails?
You''ll also need to remove that migration''s entry from the ''schema_migrations'' table. That''s how Rails keeps up with what migrations exist, and whether it''s done them all. On Tue, Apr 6, 2010 at 10:10 PM, GoodGets <goodgets-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What exactly does rake db:migrate:down VERSION=XXX do? I understand > that it runs the "down" migration, completely removing any columns/ > tables that migration may have created, but does this mean that I can > can delete these migration files as well? I''d like for Rails to have > no knowledge of their existence. (I was allowing user profile pics > with Paperclip, but have since decided to just use their Gravatars.) > > I know you can delete a migration, and even delete those columns from > the schema, but Rails still "remembers" these changes and just updates > them the next time you rake db:migrate. So, I''d like to completely > rid my app of a particular migration, is rake db:migrate:down then > deleting that migration from the migrate folder the way to do it? > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
GoodGets
2010-Apr-07 03:43 UTC
Re: Will rake db:migrate:down VERSION=XXX completely remove that migration from Rails?
Thanks Ryan and, I hope this isn''t too stupid of a question, but where is this ''schema_migrations'' table? On Apr 6, 11:29 pm, Ryan Waldron <r...-L2nCScK6t0HQT0dZR+AlfA@public.gmane.org> wrote:> You''ll also need to remove that migration''s entry from the > ''schema_migrations'' table. That''s how Rails keeps up with what > migrations exist, and whether it''s done them all. > > > > On Tue, Apr 6, 2010 at 10:10 PM, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > What exactly does rake db:migrate:down VERSION=XXX do? I understand > > that it runs the "down" migration, completely removing any columns/ > > tables that migration may have created, but does this mean that I can > > can delete these migration files as well? I''d like for Rails to have > > no knowledge of their existence. (I was allowing user profile pics > > with Paperclip, but have since decided to just use their Gravatars.) > > > I know you can delete a migration, and even delete those columns from > > the schema, but Rails still "remembers" these changes and just updates > > them the next time you rake db:migrate. So, I''d like to completely > > rid my app of a particular migration, is rake db:migrate:down then > > deleting that migration from the migrate folder the way to do it? > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ryan Waldron
2010-Apr-07 03:53 UTC
Re: Re: Will rake db:migrate:down VERSION=XXX completely remove that migration from Rails?
It is in whatever database your app is using. Rails creates and maintains it for you. So if your production database is ''foo_prod'', there would be a ''schema_migrations'' table there, as well as in your ''foo_dev'' development database. I don''t know of a simple way to remove that row without firing up your database itself (MySQL or whatever). On Tue, Apr 6, 2010 at 10:43 PM, GoodGets <goodgets-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks Ryan > > and, I hope this isn''t too stupid of a question, but where is this > ''schema_migrations'' table? > > On Apr 6, 11:29 pm, Ryan Waldron <r...-L2nCScK6t0HQT0dZR+AlfA@public.gmane.org> wrote: >> You''ll also need to remove that migration''s entry from the >> ''schema_migrations'' table. That''s how Rails keeps up with what >> migrations exist, and whether it''s done them all. >> >> >> >> On Tue, Apr 6, 2010 at 10:10 PM, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > What exactly does rake db:migrate:down VERSION=XXX do? I understand >> > that it runs the "down" migration, completely removing any columns/ >> > tables that migration may have created, but does this mean that I can >> > can delete these migration files as well? I''d like for Rails to have >> > no knowledge of their existence. (I was allowing user profile pics >> > with Paperclip, but have since decided to just use their Gravatars.) >> >> > I know you can delete a migration, and even delete those columns from >> > the schema, but Rails still "remembers" these changes and just updates >> > them the next time you rake db:migrate. So, I''d like to completely >> > rid my app of a particular migration, is rake db:migrate:down then >> > deleting that migration from the migrate folder the way to do it? >> >> > -- >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rick DeNatale
2010-Apr-07 14:36 UTC
Re: Will rake db:migrate:down VERSION=XXX completely remove that migration from Rails?
On Tue, Apr 6, 2010 at 11:29 PM, Ryan Waldron <rew-L2nCScK6t0HQT0dZR+AlfA@public.gmane.org> wrote:> You''ll also need to remove that migration''s entry from the > ''schema_migrations'' table. That''s how Rails keeps up with what > migrations exist, and whether it''s done them all.Running rake db:migrate:down VERSION=XXX should remove the entry. Otherwise rake db:migrate wouldn''t run the migration again. A normal use case for migrate down is: rake db:migrate #oops something was wrong in migration 123456 rake db:migrate:down VERSION=123456 edit db/migrate/123456_whatever_it_does rake db:migrate> On Tue, Apr 6, 2010 at 10:10 PM, GoodGets <goodgets-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> What exactly does rake db:migrate:down VERSION=XXX do? I understand >> that it runs the "down" migration, completely removing any columns/ >> tables that migration may have created,Well it does whatever YOU told it to in the down part of the migration. It''s up to you (or whatever you use to edit/generate the migration) to write the correct code there. I tend to use Textmate snippets from the rails bundle to do migrations, and the table/column migration snippets will generate ''undo'' code in the down migration when you expand them in the up migration. But YMMV depending on what tools you use.>> but does this mean that I can >> can delete these migration files as well? I''d like for Rails to have >> no knowledge of their existence. (I was allowing user profile pics >> with Paperclip, but have since decided to just use their Gravatars.)>> I know you can delete a migration, and even delete those columns from >> the schema, but Rails still "remembers" these changes and just updates >> them the next time you rake db:migrate. So, I''d like to completely >> rid my app of a particular migration, is rake db:migrate:down then >> deleting that migration from the migrate folder the way to do it?When you do rake db:migration the rake task looks for migrations under db/migrate which don''t have entries in the schema_migrations table, and runs those (actually I think it''s a bit more subtle than that, there''s been discussion of a ''bug'' which can make the task ignore migrations with a timestamp older than the newest one in schema_migrations, which can keep migrations merged from another branch NOT to be run. But... If you run rake db:migrate:down version=XXX and then remove the file db/migrate/XXX_whatever from your source, the rake task won''t see it and it will be gone. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @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: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
GoodGets
2010-Apr-07 18:10 UTC
Re: Will rake db:migrate:down VERSION=XXX completely remove that migration from Rails?
So as long as I rake db:migrate:down and delete the migration file from my local machine, the production database on the server when it does go live (I haven''t launched the app yet) will have no knowledge of this migration having ever existed, right? because that''s all I really care about, and I believe this is true, at least from from my understanding now Thank you again Ryan On Apr 6, 11:53 pm, Ryan Waldron <r...-L2nCScK6t0HQT0dZR+AlfA@public.gmane.org> wrote:> It is in whatever database your app is using. Rails creates and > maintains it for you. So if your production database is ''foo_prod'', > there would be a ''schema_migrations'' table there, as well as in your > ''foo_dev'' development database. > > I don''t know of a simple way to remove that row without firing up your > database itself (MySQL or whatever). > > > > On Tue, Apr 6, 2010 at 10:43 PM, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Thanks Ryan > > > and, I hope this isn''t too stupid of a question, but where is this > > ''schema_migrations'' table? > > > On Apr 6, 11:29 pm, Ryan Waldron <r...-L2nCScK6t0HQT0dZR+AlfA@public.gmane.org> wrote: > >> You''ll also need to remove that migration''s entry from the > >> ''schema_migrations'' table. That''s how Rails keeps up with what > >> migrations exist, and whether it''s done them all. > > >> On Tue, Apr 6, 2010 at 10:10 PM, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > What exactly does rake db:migrate:down VERSION=XXX do? I understand > >> > that it runs the "down" migration, completely removing any columns/ > >> > tables that migration may have created, but does this mean that I can > >> > can delete these migration files as well? I''d like for Rails to have > >> > no knowledge of their existence. (I was allowing user profile pics > >> > with Paperclip, but have since decided to just use their Gravatars.) > > >> > I know you can delete a migration, and even delete those columns from > >> > the schema, but Rails still "remembers" these changes and just updates > >> > them the next time you rake db:migrate. So, I''d like to completely > >> > rid my app of a particular migration, is rake db:migrate:down then > >> > deleting that migration from the migrate folder the way to do it? > > >> > -- > >> > 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@googlegroups.com. > >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
GoodGets
2010-Apr-07 18:15 UTC
Re: Will rake db:migrate:down VERSION=XXX completely remove that migration from Rails?
Wow. Thank you Rick. Very nice explanation. Yeah, I dropped the columns by raking ''down'' and have also deleted that migration, so I think I''m good to go now. Also, I don''t use textmate, but yeah, I made sure that the "down" migration removed all the columns the "up" created. Thank you again Mr. Rick On Apr 7, 10:36 am, Rick DeNatale <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, Apr 6, 2010 at 11:29 PM, Ryan Waldron <r...-L2nCScK6t0HQT0dZR+AlfA@public.gmane.org> wrote: > > You''ll also need to remove that migration''s entry from the > > ''schema_migrations'' table. That''s how Rails keeps up with what > > migrations exist, and whether it''s done them all. > > Running rake db:migrate:down VERSION=XXX should remove the entry. > > Otherwise rake db:migrate wouldn''t run the migration again. A normal > use case for migrate down is: > > rake db:migrate > > #oops something was wrong in migration 123456 > rake db:migrate:down VERSION=123456 > edit db/migrate/123456_whatever_it_does > rake db:migrate > > > On Tue, Apr 6, 2010 at 10:10 PM, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> What exactly does rake db:migrate:down VERSION=XXX do? I understand > >> that it runs the "down" migration, completely removing any columns/ > >> tables that migration may have created, > > Well it does whatever YOU told it to in the down part of the > migration. It''s up to you (or whatever you use to edit/generate the > migration) to write the correct code there. > > I tend to use Textmate snippets from the rails bundle to do > migrations, and the table/column migration snippets will generate > ''undo'' code in the down migration when you expand them in the up > migration. But YMMV depending on what tools you use. > > >> but does this mean that I can > >> can delete these migration files as well? I''d like for Rails to have > >> no knowledge of their existence. (I was allowing user profile pics > >> with Paperclip, but have since decided to just use their Gravatars.) > >> I know you can delete a migration, and even delete those columns from > >> the schema, but Rails still "remembers" these changes and just updates > >> them the next time you rake db:migrate. So, I''d like to completely > >> rid my app of a particular migration, is rake db:migrate:down then > >> deleting that migration from the migrate folder the way to do it? > > When you do rake db:migration the rake task looks for migrations > under db/migrate which don''t have entries in the schema_migrations > table, and runs those (actually I think it''s a bit more subtle than > that, there''s been discussion of a ''bug'' which can make the task > ignore migrations with a timestamp older than the newest one in > schema_migrations, which can keep migrations merged from another > branch NOT to be run. But... > > If you run > > rake db:migrate:down version=XXX > > and then remove the file db/migrate/XXX_whatever from your source, the > rake task won''t see it and it will be gone. > > -- > Rick DeNatale > > Blog:http://talklikeaduck.denhaven2.com/ > Github:http://github.com/rubyredrick > Twitter: @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: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ryan Waldron
2010-Apr-08 19:24 UTC
Re: Re: Will rake db:migrate:down VERSION=XXX completely remove that migration from Rails?
On Wed, Apr 7, 2010 at 1:10 PM, GoodGets <goodgets-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So as long as I rake db:migrate:down and delete the migration file > from my local machine, the production database on the server when it > does go live (I haven''t launched the app yet) will have no knowledge > of this migration having ever existed, right? > > because that''s all I really care about, and I believe this is true, at > least from from my understanding now > > Thank you again RyanHA! My only contribution here was to miss the explanation badly enough to motivate Rick to write a longer and actually correct one. :)> On Apr 6, 11:53 pm, Ryan Waldron <r...-L2nCScK6t0HQT0dZR+AlfA@public.gmane.org> wrote: >> It is in whatever database your app is using. Rails creates and >> maintains it for you. So if your production database is ''foo_prod'', >> there would be a ''schema_migrations'' table there, as well as in your >> ''foo_dev'' development database. >> >> I don''t know of a simple way to remove that row without firing up your >> database itself (MySQL or whatever). >> >> >> >> On Tue, Apr 6, 2010 at 10:43 PM, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > Thanks Ryan >> >> > and, I hope this isn''t too stupid of a question, but where is this >> > ''schema_migrations'' table? >> >> > On Apr 6, 11:29 pm, Ryan Waldron <r...-L2nCScK6t0HQT0dZR+AlfA@public.gmane.org> wrote: >> >> You''ll also need to remove that migration''s entry from the >> >> ''schema_migrations'' table. That''s how Rails keeps up with what >> >> migrations exist, and whether it''s done them all. >> >> >> On Tue, Apr 6, 2010 at 10:10 PM, GoodGets <goodg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > What exactly does rake db:migrate:down VERSION=XXX do? I understand >> >> > that it runs the "down" migration, completely removing any columns/ >> >> > tables that migration may have created, but does this mean that I can >> >> > can delete these migration files as well? I''d like for Rails to have >> >> > no knowledge of their existence. (I was allowing user profile pics >> >> > with Paperclip, but have since decided to just use their Gravatars.) >> >> >> > I know you can delete a migration, and even delete those columns from >> >> > the schema, but Rails still "remembers" these changes and just updates >> >> > them the next time you rake db:migrate. So, I''d like to completely >> >> > rid my app of a particular migration, is rake db:migrate:down then >> >> > deleting that migration from the migrate folder the way to do it? >> >> >> > -- >> >> > 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@googlegroups.com. >> >> > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > -- >> > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.