module PgParty::Model::SharedMethods

Public Instance Methods

in_partition(*args) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/pg_party/model/shared_methods.rb, line 26
def partitions(**args)
  PgParty::ModelDecorator.new(self).partitions(**args)
end
reset_primary_key() click to toggle source
# 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: PgParty.config.include_subpartitions_in_partition_list)
  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?() click to toggle source
# 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