Sha256: 478e4416d9617348fbc0d5892bc0f658654fa6b1bd0ff0af9cad8f79a3c80fcb

Contents?: true

Size: 1.12 KB

Versions: 45

Compression:

Stored size: 1.12 KB

Contents

require 'pact_broker/db/data_migrations/helpers'

module PactBroker
  module DB
    module DataMigrations
      class SetLatestVersionSequenceValue
        def self.call connection
          if columns_exist?(connection)
            max_order = connection[:versions].max(:order) || 0
            sequence_row = connection[:version_sequence_number].first
            if sequence_row.nil? || sequence_row[:value] <= max_order
              new_value = max_order + 100
              connection[:version_sequence_number].insert(value: new_value)
              # Make sure there is only ever one row in case there is a race condition
              connection[:version_sequence_number].exclude(value: new_value).delete
            end
          end
        end

        def self.columns_exist?(connection)
          column_exists?(connection, :versions, :order) &&
            column_exists?(connection, :version_sequence_number, :value)
        end

        def self.column_exists?(connection, table, column)
          connection.table_exists?(table) && connection.schema(table).find{|col| col.first == column }
        end
      end
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
pact_broker-2.79.1 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.79.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.78.1 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.78.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.77.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.76.2 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.76.1 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.76.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.75.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.74.1 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.74.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.73.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.72.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.71.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.70.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.69.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.68.1 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.68.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.67.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
pact_broker-2.66.0 lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb