Lazy Migrations Table Drop
Liquid error: undefined method `login' for nil:NilClass : March 2nd, 2006
I recently had a migration that had a lot create_table statements in it, so instead of carelessly copying the statements down to the self.down function, I figured I could just parse the file to do it for me.
1 2 3 4 5 6 7 8 9 10 |
def self.down File.open(__FILE__) do |fp| fp.readlines.each do |line| next unless line =~ /^\s+create_table.*$/ drop_table line.sub(/create_table :([^,]+)(,.*)$/, '\1')) end end puts "Done dropping tables." end |
7 Responses to “Lazy Migrations Table Drop”
Leave a Reply
Remember: escape your underscores \_ and indent code at least 4 spaces or incur the wrath of smartypants.
March 3rd, 2006 at 05:02 AM This should be a plugin. def self.down drop_created_tables end I'd do it but I'm totally plugin illiterate.
March 3rd, 2006 at 05:03 AM Grr. What are these comments, markdown? Guess I should have previed. I *meant*: def self.down drop_created_tables end
March 3rd, 2006 at 05:34 AM Or, you could have just used the reverse migration auto-generator: http://lunchroom.lunchboxsoftware.com/articles/2005/11/29/auto-fill-your-reverse-migrations
March 3rd, 2006 at 02:14 PM
This is a great idea and I have incorporated it in jEdit as a Abbrev. As a note, this assumes that you have a create table line with a force or some other option like:
Also, there seems to be an extra ')', I believe the line should read: Anyway, Thanks for the great tip!March 5th, 2006 at 08:45 AM Why is the main column of this site SO TINY???? even in 1024x768 the site look small.....
March 7th, 2006 at 05:35 AM Here's one that will work for people using quoted-style table syntax as well as symbol-style:
/create_table [:"']?([^,]\w+)["']?(,.*)$/March 7th, 2006 at 05:40 AM Sorry, This one doesn't assume the :force on the line. Should work for most variants of create_table.
/create_table [:"']?([^,]\w+)["']?(,?.*)$/