{"id":14955762,"url":"https://github.com/thien0291/active_partition","last_synced_at":"2025-10-06T09:31:18.252Z","repository":{"id":246745231,"uuid":"822455023","full_name":"thien0291/active_partition","owner":"thien0291","description":"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.","archived":false,"fork":false,"pushed_at":"2024-08-01T17:04:27.000Z","size":32,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-14T11:47:10.769Z","etag":null,"topics":["gem","partition","partitioning","postgresql","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thien0291.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-01T07:28:40.000Z","updated_at":"2025-01-11T07:46:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"96c071c1-ccfb-4520-b93b-d6fc092d01d5","html_url":"https://github.com/thien0291/active_partition","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"c632c5d9145b483d233e48af955503190cfcb3c7"},"previous_names":["thien0291/active_partition"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thien0291%2Factive_partition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thien0291%2Factive_partition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thien0291%2Factive_partition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thien0291%2Factive_partition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thien0291","download_url":"https://codeload.github.com/thien0291/active_partition/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235515429,"owners_count":19002481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gem","partition","partitioning","postgresql","ruby","ruby-on-rails"],"created_at":"2024-09-24T13:11:41.399Z","updated_at":"2025-10-06T09:31:17.830Z","avatar_url":"https://github.com/thien0291.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActivePartition\n\nThe 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.\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'active_partition'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install active_partition\n\n## Usage\n\nTODO: List all use-cases\n\nApply partitioning to model.\n\n```ruby\nclass Event \u003c ActiveRecord::Base\n  include ActivePartition::Partitionable\n  # the name of partitioned colunn\n  self.partitioned_by = \"created_at\"\n  # You can change this range over time. from months to hours.\n  self.partition_range = 1.day\n\n  # You can choose 1 of the following 2 options\n  # Keep all partitions within a time period\n  self.retention_period = 1.month\n  # Keep last n partitions\n  self.retention_partition_count = 3\n  # The start time of the partition range, default is Time.current.beginning_of_hour.utc\n  # For example, if today is July 31, and you create a new record.\n  # if the partition_start_from is 2021-01-01, the new partition should cover [2024-07-01 00:00:00 UTC...2024-08-01 00:00:00 UTC]\n  # if the partition_start_from is nil, the coverage can be [2024-07-31 08:00:00 UTC...2024-08-31 08:00:00 UTC]\n  # This configuration help us to sync partition ranges of all partitioned tables.\n  # Therefore, you can easy to join/drop/manage related partitioned tables.\n  self.partition_start_from = DateTime.new(2021, 1, 1)\nend\n\n# auto create a new partition if needed.\nEvent.create(created_at: Time.current)\n# create partition events_p_240404_04_1712203200_1712289600 from 2024-04-04 04:00:00 UTC to 2024-04-05 04:00:00 UTC\n\n# Delete expired partition (you can set cron job to run this command)\nEvent.delete_expired_partitions\n\n# `premake` is also supported. create 3 1-month partitions\nEvent.premake 1.month, 3\n# create partition outgoing_events_p_240801_04_1722484800_1725163200 from 2024-08-01 04:00:00 UTC to 2024-09-01 04:00:00 UTC\n# create partition outgoing_events_p_240901_04_1725163200_1727755200 from 2024-09-01 04:00:00 UTC to 2024-10-01 04:00:00 UTC\n# create partition outgoing_events_p_241001_04_1727755200_1730433600 from 2024-10-01 04:00:00 UTC to 2024-11-01 04:00:00 UTC\n\n# You can change premake period if needed. For example, create 2 1-year partition.\nEvent.premake 1.year, 2\n# create partition outgoing_events_p_241101_04_1730433600_1761969600 from 2024-11-01 04:00:00 UTC to 2025-11-01 04:00:00 UTC\n# create partition outgoing_events_p_251101_04_1761969600_1793505600 from 2025-11-01 04:00:00 UTC to 2026-11-01 04:00:00 UTC\n```\n\nThe partition name following the format\n```ruby\n\"#{@table_name}_p_#{readable_from}_#{unix_from}_#{unix_to}\"\n```\n\n\n\n## Development\n\nAfter 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.\n\nTo 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](https://rubygems.org).\n\n## Contributing\n\nBug 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](https://github.com/[USERNAME]/active_partition/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the ActivePartition project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/active_partition/blob/main/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthien0291%2Factive_partition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthien0291%2Factive_partition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthien0291%2Factive_partition/lists"}