Class: Dbsketch::Comparison::TableComparator

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

Instance Method Summary collapse

Constructor Details

#initialize(column_comparator: nil, options: {}) ⇒ TableComparator

Returns a new instance of TableComparator.

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dbsketch/comparison/table_comparator.rb', line 38

def initialize column_comparator: nil, options: {}
	### Preconditions
	raise ArgumentError, "column_comparator is not a Dbsketch::Comparison::ColumnComparator" unless nil == column_comparator or column_comparator.is_a? Dbsketch::Comparison::ColumnComparator
	###
	@check_constraint_comparator = CheckConstraintComparator.new
	@column_comparator = (nil == column_comparator ? ColumnComparator.new(:options => options) : column_comparator)
	@computed_column_comparator = ComputedColumnComparator.new
	@foreign_key_comparator = ForeignKeyComparator.new
	@primary_key_comparator = PrimaryKeyComparator.new
	@unique_constraint_comparator = UniqueConstraintComparator.new
end

Instance Method Details

#are_equivalent?(old_table, new_table) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


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

def are_equivalent? old_table, new_table
	### Preconditions
	raise ArgumentError, "old_table is not a Dbsketch::Model::Table" unless nil == old_table or old_table.is_a? Dbsketch::Model::Table
	raise ArgumentError, "new_table is not a Dbsketch::Model::Table" unless nil == new_table or new_table.is_a? Dbsketch::Model::Table
	###
	(nil != old_table and nil != new_table) and
		columns(old_table, new_table).empty? and
		@primary_key_comparator.are_equivalent?(old_table.primary_key, new_table.primary_key) and
		check_constraints(old_table, new_table).empty? and
		foreign_keys(old_table, new_table).empty? and
		unique_constraints(old_table, new_table).empty?
end

#compare(old_table, new_table) ⇒ Object

Returns a TableDiff if tables are different, nil otherwise

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/dbsketch/comparison/table_comparator.rb', line 64

def compare old_table, new_table
	### Preconditions
	raise ArgumentError, "old_table is not a Dbsketch::Model::Table" unless nil == old_table or old_table.is_a? Dbsketch::Model::Table
	raise ArgumentError, "new_table is not a Dbsketch::Model::Table" unless nil == new_table or new_table.is_a? Dbsketch::Model::Table
	###
	if not are_equivalent? old_table, new_table
		primary_key_diff = @primary_key_comparator.compare(old_table.primary_key, new_table.primary_key) if nil != old_table and nil != new_table
		TableDiff.new(
			old_table, new_table,
			columns(old_table, new_table),
			primary_key_diff,
			check_constraints(old_table, new_table),
			foreign_keys(old_table, new_table),
			unique_constraints(old_table, new_table)
		)
	end
end