It is straightforward to ignore tables when your schema format is :ruby
, but is there a way to do it when your schema format is :sql
?
Ideally something like this in environment.rb
:
ActiveRecord::SQLDumper.ignore_tables = ['table_name']
After a quick perusal through the AR source code it looks unpromising.
Ruby on Rails - Migrations. Rails Migration allows you to use Ruby to define changes to your database schema, making it possible to use a version control system to keep things synchronized with the actual code. Teams of developers − If one person makes a schema change, the other developers just need to update, and run "rake migrate".
When you add a new model to a Rails application, it generates a migration to create the corresponding table for you. If that’s not what you need, you can write your own. If you need functionality that’s not supported by Active Record, you can execute SQL inside a migration.
Rails doesn’t know how to rollback our SQL statement. You’re only supposed to place directives in a change method that Rails knows how to revert. Let’s write a migration that can be rolled back. Generate another migration named “AddAnotherUser” and open the file.
In the context of a high-load database, not being able to use a specific table for more than a few seconds can be catastrophic: all requests will start queuing and it may put the whole platform down. Let’s look at a few examples of Rails migrations, the kind of locking they require, and how to mitigate their impact.
There is currently no way to do this, when the schema format is set to :sql
, Rails doesn't go through the regular SchemaDumper
but instead uses the tasks in ActiveRecord::Tasks::PostgreSQLDatabaseTasks
to do the dump, check it out here.
The code is quite straightforward. I came up with a simple patch for ActiveRecord
that should work as expected. It relies on setting the tables to ignore in your database.yml
file. It basically adds the following code:
ignore_tables = configuration['ignore_tables']
unless ignore_tables.blank?
args += ignore_tables.split(',').map do |table|
"-T #{table}"
end
end
I just submitted a pull request to rails with those changes. In case you'd want to test it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With