Class: Dbsketch::Comparison::DatabaseComparator

Inherits:
Object
  • Object
show all
Defined in:
lib/dbsketch/comparison/database_comparator.rb

Instance Method Summary collapse

Constructor Details

#initialize(options: {}) ⇒ DatabaseComparator

Returns a new instance of DatabaseComparator.



32
33
34
35
36
37
38
39
# File 'lib/dbsketch/comparison/database_comparator.rb', line 32

def initialize options: {}
	@index_comparator = IndexComparator.new
	@function_comparator = FunctionComparator.new
	@procedure_comparator = ProcedureComparator.new
	@table_comparator = TableComparator.new :options => options
	@trigger_comparator = TriggerComparator.new
	@view_comparator = ViewComparator.new
end

Instance Method Details

#are_equivalent?(old_database, new_database) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
# File 'lib/dbsketch/comparison/database_comparator.rb', line 41

def are_equivalent? old_database, new_database
	### Preconditions
	raise ArgumentError, "old_database is not a Dbsketch::Model::Database" unless old_database.is_a? Dbsketch::Model::Database
	raise ArgumentError, "new_database is not a Dbsketch::Model::Database" unless new_database.is_a? Dbsketch::Model::Database
	###
	indexes(old_database, new_database).empty? and operations(old_database, new_database).empty? and tables(old_database, new_database).empty? and triggers(old_database, new_database).empty? and views(old_database, new_database).empty?
end

#compare(old_database, new_database) ⇒ Object

Returns a DatabaseDiff if tables are different, nil otherwise

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
# File 'lib/dbsketch/comparison/database_comparator.rb', line 50

def compare old_database, new_database
	### Preconditions
	raise ArgumentError, "old_database is not a Dbsketch::Model::Database" unless old_database.is_a? Dbsketch::Model::Database
	raise ArgumentError, "new_database is not a Dbsketch::Model::Database" unless new_database.is_a? Dbsketch::Model::Database
	###
	DatabaseDiff.new(
		old_database, new_database, indexes(old_database, new_database), operations(old_database, new_database), tables(old_database, new_database), triggers(old_database, new_database), views(old_database, new_database)
	) if not are_equivalent? old_database, new_database
end