{"id":13879746,"url":"https://github.com/fnando/ar-enum","last_synced_at":"2025-07-30T21:06:08.304Z","repository":{"id":47020523,"uuid":"174809336","full_name":"fnando/ar-enum","owner":"fnando","description":"Add support for creating `ENUM` types in PostgreSQL with ActiveRecord","archived":false,"fork":false,"pushed_at":"2022-01-18T21:06:10.000Z","size":49,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T05:51:12.483Z","etag":null,"topics":["activerecord","enum","postgresql","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/fnando.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["fnando"],"custom":["https://paypal.me/nandovieira/🍕"]}},"created_at":"2019-03-10T10:39:23.000Z","updated_at":"2022-09-29T01:02:31.000Z","dependencies_parsed_at":"2022-08-23T12:11:30.480Z","dependency_job_id":null,"html_url":"https://github.com/fnando/ar-enum","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Far-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Far-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Far-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Far-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/ar-enum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249294945,"owners_count":21246014,"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":["activerecord","enum","postgresql","rails"],"created_at":"2024-08-06T08:02:31.244Z","updated_at":"2025-04-17T00:52:35.577Z","avatar_url":"https://github.com/fnando.png","language":"Ruby","funding_links":["https://github.com/sponsors/fnando","https://paypal.me/nandovieira/🍕"],"categories":["Ruby"],"sub_categories":[],"readme":"# ar-enum\n\n[![Tests](https://github.com/fnando/ar-enum/workflows/Tests/badge.svg)](https://github.com/fnando/ar-enum)\n[![Gem](https://img.shields.io/gem/v/ar-enum.svg)](https://rubygems.org/gems/ar-enum)\n[![Gem](https://img.shields.io/gem/dt/ar-enum.svg)](https://rubygems.org/gems/ar-enum)\n\nAdd support for creating `ENUM` types in PostgreSQL with ActiveRecord. This gem\nis no longer required for Rails 7.0+.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"ar-enum\"\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install ar-enum\n\n## Usage\n\n### Creating enums\n\nTo create a `enum` type, use the method `create_enum`.\n\n```ruby\n# The type is created independently from the table.\ncreate_enum :article_status, %w[draft published]\n\ncreate_table :articles do |t|\n  # Use the type `article_status` when defining your column.\n  t.column :status, :article_status, null: false, default: \"draft\"\nend\n```\n\nYou can even use the type shortcut if you want; i.e. you can use\n`t.article_status` instead of `t.column`.\n\n```ruby\n# The type is created independently from the table.\ncreate_enum :article_status, %w[draft published]\n\ncreate_table :articles do |t|\n  # Use the type `article_status` when defining your column.\n  t.article_status :status, null: false, default: \"draft\"\nend\n```\n\n### Dropping enums\n\nTo remove the enum, use `drop_enum`.\n\n```ruby\ndrop_enum :article_status\n```\n\nYou'll receive a `ActiveRecord::StatementInvalid` if any of your tables have a\ndependency on the type; i.e. you're have a column using that enum. You can drop\nthese columns by specifying `cascade: true`.\n\n```ruby\ndrop_enum :article_status, cascade: true\n```\n\nIf you don't want to remove the column, change the column type before dropping\nthe enum.\n\n```ruby\nchange_column :articles, :status, :text\ndrop_enum :article_status\n```\n\n### Adding new labels\n\nUse `add_enum_label` to add new values to the enum type. You can control where\nthe value will be inserted by using `before: label` and `after: label`.\n\n```ruby\ncreate_enum :article_status, %w[draft published]\n\n# labels will be sorted as [draft, published, unlisted]\nadd_enum_label :article_status, \"unlisted\"\n\n# labels will be sorted as [draft, unlisted, published]\nadd_enum_value :article_status, \"unlisted\", after: \"draft\"\n\n# labels will be sorted as [draft, unlisted, published]\nadd_enum_value :article_status, \"unlisted\", before: \"published\"\n```\n\n**WARNING:** PostgreSQL does not have a way of removing values from enum types.\n\n### Renaming existing labels\n\nUse `rename_enum_label` to rename a value.\n\n```ruby\ncreate_enum :article_status, %w[draft unlisted published]\n\n# labels will be [draft, unlisted, live]\nrename_enum_label :article_status, \"published\", \"live\"\n```\n\n### Reversing changes\n\nThe following commands can be reversed:\n\n- `create_enum`\n- `rename_enum_label`\n\n```ruby\nclass CreateColorEnumClass \u003c ActiveRecord::Migration\n  def change\n    create_enum :color, %w[red blue black]\n  end\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run\n`rake test` to run the tests. You can also run `bin/console` for an interactive\nprompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To\nrelease a new version, update the version number in `version.rb`, and then run\n`bundle exec rake release`, which will create a git tag for the version, push\ngit commits and tags, and push the `.gem` file to\n[rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/fnando/ar-enum. This project is intended to be a safe,\nwelcoming space for collaboration, and contributors are expected to adhere to\nthe [Contributor Covenant](contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the\n[MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Far-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Far-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Far-enum/lists"}