{"id":15152715,"url":"https://github.com/starulli/rails-clusterid","last_synced_at":"2025-09-29T23:32:03.464Z","repository":{"id":56890529,"uuid":"464718516","full_name":"starulli/rails-clusterid","owner":"starulli","description":"ActiveRecord support for ClusterId primary keys","archived":true,"fork":false,"pushed_at":"2023-06-29T02:34:12.000Z","size":203,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-10T12:59:47.592Z","etag":null,"topics":["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/starulli.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"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":"2022-03-01T02:37:52.000Z","updated_at":"2023-06-29T02:35:31.000Z","dependencies_parsed_at":"2022-08-20T15:20:49.681Z","dependency_job_id":null,"html_url":"https://github.com/starulli/rails-clusterid","commit_stats":null,"previous_names":["tinychameleon/rails-clusterid"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starulli%2Frails-clusterid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starulli%2Frails-clusterid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starulli%2Frails-clusterid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starulli%2Frails-clusterid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/starulli","download_url":"https://codeload.github.com/starulli/rails-clusterid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234673608,"owners_count":18869698,"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":["ruby","ruby-on-rails"],"created_at":"2024-09-26T16:21:42.237Z","updated_at":"2025-09-29T23:32:03.023Z","avatar_url":"https://github.com/starulli.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rails ClusterId\nA Ruby on Rails plugin for using [ClusterId](https://github.com/tinychameleon/clusterid) values as primary keys.\n\n[![Gem Version](https://badge.fury.io/rb/rails-clusterid.svg)](https://badge.fury.io/rb/rails-clusterid)\n\n## What's in the box?\n✅ Simple usage documentation written to get started fast. [Check it out!](#usage)\n\n⚡ A pretty fast implementation of Crockford32 in pure ruby. [Check it out!](#benchmarks)\n\n📚 YARD generated API documentation for the library. [Check it out!](https://tinychameleon.github.io/rails-clusterid/)\n\n🤖 RBS types for your type checking wants. [Check it out!](./sig/rails-clusterid.rbs)\n\n💎 Tests against many Ruby versions. [Check it out!](#ruby-versions)\n\n🔒 MFA protection on all gem owners. [Check it out!](https://rubygems.org/gems/rails-clusterid)\n\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rails-clusterid'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install rails-clusterid\n\n### Compatibility\n#### Ruby Versions\nThis gem is tested against the following Ruby versions:\n\n- 2.7.5\n- 3.0.3\n- 3.1.1\n\n#### Rails Versions\nThis gem is tested against the following Ruby on Rails versions:\n\n- 7.0.x\n\n## Usage\nTo use `ClusterId` values for all model primary keys automatically create a new initializer for your application.\n\n```ruby\n# config/initializers/clusterid.rb\n\nRails.application.config.clusterid do |c|\n  c.add_generator(:default, ClusterId::V1::Generator.new)\nend\n\nRails.application.config.generators do |g|\n  g.orm :active_record, primary_key_type: :clusterid\nend\n```\n\nThe above configures the `rails-clusterid` plugin to use version 1 `ClusterId` values by default and configures ActiveRecord to use ClusterId values for primary keys.\nYou must add a `:default` generator, and the generator itself is configurable.\nSee the [ClusterId repository for information on how to configure a generator](https://github.com/tinychameleon/clusterid).\n\nOnce the initializers are complete, include the `ClusterId::Rails::Model` concern into your `ApplicationRecord`.\n\n```ruby\n# app/models/application_record.rb\n\nclass ApplicationRecord \u003c ActiveRecord::Base\n  primary_abstract_class\n\n  include ClusterId::Rails::Model\nend\n```\n\nMigrations are supported and will automatically use ClusterId values as primary keys and foreign keys.\nThis includes join tables.\n\n### Manual Usage \nIf you would like to selectively use `ClusterId` values across your models and migrations, just manually select the `:clusterid` type.\n\n```\n$ rails g model person name:string --primary-key-type=clusterid\n```\n\nYou can use it within migration files as well.\n\n```ruby\ncreate_table :people, id: :clusterid do |t|\n  t.string :name\nend\n```\n\nSince the type works with ActiveRecord you can also specify it as a foreign key.\n\n```ruby\ncreate_table :hobbies, id: :clusterid do |t|\n  t.string :name\n\n  t.references :person, null: false, foreign_key: true, type: :clusterid\nend\n```\n\n### ClusterId Ordering\nThe ClusterId values are k-sortable and will be ordered by creation time before any other part of the ID.\nIf you would like to read values from the ClusterId binary data stored within the database, you can deconstruct the raw data using a function.\n\nFor example, to extract the timestamp data while using PostgreSQL:\n```sql\nto_timestamp(('x' || encode(substring(id for 8), 'hex'))::bit(64)::bigint / 1000.0)\n```\n\nSee the [ClusterId repository for documentation about the binary representation](https://github.com/tinychameleon/clusterid).\n\n### More Information\nFor more detailed information about the library [see the API documentation](https://tinychameleon.github.io/rails-clusterid/).\n\n\n## Contributing\n\n### Development\nThis plugin relies heavily on Docker for development; ensure it is running to use most development commands.\n\nTo get started development on this gem run the `bin/setup` command. This will build the testing Docker image and run the tests and linting commands to ensure everything is working properly.\n\n### Testing\nUse the `bundle exec rake test` command to run unit tests. To install the gem onto your local machine for general integration testing use `bundle exec rake install`.\n\nTo test the gem against each supported version of Ruby and databases use `bin/test_versions`. This will create a Docker image for each version and run the tests and linting steps.\n\n### Releasing\nDo the following to release a new version of this gem:\n\n- Update the version number in [lib/rails-clusterid/version.rb](./lib/rails-clusterid/version.rb)\n- Ensure necessary documentation changes are complete\n- Ensure changes are in the [CHANGELOG.md](./CHANGELOG.md)\n- Create the new release using `bundle exec rake release`\n\nAfter this is done the following side-effects should be visible:\n\n- A new git tag for the version number should exist\n- Commits for the new version should be pushed to GitHub\n- The new gem should be available on [rubygems.org](https://rubygems.org).\n\nFinally, update the documentation hosted on GitHub Pages:\n\n- Check-out the `gh-pages` branch\n- Merge `main` into the `gh-pages` branch\n- Generate the documentation with `bundle exec rake yard`\n- Commit the documentation on the `gh-pages` branch\n- Push the new documentation so GitHub Pages can deploy it\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarulli%2Frails-clusterid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarulli%2Frails-clusterid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarulli%2Frails-clusterid/lists"}