Skip to content

Instantly share code, notes, and snippets.

@lanej
Forked from ey-pairing/dumpit.rb
Created April 17, 2012 04:16
Show Gist options
  • Save lanej/2403409 to your computer and use it in GitHub Desktop.
Save lanej/2403409 to your computer and use it in GitHub Desktop.
DataMapper Schema dump
DataMapper::Model.descendants.each do |model|
puts "create_table :#{model.storage_names[:default]} do"
model.properties.each do |property|
options = property.options.slice(:length)
primitive = property.primitive === Class ? String : property.primitive
puts " column :#{property.name}, DataMapper::Property::#{primitive.to_s}#{"," + options.map{|k,v| "#{k}: #{v}"}.join(", ") unless options.empty?}"
end
puts "end"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment