Method: ActiveRecord::LiteTable::Validator#column

Defined in:
lib/vex/active_record/lite_table.rb

#column(name, type, opts = {}) ⇒ Object

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vex/active_record/lite_table.rb', line 13

def column(name, type, opts = {})
  if !existing_column = klass.columns_hash[name.to_s]
    index_opt = opts.delete :index
    klass.connection.add_column(klass.table_name, name, type, opts)
    klass.reset_column_information
    
    index(name, :unique => (index == :unique)) if index_opt 
    return
  end
  
  return if existing_column.type == type
  
  raise ColumnTypeMismatch, 
    "Column type mismatch on #{klass}##{name}: is #{existing_column.type}, but should be #{type}"
end