Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
603 views
in Technique[技术] by (71.8m points)

ruby on rails - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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/]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...