class PgDice::PartitionDropper
Simple class used to provide a mechanism that users can hook into if they want to override this default behavior for dropping a table.
Attributes
logger[R]
query_executor[R]
Public Class Methods
new(logger:, query_executor:)
click to toggle source
# File lib/pgdice/partition_dropper.rb, line 10 def initialize(logger:, query_executor:) @logger = logger @query_executor = query_executor end
Public Instance Methods
call(old_partitions)
click to toggle source
# File lib/pgdice/partition_dropper.rb, line 15 def call(old_partitions) logger.info { "Partitions to be deleted are: #{old_partitions}" } query_executor.call(generate_drop_sql(old_partitions)) old_partitions end
Private Instance Methods
generate_drop_sql(old_partitions)
click to toggle source
# File lib/pgdice/partition_dropper.rb, line 25 def generate_drop_sql(old_partitions) return if old_partitions.size.zero? sql_query = old_partitions.reduce("BEGIN;\n") do |sql, table_name| sql + "DROP TABLE IF EXISTS #{table_name} CASCADE;\n" end sql_query + 'COMMIT;' end