DM's Integrity Map causes issues when setting up tables in legacy repositories. The rails console can access the models, but the controller cannot. The (temporary?) solution is to add the following lines to the models. http://groups.google.com/group/datamapper/browse_thread/thread/16dc095f33097050#
def self.default_repository_name
:your_repository
end
def self.repository(name = nil, &block)
super(:your_repository, &block)
end
In order to avoid migration in a legacy database (repository :legacy):
# ./spec/spec_helper.rb
config.before(:suite) do
DataMapper::Model.descendants.entries.each do |model|
model.auto_migrate!(:default) unless model.default_repository_name == :legacy
end
end
# call the bellow rake task to upgrade the table that are not in the :legacy repository
# ./lib/tasks/limited_auto_upgrade.rake
task :environment do
require File.expand_path('../../config/boot', File.dirname(__FILE__))
end
desc "Perform auto_upgrade on the default repository only"
task :limited_auto_upgrade => :environment do
DataMapper::Model.descendants.entries.reject { |m| m.default_repository_name == :excluded_repository }.each do |model|
puts "Upgrading #{model.name}"
model.auto_migrate!(:default)
end
end