Class: PactBroker::DB::DataMigrations::SetLatestVersionSequenceValue
- Inherits:
-
Object
- Object
- PactBroker::DB::DataMigrations::SetLatestVersionSequenceValue
- Defined in:
- lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb
Class Method Summary collapse
- .call(connection) ⇒ Object
- .column_exists?(connection, table, column) ⇒ Boolean
- .columns_exist?(connection) ⇒ Boolean
Class Method Details
.call(connection) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb', line 7 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 |
.column_exists?(connection, table, column) ⇒ Boolean
25 26 27 |
# File 'lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb', line 25 def self.column_exists?(connection, table, column) connection.table_exists?(table) && connection.schema(table).find{|col| col.first == column } end |
.columns_exist?(connection) ⇒ Boolean
20 21 22 23 |
# File 'lib/pact_broker/db/data_migrations/set_latest_version_sequence_value.rb', line 20 def self.columns_exist?(connection) column_exists?(connection, :versions, :order) && column_exists?(connection, :version_sequence_number, :value) end |