barinek.com: the official website

Below you'll find a quick stream of consciousness that includes photos, quotes, code snippets, and possibly even a full post. enjoy!

ActiveRecord MySQL Partitions

Check out the below example of how to create partitioned MySQL tables within a Rails Migration. We’ve had a handful of tables that we continually want to partition and a team member wrote the below.

Here’s the migration snippet

class AddResultsTable < ActiveRecord::Migration
  def self.up
    create_partitioned_table :results do |t|

The below creates a results table partitioned by day. The example migration defaults to 4 days back and 4 days forward. We then have a few scripts to manage our partitioned tables.

Here’s the rails source