Keep a table out of schema.rb during migrations

前端 未结 2 2010
鱼传尺愫
鱼传尺愫 2020-12-11 01:31

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.

2条回答
  •  醉话见心
    2020-12-11 02:01

    Turns out there's an option for just this situation!

    I found it in 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 = []
    

    So all I had to do was stick this at the end of environment.rb:

    ActiveRecord::SchemaDumper.ignore_tables = ["table_name"]
    

    The ignore_tables option will accept regular expressions. For example, to ignore all tables starting with "MS":

    ActiveRecord::SchemaDumper.ignore_tables = [/^MS/]
    

提交回复
热议问题