Class: DbDiff::ForeignKey
- Inherits:
-
TableElement
- Object
- TableElement
- DbDiff::ForeignKey
- Defined in:
- lib/dbdiff/foreign_key.rb
Instance Attribute Summary collapse
-
#column_data ⇒ Object
readonly
Returns the value of attribute column_data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ref_column_data ⇒ Object
readonly
Returns the value of attribute ref_column_data.
-
#ref_table ⇒ Object
readonly
Returns the value of attribute ref_table.
Attributes inherited from TableElement
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_delta ⇒ Object
- #columns ⇒ Object
- #definition ⇒ Object
- #drop_delta ⇒ Object
-
#initialize(info = {}) ⇒ ForeignKey
constructor
A new instance of ForeignKey.
- #merge(fk) ⇒ Object
- #modify_delta(new_element) ⇒ Object
- #ref_columns ⇒ Object
Methods inherited from TableElement
Constructor Details
#initialize(info = {}) ⇒ ForeignKey
Returns a new instance of ForeignKey.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dbdiff/foreign_key.rb', line 7 def initialize(info = {}) super # XXX need to work on tihs @name = info['CONSTRAINT_NAME'] seq_index = info['ORDINAL_POSITION'].to_i - 1 @column_data = {} @ref_column_data = {} @column_data[seq_index] = info['COLUMN_NAME'] ref_seq_index = info['POSITION_IN_UNIQUE_CONSTRAINT'].to_i - 1 @ref_table = info['REFERENCED_TABLE_NAME'] @ref_column_data[ref_seq_index] = info['REFERENCED_COLUMN_NAME'] end |
Instance Attribute Details
#column_data ⇒ Object (readonly)
Returns the value of attribute column_data.
5 6 7 |
# File 'lib/dbdiff/foreign_key.rb', line 5 def column_data @column_data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/dbdiff/foreign_key.rb', line 5 def name @name end |
#ref_column_data ⇒ Object (readonly)
Returns the value of attribute ref_column_data.
5 6 7 |
# File 'lib/dbdiff/foreign_key.rb', line 5 def ref_column_data @ref_column_data end |
#ref_table ⇒ Object (readonly)
Returns the value of attribute ref_table.
5 6 7 |
# File 'lib/dbdiff/foreign_key.rb', line 5 def ref_table @ref_table end |
Instance Method Details
#==(other) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/dbdiff/foreign_key.rb', line 58 def ==(other) self.name == other.name && self.columns == other.columns && self.table_name == other.table_name && self.ref_table == other.ref_table && self.ref_columns == other.ref_columns end |
#add_delta ⇒ Object
54 55 56 |
# File 'lib/dbdiff/foreign_key.rb', line 54 def add_delta Delta::AddForeignKey.new(self) end |
#columns ⇒ Object
37 38 39 |
# File 'lib/dbdiff/foreign_key.rb', line 37 def columns @column_data.keys.sort.map {|k| @column_data[k]} end |
#definition ⇒ Object
41 42 43 44 |
# File 'lib/dbdiff/foreign_key.rb', line 41 def definition return "CONSTRAINT `#{self.name}` FOREIGN KEY (`" + self.columns.join("`,`") + "`) references #{self.ref_table}(`" + self.ref_columns.join("`,`") + "`)" end |
#drop_delta ⇒ Object
50 51 52 |
# File 'lib/dbdiff/foreign_key.rb', line 50 def drop_delta Delta::DropForeignKey.new(self) end |
#merge(fk) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/dbdiff/foreign_key.rb', line 23 def merge(fk) unless fk.name == self.name raise "Error - names don't match #{fk.name} #{self.name}" end @column_data.merge!(fk.column_data) @ref_column_data.merge!(fk.ref_column_data) end |
#modify_delta(new_element) ⇒ Object
46 47 48 |
# File 'lib/dbdiff/foreign_key.rb', line 46 def modify_delta(new_element) [self.drop_delta, new_element.add_delta] end |
#ref_columns ⇒ Object
33 34 35 |
# File 'lib/dbdiff/foreign_key.rb', line 33 def ref_columns @ref_column_data.keys.sort.map {|k| @ref_column_data[k]} end |