Skip to content

Instantly share code, notes, and snippets.

@pokka
Last active April 12, 2016 05:10
Show Gist options
  • Save pokka/9ef17df2be43317dd45daf15896b4d2a to your computer and use it in GitHub Desktop.
Save pokka/9ef17df2be43317dd45daf15896b4d2a to your computer and use it in GitHub Desktop.
run multiple statments in rails migrate
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