在迁移期间将表保留在 schema.rb 之外

编程入门 行业动态 更新时间:2024-10-13 16:15:56
本文介绍了在迁移期间将表保留在 schema.rb 之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

作为 之前关于在运行测试时不重新加载巨大的持久表的问题,我需要在运行迁移时将此表保留在 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 之外

本文发布于:2023-10-18 04:29:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1503114.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将表保   schema   rb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!