No commit activity in last 3 years
No release in over 3 years
This rubygem does not have a description or summary.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

<= 6.0.0, >= 4.2.0
>= 0
 Project Readme

SlidingPartition

Gem Version Code Climate GPA Code Climate Coverage Gemnasium Status Travis CI Status

Table of Contents

  • Features
  • Screencasts
  • Requirements
  • Setup
  • Usage
    • Rails
  • Tests
  • Versioning
  • Code of Conduct
  • Contributions
  • License
  • History
  • Credits

Features

Screencasts

Requirements

  1. MRI 2.3.1

Setup

For a secure install, type the following (recommended):

gem cert --add <(curl --location --silent /gem-public.pem)
gem install sliding_partition --trust-policy MediumSecurity

NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while allowing the installation of unsigned dependencies since they are beyond the scope of this gem.

For an insecure install, type the following (not recommended):

gem install sliding_partition

Add the following to your Gemfile:

gem "sliding_partition"

Usage

Rails

Create a migration for the parent table. This table won't contain any data itself, but gives us the skeleton that the other tables will inherit, and will be used by the model for queries.

class AddEventsTable
  def change
    create_table :events do |t|
      t.string    :name
      t.timestamp :event_at
      t.timestamps
    end

    add_index :events, [:name, :event_at]
  end
end

Once that table exists, set up a config to tell SlidingPartition how you want it partitioned:

# config/sliding_partitions.rb

SlidingPartition.define(Event) do |partition|
  partition.time_column          = :event_at
  partition.suffix               = "%Y%m%d"   # A strftime-formatted string, will be appended to all partition table names
  partition.partition_interval   = 1.month
  partition.retention_interval   = 6.months
end

Now, have SlidingPartition manage these tables.

SlidingPartition.initialize!

Finally, you'll want SlidingPartition to run periodically, to ensure the next period's table is created ahead of time. We recommend that you run it several times leading up to the next date, it does no harm to have the empty table sitting around for future use, in case something fails and it takes it awhile to fix it. We also recommend you put this in a background job, and trigger it using clockwork or some other recurring job spawner. SlidingPartition comes with an ActiveJob Job for this purpose.

module Clockwork

  every 1.day do
    SlidingPartition::Job.perform_later
  end

end

Tests

To test, run:

bundle exec rake

Versioning

Read Semantic Versioning for details. Briefly, it means:

  • Patch (x.y.Z) - Incremented for small, backwards compatible bug fixes.
  • Minor (x.Y.z) - Incremented for new, backwards compatible public API enhancements and/or bug fixes.
  • Major (X.y.z) - Incremented for any backwards incompatible public API changes.

Code of Conduct

Please note that this project is released with a CODE OF CONDUCT. By participating in this project you agree to abide by its terms.

Contributions

Read CONTRIBUTING for details.

License

Copyright (c) 2016 . Read the LICENSE for details.

History

Read the CHANGELOG for details. Built with Gemsmith.

Credits

Developed by Paul Sadauskas at .