Class: PactBroker::DB::DeleteOverwrittenData
- Inherits:
-
Object
- Object
- PactBroker::DB::DeleteOverwrittenData
- Defined in:
- lib/pact_broker/db/delete_overwritten_data.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(database_connection, options = {}) ⇒ DeleteOverwrittenData
constructor
A new instance of DeleteOverwrittenData.
Constructor Details
#initialize(database_connection, options = {}) ⇒ DeleteOverwrittenData
Returns a new instance of DeleteOverwrittenData.
11 12 13 14 15 16 |
# File 'lib/pact_broker/db/delete_overwritten_data.rb', line 11 def initialize database_connection, = {} @db = database_connection @options = @cut_off_date = [:max_age] ? (DateTime.now - [:max_age]) : DateTime.now @limit = [:limit] || 1000 end |
Class Method Details
.call(database_connection, options = {}) ⇒ Object
7 8 9 |
# File 'lib/pact_broker/db/delete_overwritten_data.rb', line 7 def self.call database_connection, = {} new(database_connection, ).call end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pact_broker/db/delete_overwritten_data.rb', line 18 def call require "pact_broker/pacts/pact_publication" require "pact_broker/domain/verification" deleted_counts = {} kept_counts = {} deleted_counts.merge!(delete_overwritten_pact_publications) deleted_counts.merge!(delete_overwritten_verifications) deleted_counts.merge!(delete_orphan_pact_versions) deleted_counts.merge!(delete_webhook_data) kept_counts[:pact_publications] = db[:pact_publications].count kept_counts[:verification_results] = db[:verifications].count kept_counts[:pact_versions] = db[:pact_versions].count kept_counts[:triggered_webhooks] = db[:triggered_webhooks].count if dry_run? to_keep = deleted_counts.keys.each_with_object({}) do | table_name, new_counts | new_counts[table_name] = kept_counts[table_name] - deleted_counts[table_name] end { toDelete: deleted_counts, toKeep: to_keep } else { deleted: deleted_counts, kept: kept_counts } end end |