Module: ActiveRecord::ConnectionAdapters::PostgreSQL::ColumnMethods
- Included in:
- Table, TableDefinition
- Defined in:
- lib/active_record/connection_adapters/postgresql/schema_definitions.rb
Instance Method Summary collapse
- #bigserial(*args, **options) ⇒ Object
- #bit(*args, **options) ⇒ Object
- #bit_varying(*args, **options) ⇒ Object
- #box(*args, **options) ⇒ Object
- #cidr(*args, **options) ⇒ Object
- #circle(*args, **options) ⇒ Object
- #citext(*args, **options) ⇒ Object
- #daterange(*args, **options) ⇒ Object
- #hstore(*args, **options) ⇒ Object
- #inet(*args, **options) ⇒ Object
- #int4range(*args, **options) ⇒ Object
- #int8range(*args, **options) ⇒ Object
- #json(*args, **options) ⇒ Object
- #jsonb(*args, **options) ⇒ Object
- #line(*args, **options) ⇒ Object
- #lseg(*args, **options) ⇒ Object
- #ltree(*args, **options) ⇒ Object
- #macaddr(*args, **options) ⇒ Object
- #money(*args, **options) ⇒ Object
- #numrange(*args, **options) ⇒ Object
- #path(*args, **options) ⇒ Object
- #point(*args, **options) ⇒ Object
- #polygon(*args, **options) ⇒ Object
-
#primary_key(name, type = :primary_key, **options) ⇒ Object
Defines the primary key field.
- #serial(*args, **options) ⇒ Object
- #tsrange(*args, **options) ⇒ Object
- #tstzrange(*args, **options) ⇒ Object
- #tsvector(*args, **options) ⇒ Object
- #uuid(*args, **options) ⇒ Object
- #xml(*args, **options) ⇒ Object
Instance Method Details
#bigserial(*args, **options) ⇒ Object
38 39 40 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 38 def bigserial(*args, **) args.each { |name| column(name, :bigserial, ) } end |
#bit(*args, **options) ⇒ Object
42 43 44 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 42 def bit(*args, **) args.each { |name| column(name, :bit, ) } end |
#bit_varying(*args, **options) ⇒ Object
46 47 48 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 46 def (*args, **) args.each { |name| column(name, :bit_varying, ) } end |
#box(*args, **options) ⇒ Object
114 115 116 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 114 def box(*args, **) args.each { |name| column(name, :box, ) } end |
#cidr(*args, **options) ⇒ Object
50 51 52 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 50 def cidr(*args, **) args.each { |name| column(name, :cidr, ) } end |
#circle(*args, **options) ⇒ Object
126 127 128 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 126 def circle(*args, **) args.each { |name| column(name, :circle, ) } end |
#citext(*args, **options) ⇒ Object
54 55 56 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 54 def citext(*args, **) args.each { |name| column(name, :citext, ) } end |
#daterange(*args, **options) ⇒ Object
58 59 60 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 58 def daterange(*args, **) args.each { |name| column(name, :daterange, ) } end |
#hstore(*args, **options) ⇒ Object
62 63 64 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 62 def hstore(*args, **) args.each { |name| column(name, :hstore, ) } end |
#inet(*args, **options) ⇒ Object
66 67 68 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 66 def inet(*args, **) args.each { |name| column(name, :inet, ) } end |
#int4range(*args, **options) ⇒ Object
70 71 72 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 70 def int4range(*args, **) args.each { |name| column(name, :int4range, ) } end |
#int8range(*args, **options) ⇒ Object
74 75 76 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 74 def int8range(*args, **) args.each { |name| column(name, :int8range, ) } end |
#json(*args, **options) ⇒ Object
78 79 80 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 78 def json(*args, **) args.each { |name| column(name, :json, ) } end |
#jsonb(*args, **options) ⇒ Object
82 83 84 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 82 def jsonb(*args, **) args.each { |name| column(name, :jsonb, ) } end |
#line(*args, **options) ⇒ Object
106 107 108 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 106 def line(*args, **) args.each { |name| column(name, :line, ) } end |
#lseg(*args, **options) ⇒ Object
110 111 112 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 110 def lseg(*args, **) args.each { |name| column(name, :lseg, ) } end |
#ltree(*args, **options) ⇒ Object
86 87 88 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 86 def ltree(*args, **) args.each { |name| column(name, :ltree, ) } end |
#macaddr(*args, **options) ⇒ Object
90 91 92 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 90 def macaddr(*args, **) args.each { |name| column(name, :macaddr, ) } end |
#money(*args, **options) ⇒ Object
94 95 96 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 94 def money(*args, **) args.each { |name| column(name, :money, ) } end |
#numrange(*args, **options) ⇒ Object
98 99 100 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 98 def numrange(*args, **) args.each { |name| column(name, :numrange, ) } end |
#path(*args, **options) ⇒ Object
118 119 120 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 118 def path(*args, **) args.each { |name| column(name, :path, ) } end |
#point(*args, **options) ⇒ Object
102 103 104 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 102 def point(*args, **) args.each { |name| column(name, :point, ) } end |
#polygon(*args, **options) ⇒ Object
122 123 124 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 122 def polygon(*args, **) args.each { |name| column(name, :polygon, ) } end |
#primary_key(name, type = :primary_key, **options) ⇒ Object
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.
end
By default, this will use the uuid_generate_v4() function from the uuid-ossp
extension, which MUST be enabled on your database. To enable the uuid-ossp
extension, you can use the enable_extension
method in your migrations. To use a UUID primary key without uuid-ossp
enabled, you can 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.
end
You may also pass a different UUID generation function from uuid-ossp
or 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.
33 34 35 36 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 33 def primary_key(name, type = :primary_key, **) [:default] = .fetch(:default, 'uuid_generate_v4()') if type == :uuid super end |
#serial(*args, **options) ⇒ Object
130 131 132 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 130 def serial(*args, **) args.each { |name| column(name, :serial, ) } end |
#tsrange(*args, **options) ⇒ Object
134 135 136 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 134 def tsrange(*args, **) args.each { |name| column(name, :tsrange, ) } end |
#tstzrange(*args, **options) ⇒ Object
138 139 140 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 138 def tstzrange(*args, **) args.each { |name| column(name, :tstzrange, ) } end |
#tsvector(*args, **options) ⇒ Object
142 143 144 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 142 def tsvector(*args, **) args.each { |name| column(name, :tsvector, ) } end |
#uuid(*args, **options) ⇒ Object
146 147 148 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 146 def uuid(*args, **) args.each { |name| column(name, :uuid, ) } end |
#xml(*args, **options) ⇒ Object
150 151 152 |
# File 'lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 150 def xml(*args, **) args.each { |name| column(name, :xml, ) } end |