Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • T torque-postgresql
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 6
    • Issues 6
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Carlos
  • torque-postgresql
  • Wiki
  • Enum

Enum · Changes

Page history
Migration authored Apr 11, 2017 by Carlos's avatar Carlos
Hide whitespace changes
Inline Side-by-side
Enum.md 0 → 100644
View page @ c8a7622e
Enum type manager. It creates a separated class to hold each enum set, that can be used by multiple models, and also keeps the database data consistent. The enum type is shown to have a better performance against string- and integer-like enums.
# How it works
### Migration
First you have to create the enum during your migration, since the database that holds the list of possible values.
```ruby
create_enum :status, %i(created draft published archived)
```
Some other examples are:
```ruby
# ['status_foo', 'status_bar']
create_enum :status, %i(foo bar), prefix: true
# 'foo_tst', 'bar_tst']
create_enum :status, %i(foo bar), suffix: 'tst'
```
Then you can also manage this type along other migrations, like rename, add values, or delete it.
```ruby
# Rename enum by renaming the type it represents
rename_type :status, :content_status
# Adding values
add_enum_values :status, %i(baz qux) # To the end of the list
add_enum_values :status, %i(baz qux), prepend: true # At the beginning of the list
add_enum_values :status, %i(baz qux), after: 'foo' # After a certain value
add_enum_values :status, %i(baz qux), before: 'foo' # Before a certain value
add_enum_values :status, %i(baz qux), prefix: true # With type name as prefix
add_enum_values :status, %i(baz qux), suffix: 'tst' # With a specific suffix
# Deleting an enum by dropping the type it represents
drop_type :status
```
\ No newline at end of file
Clone repository
  • Arel
  • Auxiliary Statements
  • Belongs to Many
  • Box
  • Circle
  • Configuring
  • Date Time Range
  • Distinct On
  • Dynamic Attributes
  • Enum Set
  • Enum
  • Has Many
  • Home
  • Inherited Tables
  • Insert All
View All Pages