Last active
April 12, 2016 05:10
-
-
Save pokka/9ef17df2be43317dd45daf15896b4d2a to your computer and use it in GitHub Desktop.
run multiple statments in rails migrate
This file contains hidden or 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
sql = File.read(sql_file) | |
statements = sql.split(/;$/) | |
statements.pop if statements.last.blank? | |
ActiveRecord::Base.transaction do | |
statements.uniq.each { |statement| execute(statement.gsub(/\n/, '')) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment