rapid7/metasploit_data_models

View on GitHub
lib/metasploit_data_models/change_required_columns_to_null_false.rb

Summary

Maintainability
A
0 mins
Test Coverage
# Changes all the COLUMNS in the table with TABLE_NAME that are required from the table's mode, but were previously
# `:null => true`, to `:null => false`.
#
#  @abstract Subclass and define COLUMNS as Array<Symbol> and TABLE_NAME as Symbol.
class MetasploitDataModels::ChangeRequiredColumnsToNullFalse < ActiveRecord::Migration[4.2]
  # Marks all the COLUMNS as `:null => true`
  def down
    # Use self.class:: so constants are resolved in subclasses instead of this class.
    self.class::COLUMNS.each do |column|
      change_column_null(self.class::TABLE_NAME, column, true)
    end
  end

  # Marks all the COLUMNS as `:null => false`
  def up
    # Use self.class:: so constants are resolved in subclasses instead of this class.
    self.class::COLUMNS.each do |column|
      change_column_null(self.class::TABLE_NAME, column, false)
    end
  end
end