Created
November 9, 2009 03:03
-
-
Save jinzhu/229644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
schema = File.read('/home/jinzhu/GIT/joblet/db/schema.rb') | |
schema.scan(/(^\s*create_table.*?)(?=\n\s*create_table)/m).map do |x| | |
content = x[0] | |
content =~ /create_table\s+"(.*?)"/ | |
filename = Time.now.utc.strftime("%Y%m%d%H%M%S") + '_create_' + $1 + '.rb' | |
filename = File.join('/home/jinzhu/GIT/joblet/db/migrate',filename) | |
content = "class Create" + $1.capitalize.gsub(/_(\w)/) { $1.to_s.upcase } + " < ActiveRecord::Migration\n def self.up\n" + content.sub(/\A\s*\n/,'') + "\n end\n\n def self.down\n end\nend" | |
puts content | |
f = File.new(filename,'w+') | |
f << content | |
f.close | |
# `vim #{filename} --cmd 'Rinvert' --cmd 'x'` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment