简体   繁体   English

DataMapper,Rails 3.1如何跳过存储库中的类迁移?

[英]DataMapper, Rails 3.1 How do I skip migrations on a repository a Class?

I've been searching quite a bit (and experimenting with monkey patching) for a solution to this issue but no avail. 我一直在搜索(并尝试用猴子修补程序)这个问题的解决方案,但无济于事。

I am wondering ... how do I prevent migrations from executing on a class that has DataMapper::Resource included in it? 我想知道...如何防止迁移在其中包含DataMapper :: Resource的类上执行?

In my Rails app, I have a few classes that connect to a different repository than the default. 在我的Rails应用程序中,我有一些类可以连接到与默认存储库不同的存储库。 So they are essentially read only. 因此,它们基本上是只读的。 I want to exclude them from the auto_migrations that happen with rake tasks. 我想将它们从rake任务发生的auto_migrations中排除。 This way I can rest assured I won't be triggering any bad behavior on a database I shouldn't be trying to migrate. 这样,我可以放心,我不会在我不打算迁移的数据库上触发任何不良行为。 (user permissions err out properly so this is more about proper form IMO, the databases around here are maintained by DBAs) (用户权限有误,所以这更多是关于正确的IMO形式,此处的数据库由DBA维护)

This behavior would be only on a few models that utilize a repository separate from the default repo. 仅在少数几个使用与默认存储库分开的存储库的模型上会出现这种情况。 So I still need migrations for the classes using the default repo. 因此,我仍然需要使用默认存储库为类进行迁移。

I having a feeling this is probably much easier than I am finding it to be but I am throwing it out to the DM community. 我觉得这可能比我发现的要容易得多,但是我将其扔给了DM社区。

Any help is appreciated! 任何帮助表示赞赏!

Ugly solution? 解决方案不好?

klass = ToProtect
noop = proc {|*|}
DataMapper::Migrations::Model.instance_methods.each do |meth|
  klass.define_method(meth, &noop)
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM