Class: ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition

Inherits:
TableDefinition show all
Includes:
ColumnMethods
Defined in:
activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb

Overview

Active Record PostgreSQL Adapter Table Definition

Instance Attribute Summary collapse

Attributes inherited from TableDefinition

#as, #check_constraints, #comment, #foreign_keys, #if_not_exists, #indexes, #name, #options, #temporary

Instance Method Summary collapse

Methods included from ColumnMethods

#bigserial, #primary_key

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Methods inherited from TableDefinition

#[], #check_constraint, #column, #columns, #foreign_key, #index, #new_check_constraint_definition, #new_foreign_key_definition, #primary_keys, #references, #remove_column, #set_primary_key, #timestamps

Methods included from ColumnMethods

#bigint, #primary_key

Constructor Details

#initializeTableDefinition

Returns a new instance of TableDefinition.



249
250
251
252
253
254
# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 249

def initialize(*, **)
  super
  @exclusion_constraints = []
  @unique_constraints = []
  @unlogged = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables
end

Instance Attribute Details

#exclusion_constraintsObject (readonly)

Returns the value of attribute exclusion_constraints.



247
248
249
# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 247

def exclusion_constraints
  @exclusion_constraints
end

#unique_constraintsObject (readonly)

Returns the value of attribute unique_constraints.



247
248
249
# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 247

def unique_constraints
  @unique_constraints
end

#unloggedObject (readonly)

Returns the value of attribute unlogged.



247
248
249
# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 247

def unlogged
  @unlogged
end

Instance Method Details

#exclusion_constraint(expression, **options) ⇒ Object



256
257
258
# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 256

def exclusion_constraint(expression, **options)
  exclusion_constraints << new_exclusion_constraint_definition(expression, options)
end

#new_column_definition(name, type, **options) ⇒ Object

:nodoc:



274
275
276
277
278
279
280
281
# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 274

def new_column_definition(name, type, **options) # :nodoc:
  case type
  when :virtual
    type = options[:type]
  end

  super
end

#new_exclusion_constraint_definition(expression, options) ⇒ Object

:nodoc:



264
265
266
267
# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 264

def new_exclusion_constraint_definition(expression, options) # :nodoc:
  options = @conn.exclusion_constraint_options(name, expression, options)
  ExclusionConstraintDefinition.new(name, expression, options)
end

#new_unique_constraint_definition(column_name, options) ⇒ Object

:nodoc:



269
270
271
272
# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 269

def new_unique_constraint_definition(column_name, options) # :nodoc:
  options = @conn.unique_constraint_options(name, column_name, options)
  UniqueConstraintDefinition.new(name, column_name, options)
end

#unique_constraint(column_name, **options) ⇒ Object



260
261
262
# File 'activerecord/lib/active_record/connection_adapters/postgresql/schema_definitions.rb', line 260

def unique_constraint(column_name, **options)
  unique_constraints << new_unique_constraint_definition(column_name, options)
end