After being inspired by errtheblog''s sexy migrations ( http://errtheblog.com/posts/51-sexy-migrations) I got tired of writing my un-sexy migrations containing line after line of remove_column and its alter-ego add_column. So I made two new methods, add_columns and remove_columns. http://frozenplague.net/?p=102 Repetition no more! -- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg wrote:> After being inspired by errtheblog''s sexy migrations ( > http://errtheblog.com/posts/51-sexy-migrations) I got tired of writing > my > un-sexy migrations containing line after line of remove_column and its > alter-ego add_column. > > So I made two new methods, add_columns and remove_columns. > > http://frozenplague.net/?p=102 > > Repetition no more! > > -- > Ryan Bigg > http://www.frozenplague.netdoesn''t Rails 2.0 already do something like this with t.string :column_one, :column_two, :ect ? -- 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 -~----------~----~----~----~------~----~------~--~---
That''s for when you''re creating a table. This is for after the table has been created and you want to change it. On Dec 19, 2007 10:49 AM, Jeremy Woertink <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Ryan Bigg wrote: > > After being inspired by errtheblog''s sexy migrations ( > > http://errtheblog.com/posts/51-sexy-migrations) I got tired of writing > > my > > un-sexy migrations containing line after line of remove_column and its > > alter-ego add_column. > > > > So I made two new methods, add_columns and remove_columns. > > > > http://frozenplague.net/?p=102 > > > > Repetition no more! > > > > -- > > Ryan Bigg > > http://www.frozenplague.net > > doesn''t Rails 2.0 already do something like this with > > t.string :column_one, :column_two, :ect > > ? > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg wrote:> That''s for when you''re creating a table. This is for after the table has > been created and you want to change it. > > On Dec 19, 2007 10:49 AM, Jeremy Woertink > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > >> > http://frozenplague.net/?p=102 >> >> ? >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > > -- > Ryan Bigg > http://www.frozenplague.netHi Ryan, This feature is now part of rails 2.0 :) http://ryandaigle.com/articles/2007/5/6/what-s-new-in-edge-rails-bringin-sexy-back -- 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 -~----------~----~----~----~------~----~------~--~---
That''s not the same as what he''s got here... I think this is pretty neat. I like remove_columns especially. I don''t know how much I''d really use add_columns, but having it like that would be nice just in case. :) --Jeremy On Dec 18, 2007 10:46 PM, Mohan Kumar <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Ryan Bigg wrote: > > That''s for when you''re creating a table. This is for after the table has > > been created and you want to change it. > > > > On Dec 19, 2007 10:49 AM, Jeremy Woertink > > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > >> > http://frozenplague.net/?p=102 > >> > >> ? > >> -- > >> Posted via http://www.ruby-forum.com/. > >> > >> > > >> > > > > > > -- > > Ryan Bigg > > http://www.frozenplague.net > > Hi Ryan, > > This feature is now part of rails 2.0 :) > > http://ryandaigle.com/articles/2007/5/6/what-s-new-in-edge-rails-bringin-sexy-back > -- > Posted via http://www.ruby-forum.com/. > > > > >-- http://www.jeremymcanally.com/ My books: Ruby in Practice http://www.manning.com/mcanally/ My free Ruby e-book http://www.humblelittlerubybook.com/ My blogs: http://www.mrneighborly.com/ http://www.rubyinpractice.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 -~----------~----~----~----~------~----~------~--~---
Thank you Jeremy M. Mohan, as I explained before it''s not replicating what is already in Rails 2.0, as that is for when you''re creating tables. This is for when you''ve already created the tables and want to do more to them. On Dec 19, 2007 2:31 PM, Jeremy McAnally <jeremymcanally-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > That''s not the same as what he''s got here... > > I think this is pretty neat. I like remove_columns especially. I > don''t know how much I''d really use add_columns, but having it like > that would be nice just in case. :) > > --Jeremy > > On Dec 18, 2007 10:46 PM, Mohan Kumar <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > > Ryan Bigg wrote: > > > That''s for when you''re creating a table. This is for after the table > has > > > been created and you want to change it. > > > > > > On Dec 19, 2007 10:49 AM, Jeremy Woertink > > > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > wrote: > > > > > >> > http://frozenplague.net/?p=102 > > >> > > >> ? > > >> -- > > >> Posted via http://www.ruby-forum.com/. > > >> > > >> > > > >> > > > > > > > > > -- > > > Ryan Bigg > > > http://www.frozenplague.net > > > > Hi Ryan, > > > > This feature is now part of rails 2.0 :) > > > > > http://ryandaigle.com/articles/2007/5/6/what-s-new-in-edge-rails-bringin-sexy-back > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > > > > > > > > -- > http://www.jeremymcanally.com/ > > My books: > Ruby in Practice > http://www.manning.com/mcanally/ > > My free Ruby e-book > http://www.humblelittlerubybook.com/ > > My blogs: > http://www.mrneighborly.com/ > http://www.rubyinpractice.com/ > > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I like it but I am surprised no one has ever made a syntax for adding and removing columns that matches create table. To me, the following would be ideal: add_columns "users" do |t| t.integer :group_id, :employer_id t.string :first, :last t.timestamps end remove_columns "users" do |t| t.integer :group_id, :employer_id t.string :first, :last t.timestamps end Frankly this would be the most intuitive and should be part of the rails core migrations system. -- 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 -~----------~----~----~----~------~----~------~--~---
Why not DRY it up even more? columns "users" do |t| t.integer :group_id, :employer_id t.string :first, :last t.timestamps end You know exactly which columns are being added. Reversing the migration should be able to use that structure to automagically remove the columns. The catch would be if there is additional processing occuring during the migration which would need to be reversed during the back-out. cheers -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Nathan Esquenazi Sent: Wednesday, 19 December 2007 3:25 PM To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Subject: [Rails] Re: More Migration Sexiness I like it but I am surprised no one has ever made a syntax for adding and removing columns that matches create table. To me, the following would be ideal: add_columns "users" do |t| t.integer :group_id, :employer_id t.string :first, :last t.timestamps end remove_columns "users" do |t| t.integer :group_id, :employer_id t.string :first, :last t.timestamps end Frankly this would be the most intuitive and should be part of the rails core migrations system. -- Posted via http://www.ruby-forum.com/. "Warning: The information contained in this email and any attached files is confidential to BAE Systems Australia. If you are not the intended recipient, any use, disclosure or copying of this email or any attachments is expressly prohibited. If you have received this email in error, please notify us immediately. VIRUS: Every care has been taken to ensure this email and its attachments are virus free, however, any loss or damage incurred in using this email is not the sender''s responsibility. It is your responsibility to ensure virus checks are completed before installing any data sent in this email to your computer." --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
^^ Point taken. Still, doesn''t this syntax just look natural? -- 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 -~----------~----~----~----~------~----~------~--~---
Being able to specify it in a block form would be wonderful. Unfortunately this is beyond my scope of knowledge. If anyone would like to do that and post it here I would be very thankful. On Dec 19, 2007 3:39 PM, Nathan Esquenazi <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > ^^ Point taken. Still, doesn''t this syntax just look natural? > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I probably won''t take the time to code this up but in case someone else here is eager to do this, I can easily show you where to start. The funny thing is that it would actually be ridiculously easy. First start here: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#M001150 Here is the (abridged for relevance) code for "create_table": def create_table(table_name, options = {}) # instantiate a "TableDefinition" class table_definition = TableDefinition.new(self) #...set the tables "id".... #... # yield the instance to the user (let them make calls to the object) yield table_definition #make the sql based on the columns added to the instance create_sql = #... turn the table_definition into SQL #run the sql that was built based on the columns stored in the instance execute create_sql end This is actually not very complicated at all. Simply "yielding" to the code passed into the block so: create_table "examples" do |t| t.column :example, :integer end simply calls the "column" function on the "t" variable which is actually an instance of TableDefinition So, what is TableDefinition? http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html Just a class with some basic functions that adds columns to an instance variable array and has a method for turning the columns array into sql. That is basically the jist of it. I leave actually coding it as an exercise to the reader, but I guarantee that it is doable. -- 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 -~----------~----~----~----~------~----~------~--~---