0.0
No commit activity in last 3 years
No release in over 3 years
Generates datamapper models from existing database schemas and export them to files
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
~> 0.5

Runtime

 Project Readme

dm-reflection¶ ↑

For now, this gem only allows you to print the ruby source for any DataMapper::Model, taking all property and relationship definitions into account. However, the plan is to be able to reflect on an existing relational database schema and export the corresponding datamapper model definitions to ruby source files. Think of it as active_record and annotate_models combined to do something useful with legacy databases.

require 'rubygems'
require 'dm-core'
require 'dm-reflection'

class Project

  include DataMapper::Resource

  property :id, Serial

  property :name, String, :required => true, :length => 200
  property :created_at, DateTime
  property :updated_at, DateTime

  has 0..n, :project_tasks
  has 0..n, :tasks, :through => :project_tasks
  has 0..n, :people, :through => Resource

end

Project.to_ruby # produces this nicely formatted ruby code

<<-RUBY
class Project

  include DataMapper::Resource

  property :id, Serial

  property :name, String, :required => true, :length => 200
  property :created_at, DateTime
  property :updated_at, DateTime

  has 0..n, :project_tasks
  has 0..n, :tasks, :through => :project_tasks
  has 0..n, :people, :through => Resource

end
RUBY

Also, you can create models from a repository by doing the following:

require 'dm-reflection'
models = DataMapper::Reflection.reflect(:default)

Note on Patches/Pull Requests¶ ↑

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Future Work¶ ↑

  • Support Associations/Relationships

  • Support Single Table Inheritance

  • Ensure Round tripping is functional ** Create model M in DataMapper ** Migrate M to a repository ** Reflect M’ from the repository ** M should == M’

  • Having round tripping provably working is the first goal

  • Legacy reflection is something to make work after round tripping (because the assumptions DM makes won’t always hold.)

See LICENSE for details. Copyright © 2009 Martin Gamsjaeger (snusnu). Copyright © 2010 Montana State University, Bozeman (The Yogo Data Management Team).