ActivePartition
The active_partition gem is a Ruby library designed for Rails application that provides functionality for partitioning data in a database table. Partitioning is a technique used to divide large datasets into smaller, more manageable chunks called partitions. This can improve query performance and make it easier to manage and maintain the data.
Installation
Add this line to your application's Gemfile:
gem 'active_partition'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install active_partition
Usage
TODO: List all use-cases
Apply partitioning to model.
class Event < ActiveRecord::Base
include ActivePartition::Partitionable
self.partitioned_by = "created_at"
self.partition_range = 1.day
self.retention_period = 1.month
self.retention_partition_count = 3
self.partition_start_from = DateTime.new(2021, 1, 1)
end
Event.create(created_at: Time.current)
Event.delete_expired_partitions
Event.premake 1.month, 3
Event.premake 1.year, 2
The partition name following the format
"#{@table_name}_p_#{readable_from}_#{unix_from}_#{unix_to}"
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/active_partition. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the ActivePartition project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.