Method: Sequel::Schema::AlterTableGenerator#add_column

Defined in:
lib/sequel/database/schema_generator.rb

#add_column(name, type, opts = OPTS) ⇒ Object

Add a column with the given name, type, and opts. See CreateTableGenerator#column for the available options.

add_column(:name, String) # ADD COLUMN name varchar(255)

PostgreSQL specific options:

:if_not_exists

Set to true to not add the column if it already exists (PostgreSQL 9.6+)

MySQL specific options:

:after

The name of an existing column that the new column should be positioned after

:first

Create this new column before all other existing columns



456
457
458
459
460
461
462
# File 'lib/sequel/database/schema_generator.rb', line 456

def add_column(name, type, opts = OPTS)
  op = {:op => :add_column, :name => name, :type => type}.merge!(opts)
  index_opts = op.delete(:index)
  @operations << op
  add_index(name, index_opts.is_a?(Hash) ? index_opts : OPTS) if index_opts
  nil
end