diff --git a/lib/db.rb b/lib/db.rb index fc0ffd1b5..7e13409ae 100644 --- a/lib/db.rb +++ b/lib/db.rb @@ -25,11 +25,17 @@ module DB # pool, as noted in the documentation for the extension. # def self.connect db_credentials + # Keep this conifiguration in sync with lib/pact_broker/app.rb#configure_database_connection Sequel.datetime_class = DateTime # logger = Logger.new($stdout) con = Sequel.connect(db_credentials.merge(:logger => logger, :pool_class => Sequel::ThreadedConnectionPool, :encoding => 'utf8')) con.extension(:connection_validator) con.extension(:pagination) + con.extend_datasets do + def any? + !empty? + end + end con.pool.connection_validation_timeout = -1 #Check the connection on every request con.timezone = :utc con.run("SET sql_mode='STRICT_TRANS_TABLES';") if db_credentials[:adapter].to_s =~ /mysql/ diff --git a/lib/pact_broker/app.rb b/lib/pact_broker/app.rb index fc2de3e8c..2c7576ea8 100644 --- a/lib/pact_broker/app.rb +++ b/lib/pact_broker/app.rb @@ -106,11 +106,18 @@ def load_configuration_from_database end def configure_database_connection + # Keep this configuration in sync with lib/db.rb PactBroker::DB.connection = configuration.database_connection PactBroker::DB.connection.timezone = :utc PactBroker::DB.validate_connection_config if configuration.validate_database_connection_config PactBroker::DB.set_mysql_strict_mode_if_mysql PactBroker::DB.connection.extension(:pagination) + PactBroker::DB.extend_datasets do + def any? + !empty? + end + end + Sequel.datetime_class = DateTime Sequel.database_timezone = :utc # Store all dates in UTC, assume any date without a TZ is UTC Sequel.application_timezone = :local # Convert dates to localtime when retrieving from database diff --git a/lib/pact_broker/pacts/pact_version.rb b/lib/pact_broker/pacts/pact_version.rb index c2e1a8a09..93153def9 100644 --- a/lib/pact_broker/pacts/pact_version.rb +++ b/lib/pact_broker/pacts/pact_version.rb @@ -52,21 +52,31 @@ def latest_consumer_version_number def select_provider_tags_with_successful_verifications(tags) tags.select do | tag | + verifications_join = { + Sequel[:verifications][:pact_version_id] => Sequel[:pact_versions][:id], + Sequel[:verifications][:success] => true + } + tags_join = { + Sequel[:tags][:version_id] => Sequel[:versions][:id], + Sequel[:tags][:name] => tag + } PactVersion.where(Sequel[:pact_versions][:id] => id) - .join(:verifications, Sequel[:verifications][:pact_version_id] => Sequel[:pact_versions][:id]) + .join(:verifications, verifications_join) .join(:versions, Sequel[:versions][:id] => Sequel[:verifications][:provider_version_id]) - .join(:tags, Sequel[:tags][:version_id] => Sequel[:versions][:id]) - .where(Sequel[:tags][:name] => tag) - .where(Sequel[:verifications][:success] => true) + .join(:tags, tags_join) .any? end end def verified_successfully_by_any_provider_version? + verifications_join = { + Sequel[:verifications][:pact_version_id] => Sequel[:pact_versions][:id], + Sequel[:verifications][:pact_version_id] => id, + Sequel[:verifications][:success] => true + } PactVersion.where(Sequel[:pact_versions][:id] => id) - .join(:verifications, Sequel[:verifications][:pact_version_id] => Sequel[:pact_versions][:id]) + .join(:verifications, verifications_join) .join(:versions, Sequel[:versions][:id] => Sequel[:verifications][:provider_version_id]) - .where(Sequel[:verifications][:success] => true) .any? end