简体   繁体   中英

Ruby on Rails / ActiveRecord and Table Partitions

I've read the documentation and been able to find anything to assist me so far. I've also read a large number of blog articles, but nothing seems to answer my question directly:

Is it possible to manage table partitions in an InnoDB table with ActiveRecord? I'd really prefer to keep things very clean and I'm trying to avoid writing external scripts to try to automate the creation/deletion of partitions over time.

Yes, you can! But I don't think that there is a gem that will do it for you.

In order to perform partition management you need to do the hard work by yourself and send the command that you need to run on the DB directly via the connection in the following way

ActiveRecord::Base.connection.execute("ALTER TABLE your_table drop partition p0")

An additional solution has emerged since I first asked this question. While the solution does require the use of Postgresql over MySQL or Maria, this isn't a high hurdle since it is more or less the default database for Rails.

The Partitioned gem on Github specifically handles all of the partitioning mechanics in a nice, Railsy way.

I can't see how ActiveRecord could do things like DROP PARTITION and REORGANIZE PARTITION . Can it even call a Stored procedure? If so, then build one similar to what is in my blog and call it from Rails.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM