Keep a table out of schema.rb during migrations
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.
So, how can I keep a specific table out of schema.rb?
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"]
If ActiveRecord.schema_format == :ruby, the array can also contain RegExp. For example, to ignore all tables starting with "MS":
ActiveRecord::SchemaDumper.ignore_tables = [/^MS/]
I think that if you keep the migration to generate the table out of your migrations folder, then it won't get run, and in turn won't be used to generate the development database, which should keep it out of the schema.rb.
You can probably figure out some way to run that single migration if you need to outside of the rake task (should just be establishing the connection and then running up on the migration class)
精彩评论