Skip to content

Instantly share code, notes, and snippets.

@laiso
Last active May 6, 2016 04:00
Show Gist options
  • Save laiso/2b198c81cb49fd00e3f033d040c51aa7 to your computer and use it in GitHub Desktop.
Save laiso/2b198c81cb49fd00e3f033d040c51aa7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'nokogiri'
path = ARGV.shift
doc = Nokogiri::XML(File.open(path))
doc.xpath("/database/object").each do |object|
o = object.clone
o.children.each do |element|
if element.attribute("name")&.value == "sourcename"
entity = element.child.text
o.add_child("<attribute name=\"migrationpolicyclassname\" type=\"string\">#{entity}To#{entity}MigrationPolicy</attribute>")
end
end
object.replace(o)
end
doc.write_xml_to(File.open(File.basename(path), "w"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment