Module: SchemaPlus::ActiveRecord::ConnectionAdapters::PostgreSQLColumn::ClassMethods

Defined in:
lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb

Instance Method Summary collapse

Instance Method Details

#convert_default_value(default, value) ⇒ Object

in some cases (e.g. if change_column_default(table, column, nil) is used), postgresql will return NULL::xxxxx (rather than nil) for a null default – make sure we treat it as nil, not as a function.


54
55
56
57
58
59
60
61
# File 'lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb', line 54

def convert_default_value(default, value)
  default = nil if value.nil? && default =~ /\ANULL::(?:character varying|bpchar|text)\z/m

  if value.nil? && !default.nil?
    value = { :expr => default }
  end
  value
end

#extract_value_from_default_with_schema_plus(default) ⇒ Object


45
46
47
48
# File 'lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb', line 45

def extract_value_from_default_with_schema_plus(default)
  value = extract_value_from_default_without_schema_plus(default)
  convert_default_value(default, value)
end