Module: Torque::PostgreSQL::Adapter::InheritanceStatements

Included in:
Torque::PostgreSQL::Adapter
Defined in:
lib/torque/postgresql/adapter/inheritance_statements.rb,
sig/torque/postgresql/adapter/inheritance_statements.rbs

Constant Summary collapse

SYNC_MARKER =

Copies created by a sync are named after this, which is how they are told apart from anything written by hand

Returns:

  • (String)
'sync_inh_'
SYNC_FEATURES =

Returns:

  • (Array[Symbol])
%i[
  primary_key indexes unique_constraints exclusion_constraints foreign_keys
].freeze

Instance Method Summary collapse

Instance Method Details

#sync_inheritance_features(table_name, children = nil, prune: false, **features) ⇒ tree

PostgreSQL only propagates columns, their defaults and their check constraints to inherited tables. This copies over everything else that Rails has a DSL for, from table_name down to its children

Features default to true, so passing one as false excludes it. Passing any of them as true instead selects only those

Example:

sync_inheritance_features :activities
sync_inheritance_features :activities, %i[activity_books]
sync_inheritance_features :activities, primary_key: false
sync_inheritance_features :activities, prune: true

Parameters:

  • table_name (table_ref)
  • children (table_ref, Array[table_ref], nil) (defaults to: nil)
  • prune: (Boolean) (defaults to: false)
  • features (Boolean)

Returns:

  • (tree)


28
29
30
31
32
33
34
# File 'lib/torque/postgresql/adapter/inheritance_statements.rb', line 28

def sync_inheritance_features(table_name, children = nil, prune: false, **features)
  features = sync_inheritance_selection(features)

  sync_inheritance_tree(table_name, children).each do |child, parents|
    sync_inheritance_into(child, parents, features, prune)
  end
end