{"id":29832324,"url":"https://github.com/hauntedhost/enum_from_pg_constraint","last_synced_at":"2025-10-06T16:15:45.197Z","repository":{"id":62558105,"uuid":"50807104","full_name":"hauntedhost/enum_from_pg_constraint","owner":"hauntedhost","description":"Derive a Rails from an existing PostgreSQL constraint","archived":false,"fork":false,"pushed_at":"2016-02-03T15:48:10.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-22T21:47:11.923Z","etag":null,"topics":[],"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/hauntedhost.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2016-02-01T02:04:03.000Z","updated_at":"2016-02-01T03:00:34.000Z","dependencies_parsed_at":"2022-11-03T06:45:28.664Z","dependency_job_id":null,"html_url":"https://github.com/hauntedhost/enum_from_pg_constraint","commit_stats":null,"previous_names":["seanomlor/enum_from_pg_constraint","somlor/enum_from_pg_constraint"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hauntedhost/enum_from_pg_constraint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hauntedhost%2Fenum_from_pg_constraint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hauntedhost%2Fenum_from_pg_constraint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hauntedhost%2Fenum_from_pg_constraint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hauntedhost%2Fenum_from_pg_constraint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hauntedhost","download_url":"https://codeload.github.com/hauntedhost/enum_from_pg_constraint/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hauntedhost%2Fenum_from_pg_constraint/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278639244,"owners_count":26020191,"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","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-07-29T11:35:56.438Z","updated_at":"2025-10-06T16:15:45.166Z","avatar_url":"https://github.com/hauntedhost.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"## EnumFromPgConstraint\n\nDerive a Rails [enum](http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html) from an existing PostgreSQL constraint.\n\n## Usage:\n\nGiven a migration to create table `Thing` with a PostgreSQL constraint:\n\n```ruby\nclass CreateThing \u003c ActiveRecord::Migration\n  def up\n    create_table :things do |t|\n      t.string :name\n      t.string :status, null: false, default: 'pending'\n      t.timestamps null: false\n    end\n\n    execute \u003c\u003c-SQL.strip_heredoc\n      ALTER TABLE things\n      ADD CONSTRAINT allowed_statuses\n      CHECK (status IN (\n        'pending', -- thing not yet attempted\n        'success', -- thing succeeded\n        'failure'  -- thing failed\n      ));\n    SQL\n  end\n\n  def down\n    drop_table :things\n  end\nend\n```\n\nAdd the constraint to your Model:\n\n```ruby\nclass Thing \u003c ActiveRecord::Base\n  include EnumFromPgConstraint\n\n  enum_from_pg_constraint :status\nend\n```\n\n```ruby\n$ rails c\n\u003e Thing.statuses\n=\u003e {\"pending\"=\u003e\"pending\", \"success\"=\u003e\"success\", \"failure\"=\u003e\"failure\"}\n\n\u003e Thing.create(name: 'Hello World!')\n\u003e Thing.pending\n=\u003e [#\u003cThing:0x007fec93d6b5f0\n  id: 1,\n  name: 'Hello World!'\n  status: \"pending\",\n  created_at: Sun, 31 Jan 2016 18:53:25 PST -08:00,\n  updated_at: Sun, 31 Jan 2016 18:53:25 PST -08:00\u003e]\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/somlor/enum_from_pg_constraint. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhauntedhost%2Fenum_from_pg_constraint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhauntedhost%2Fenum_from_pg_constraint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhauntedhost%2Fenum_from_pg_constraint/lists"}