Skip to content

Commit

Permalink
chore: truncate tables in a database specific way
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 5, 2020
1 parent b7b9299 commit 4a89e90
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/pact_broker/integrations/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'pact_broker/logging'
require 'pact_broker/integrations/integration'
require 'pact_broker/db/models'
require 'pact_broker/repositories/helpers'

module PactBroker
module Integrations
Expand Down Expand Up @@ -46,8 +47,16 @@ def self.delete(consumer_name, provider_name)
def self.delete_all
# TODO move all these into their own repositories
PactBroker::DB.each_integration_model do | model |
logger.info("Truncating ", model.table_name)
model.truncate(cascade: true)
if PactBroker::Repositories::Helpers.postgres?
logger.info("Truncating ", model.table_name)
model.truncate(cascade: true)
else
logger.info("Deleting all from ", model.table_name)
# Mysql adapter needs to support cascade truncate
# https://travis-ci.org/pact-foundation/pact_broker/jobs/633050220#L841
# https://travis-ci.org/pact-foundation/pact_broker/jobs/633053228#L849
model.dataset.delete
end
end
end
end
Expand Down

0 comments on commit 4a89e90

Please sign in to comment.