在迁移期间将表保留在 schema.rb 之外 [英] Keep a table out of schema.rb during migrations
问题描述
作为 之前关于在运行测试时不重新加载巨大的持久表的问题,我需要在运行迁移时将此表保留在 schema.rb 之外.该表直接从 mysqldump 加载,所以我不担心跟踪它.
As a follow-on to an earlier question about not reloading a huge, persistent table when I run my tests, I need to keep this table out of schema.rb when I run my migrations. This table gets loaded directly from a mysqldump, so I'm not worried about keeping track of it.
那么,如何将特定表保留在 schema.rb 之外?
So, how can I keep a specific table out of schema.rb?
推荐答案
原来有一个选项可以解决这种情况!
Turns out there's an option for just this situation!
我在 activerecord-2.3.4/lib/active_record/schema_dumper.rb
中找到它:
##
# :singleton-method:
# A list of tables which should not be dumped to the schema.
# Acceptable values are strings as well as regexp.
# This setting is only used if ActiveRecord::Base.schema_format == :ruby
cattr_accessor :ignore_tables
@@ignore_tables = []
所以我所要做的就是把它放在 environment.rb 的末尾:
So all I had to do was stick this at the end of environment.rb:
ActiveRecord::SchemaDumper.ignore_tables = ["table_name"]
ignore_tables
选项将接受正则表达式.例如,忽略所有以MS"开头的表:
The ignore_tables
option will accept regular expressions. For example, to ignore all tables starting with "MS":
ActiveRecord::SchemaDumper.ignore_tables = [/^MS/]
这篇关于在迁移期间将表保留在 schema.rb 之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!