edge badge
Methods
B
C
D
H
I
J
L
M
N
O
P
S
T
U
X
Instance Public methods
bigserial(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 53
def bigserial(*args, **options)
  args.each { |name| column(name, :bigserial, options) }
end
bit(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 57
def bit(*args, **options)
  args.each { |name| column(name, :bit, options) }
end
bit_varying(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 61
def bit_varying(*args, **options)
  args.each { |name| column(name, :bit_varying, options) }
end
box(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 133
def box(*args, **options)
  args.each { |name| column(name, :box, options) }
end
cidr(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 65
def cidr(*args, **options)
  args.each { |name| column(name, :cidr, options) }
end
circle(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 145
def circle(*args, **options)
  args.each { |name| column(name, :circle, options) }
end
citext(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 69
def citext(*args, **options)
  args.each { |name| column(name, :citext, options) }
end
daterange(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 73
def daterange(*args, **options)
  args.each { |name| column(name, :daterange, options) }
end
hstore(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 77
def hstore(*args, **options)
  args.each { |name| column(name, :hstore, options) }
end
inet(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 81
def inet(*args, **options)
  args.each { |name| column(name, :inet, options) }
end
int4range(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 89
def int4range(*args, **options)
  args.each { |name| column(name, :int4range, options) }
end
int8range(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 93
def int8range(*args, **options)
  args.each { |name| column(name, :int8range, options) }
end
interval(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 85
def interval(*args, **options)
  args.each { |name| column(name, :interval, options) }
end
jsonb(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 97
def jsonb(*args, **options)
  args.each { |name| column(name, :jsonb, options) }
end
line(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 125
def line(*args, **options)
  args.each { |name| column(name, :line, options) }
end
lseg(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 129
def lseg(*args, **options)
  args.each { |name| column(name, :lseg, options) }
end
ltree(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 101
def ltree(*args, **options)
  args.each { |name| column(name, :ltree, options) }
end
macaddr(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 105
def macaddr(*args, **options)
  args.each { |name| column(name, :macaddr, options) }
end
money(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 109
def money(*args, **options)
  args.each { |name| column(name, :money, options) }
end
numrange(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 113
def numrange(*args, **options)
  args.each { |name| column(name, :numrange, options) }
end
oid(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 117
def oid(*args, **options)
  args.each { |name| column(name, :oid, options) }
end
path(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 137
def path(*args, **options)
  args.each { |name| column(name, :path, options) }
end
point(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 121
def point(*args, **options)
  args.each { |name| column(name, :point, options) }
end
polygon(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 141
def polygon(*args, **options)
  args.each { |name| column(name, :polygon, options) }
end
primary_key(name, type = :primary_key, **options)

Defines the primary key field. Use of the native PostgreSQL UUID type is supported, and can be used by defining your tables as such:

create_table :stuffs, id: :uuid do |t|
  t.string :content
  t.timestamps
end

By default, this will use the +gen_random_uuid()+ function from the pgcrypto extension. As that extension is only available in PostgreSQL 9.4+, for earlier versions an explicit default can be set to use +uuid_generate_v4()+ from the uuid-ossp extension instead:

create_table :stuffs, id: false do |t|
  t.primary_key :id, :uuid, default: "uuid_generate_v4()"
  t.uuid :foo_id
  t.timestamps
end

To enable the appropriate extension, which is a requirement, use the enable_extension method in your migrations.

To use a UUID primary key without any of the extensions, set the :default option to nil:

create_table :stuffs, id: false do |t|
  t.primary_key :id, :uuid, default: nil
  t.uuid :foo_id
  t.timestamps
end

You may also pass a custom stored procedure that returns a UUID or use a different UUID generation function from another library.

Note that setting the UUID primary key default value to nil will require you to assure that you always provide a UUID value before saving a record (as primary keys cannot be nil). This might be done via the SecureRandom.uuid method and a before_save callback, for instance.

# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 45
def primary_key(name, type = :primary_key, **options)
  if type == :uuid
    options[:default] = options.fetch(:default, "gen_random_uuid()")
  end

  super
end
serial(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 149
def serial(*args, **options)
  args.each { |name| column(name, :serial, options) }
end
tsrange(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 153
def tsrange(*args, **options)
  args.each { |name| column(name, :tsrange, options) }
end
tstzrange(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 157
def tstzrange(*args, **options)
  args.each { |name| column(name, :tstzrange, options) }
end
tsvector(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 161
def tsvector(*args, **options)
  args.each { |name| column(name, :tsvector, options) }
end
uuid(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 165
def uuid(*args, **options)
  args.each { |name| column(name, :uuid, options) }
end
xml(*args, **options)
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb, line 169
def xml(*args, **options)
  args.each { |name| column(name, :xml, options) }
end