Skip to content

Instantly share code, notes, and snippets.

@nolili
Forked from laiso/migpo.rb
Created May 6, 2016 04:00
Show Gist options
  • Save nolili/1979c6039242b81d47c5c8bd78f1b846 to your computer and use it in GitHub Desktop.
Save nolili/1979c6039242b81d47c5c8bd78f1b846 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