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, options = {})
  assert_valid_add_enum_value_options(options)

  sql = "ALTER TYPE #{quote_generic(enum)} ADD VALUE"

  if options.key?(:if_not_exists)
    ActiveRecord::PostgreSQLExtensions::Features.check_feature(:type_if_not_exists)

    sql << " IF NOT EXISTS" if options[:if_not_exists]
  end

  sql << " #{quote(value)}"

  if options[:before]
    sql << " BEFORE #{quote(options[:before])}"
  elsif options[:after]
    sql << " AFTER #{quote(options[:after])}"
  end

  execute("#{sql};")
end