Method: Sequel::Schema::AlterTableGenerator#add_primary_key

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

#add_primary_key(name, opts = OPTS) ⇒ Object

Add a primary key. See CreateTableGenerator#column for the available options. Like add_foreign_key, if you specify the column name as an array, it just creates a constraint:

add_primary_key(:id) # ADD COLUMN id serial PRIMARY KEY
add_primary_key([:artist_id, :name]) # ADD PRIMARY KEY (artist_id, name)

PostgreSQL specific options:

:include

Include additional columns in the underlying index, to allow for index-only scans in more cases (PostgreSQL 11+).

:using_index

Use the USING INDEX clause to specify an existing unique index

:without_overlaps

Use WITHOUT OVERLAPS clause to specify an exclusion constraint on the final column (PostgreSQL 18+, composite primary keys only).



554
555
556
557
558
# File 'lib/sequel/database/schema_generator.rb', line 554

def add_primary_key(name, opts = OPTS)
  return add_composite_primary_key(name, opts) if name.is_a?(Array)
  opts = @db.serial_primary_key_options.merge(opts)
  add_column(name, opts.delete(:type), opts)
end