README.md in ar-enum-0.1.0 vs README.md in ar-enum-0.2.0

- old
+ new

@@ -24,10 +24,12 @@ $ gem install ar-enum ## Usage +### Creating enums + To create a `enum` type, use the method `create_enum`. ```ruby # The type is created independently from the table. create_enum :article_status, %w[draft published] @@ -36,10 +38,12 @@ # Use the type `article_status` when defining your column. t.column :status, :article_status, null: false, default: "draft" end ``` +### Dropping enums + To remove the enum, use `drop_enum`. ```ruby drop_enum :article_status ``` @@ -55,10 +59,12 @@ ```ruby change_column :articles, :status, :text drop_enum :article_status ``` +### Adding new labels + Use `add_enum_label` to add new values to the enum type. You can control where the value will be inserted by using `before: label` and `after: label`. ```ruby create_enum :article_status, %w[draft published] @@ -70,19 +76,37 @@ # labels will be sorted as [draft, unlisted, published] add_enum_value :article_status, "unlisted", before: "published" ``` +**WARNING:** PostgreSQL does not have a way of removing values from enum types. + +### Renaming existing labels + Use `rename_enum_label` to rename a value. ```ruby create_enum :article_status, %w[draft unlisted published] -# labels will be [draft, hidden, unlisted] -rename_enum_label :article_status, "unlisted", "hidden" +# labels will be [draft, unlisted, live] +rename_enum_label :article_status, "published", "live" ``` -**WARNING:** PostgreSQL does not have a way of removing values from enum types. +### Reversing changes + +The following commands can be reversed: + +- `create_enum` +- `rename_enum_label` + + +```ruby +class CreateColorEnumClass < ActiveRecord::Migration + def change + create_enum :color, %w[red blue black] + end +end +``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.