Skip to content

Latest commit

 

History

History
142 lines (105 loc) · 5.52 KB

README.md

File metadata and controls

142 lines (105 loc) · 5.52 KB

Gem Version Build Status Coverage Status

SchemaPlus::Enums

SchemaPlus::Enums provides support for enum data types in ActiveRecord. Currently the support is limited to defining enum data types, for PostgreSQL only.

SchemaPlus::Enums is part of the SchemaPlus family of Ruby on Rails ActiveRecord extension gems.

Installation

As usual:

gem "schema_plus_enums"                # in a Gemfile
gem.add_dependency "schema_plus_enums" # in a .gemspec

Compatibility

SchemaPlus::Enums is tested on:

  • ruby 2.5 with activerecord 5.2, using postgresql:9.6, postgresql:10, postgresql:11 or postgresql:12
  • ruby 2.5 with activerecord 6.0, using postgresql:9.6, postgresql:10, postgresql:11 or postgresql:12
  • ruby 2.7 with activerecord 5.2, using postgresql:9.6, postgresql:10, postgresql:11 or postgresql:12
  • ruby 2.7 with activerecord 6.0, using postgresql:9.6, postgresql:10, postgresql:11 or postgresql:12
  • ruby 3.0 with activerecord 6.0, using postgresql:9.6, postgresql:10, postgresql:11 or postgresql:12

Usage

In a migration, an enum can be created:

create_enum :color, 'red', 'green', 'blue' # default schema is 'public'
create_enum :color, 'cyan', 'magenta', 'yellow', 'black', schema: 'cmyk'

New values can be added

add_enum_value :color, 'black'
add_enum_value :color, 'red', if_not_exists: true
add_enum_value :color, 'purple', after: 'red'
add_enum_value :color, 'pink', before: 'purple'
add_enum_value :color, 'white', schema: 'cmyk'

Values can be dropped

remove_enum_value :color, 'black'
remove_enum_value :color, 'black', schema: 'cmyk'

Values can be renamed

rename_enum_value :color, 'red', 'orange'
rename_enum_value :color, 'red', 'orange', schema: 'cmyk'

The enum can be renamed

rename_enum :color, :hue
rename_enum :color, :hue, schema: 'cmyk'

And can be dropped:

drop_enum :color
drop_enum :color, schema: 'cmyk'

Release Notes

  • 1.0.0 - Add AR 6.0, Ruby 3.0, and drop AR < 5.2 and Ruby < 2.5. Also add new functionality
  • 0.1.8 - Update dependencies to include AR 5.2.
  • 0.1.7 - Update dependencies to include AR 5.1.* Thanks to @patleb
  • 0.1.6 - Update dependencies to include AR 5.1. Thanks to @willsoto
  • 0.1.5 - Update dependencies to include AR 5.0. Thanks to @jimcavoli
  • 0.1.4 - Missing require
  • 0.1.3 - Explicit gem dependencies
  • 0.1.2 - Upgrade schema_plus_core dependency
  • 0.1.1 - Clean up and sort dumper output. Thanks to @pik
  • 0.1.0 - Initial release, pulled from schema_plus 1.x

Development & Testing

Are you interested in contributing to SchemaPlus::Enums? Thanks! Please follow the standard protocol: fork, feature branch, develop, push, and issue pull request.

Some things to know about to help you develop and test:

  • schema_dev: SchemaPlus::Enums uses schema_dev to facilitate running rspec tests on the matrix of ruby, activerecord, and database versions that the gem supports, both locally and on github actions

    To to run rspec locally on the full matrix, do:

      $ schema_dev bundle install
      $ schema_dev rspec
    

    You can also run on just one configuration at a time; For info, see schema_dev --help or the schema_dev README.

    The matrix of configurations is specified in schema_dev.yml in the project root.

  • schema_plus_core: SchemaPlus::Enums uses the SchemaPlus::Core API that provides middleware callback stacks to make it easy to extend ActiveRecord's behavior. If that API is missing something you need for your contribution, please head over to schema_plus_core and open an issue or pull request.
  • schema_monkey: SchemaPlus::Enums is implemented as a schema_monkey client, using schema_monkey's convention-based protocols for extending ActiveRecord and using middleware stacks.