Module: PgParty::Model::SharedMethods

Defined in:
lib/pg_party/model/shared_methods.rb

Instance Method Summary collapse

Instance Method Details

#in_partition(*args) ⇒ Object



30
31
32
# File 'lib/pg_party/model/shared_methods.rb', line 30

def in_partition(*args)
  PgParty::ModelDecorator.new(self).in_partition(*args)
end

#partition_key_eq(*args) ⇒ Object



34
35
36
# File 'lib/pg_party/model/shared_methods.rb', line 34

def partition_key_eq(*args)
  PgParty::ModelDecorator.new(self).partition_key_eq(*args)
end

#partitions(*args) ⇒ Object



26
27
28
# File 'lib/pg_party/model/shared_methods.rb', line 26

def partitions(*args)
  PgParty::ModelDecorator.new(self).partitions(*args)
end

#reset_primary_keyObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/pg_party/model/shared_methods.rb', line 8

def reset_primary_key
  return base_class.primary_key if self != base_class

  partitions = partitions(include_subpartitions: true)
  return get_primary_key(base_class.name) if partitions.empty?

  first_partition = partitions.detect { |p| !connection.table_partitioned?(p) }
  raise 'No leaf partitions exist for this model. Create a partition to contain your data' unless first_partition

  in_partition(first_partition).get_primary_key(base_class.name)
end

#table_exists?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/pg_party/model/shared_methods.rb', line 20

def table_exists?
  target_table = partitions.first || table_name

  connection.schema_cache.data_source_exists?(target_table)
end