Project

sql_enum

0.07
Low commit activity in last 3 years
A long-lived project that still receives updates
Enable using native sql enums
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.0
~> 13.0
>= 0

Runtime

 Project Readme

SqlEnum

Enables usage of native sql enums with ActiveRecord

NOTE

Version 1.0 of this is compatible with Rails 7 and above.

For Rails versions below Rails 7, use version 0.4

Installation

Add this line to your application's Gemfile:

gem 'sql_enum'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sql_enum

Usage

Migrations

Use a part of table definition:

class CreateUsers < ActiveRecord::Migration[5.1]
  def change
    create_table :users do |t|
      t.enum :status, limit: [:active, :pending, :inactive], default: :active

      t.timestamps
    end
  end
end

Or add an enum column:

add_column :users, :status, :enum, limit: [:active, :pending, :inactive], default: :active

ActiveRecord

class User < ActiveRecord::Base
  sql_enum :status
end

Development

Testing

Run docker-compose run --rm rspec to run the specs in a docker container alongside Mysql.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/1debit/sql_enum. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

Inspiration from native_enum

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the SqlEnum project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.