在迁移期间将表格从schema.rb中保留
作为我在运行测试时不重新加载巨大的持久表的早期问题的后续内容 ,我需要在运行迁移时将此表保留在schema.rb之外。 这个表直接从mysqldump加载,所以我不担心跟踪它。
那么,如何从schema.rb中保留一个特定的表?
事实certificate,这种情况有一个选择!
我在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 = []
所以我所要做的就是在环境结束时坚持这个.rb:
ActiveRecord::SchemaDumper.ignore_tables = ["table_name"]
ignore_tables
选项将接受正则表达式。 例如,要忽略以“MS”开头的所有表:
ActiveRecord::SchemaDumper.ignore_tables = [/^MS/]
我认为,如果您继续迁移以从迁移文件夹中生成表,那么它将无法运行,反过来也不会用于生成开发数据库,这应该使其不受schema.rb的限制。 。
如果你需要在rake任务之外(你应该只是建立连接,然后在迁移类上运行),你可能会想出一些运行单一迁移的方法。