Method: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#add_enum_value
- Defined in:
- lib/active_record/postgresql_extensions/types.rb
#add_enum_value(enum, value, options = {}) ⇒ Object
Adds a new value to an ENUM.
Options
-
:before- add the new value before this value. -
:after- add the new value after this value. -
:if_not_exists- adds the value if it doesn’t already exist. Available in PostgreSQL 9.3+.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/active_record/postgresql_extensions/types.rb', line 49 def add_enum_value(enum, value, = {}) () sql = "ALTER TYPE #{quote_generic(enum)} ADD VALUE" if .key?(:if_not_exists) ActiveRecord::PostgreSQLExtensions::Features.check_feature(:type_if_not_exists) sql << " IF NOT EXISTS" if [:if_not_exists] end sql << " #{quote(value)}" if [:before] sql << " BEFORE #{quote([:before])}" elsif [:after] sql << " AFTER #{quote([:after])}" end execute("#{sql};") end |