Class: DbDiff::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/dbdiff/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info = {}) ⇒ Table

Returns a new instance of Table.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dbdiff/table.rb', line 6

def initialize(info = {})

  @rows = []
  @foreign_keys = []
  @keys = []
  @columns = []
  @triggers = []

  @engine = info['ENGINE']
  @collation = info['TABLE_COLLATION']
  @name = info['TABLE_NAME']
end

Instance Attribute Details

#charsetObject

Returns the value of attribute charset.



4
5
6
# File 'lib/dbdiff/table.rb', line 4

def charset
  @charset
end

#collationObject

Returns the value of attribute collation.



4
5
6
# File 'lib/dbdiff/table.rb', line 4

def collation
  @collation
end

#columnsObject

Returns the value of attribute columns.



4
5
6
# File 'lib/dbdiff/table.rb', line 4

def columns
  @columns
end

#engineObject

Returns the value of attribute engine.



4
5
6
# File 'lib/dbdiff/table.rb', line 4

def engine
  @engine
end

#foreign_keysObject

Returns the value of attribute foreign_keys.



4
5
6
# File 'lib/dbdiff/table.rb', line 4

def foreign_keys
  @foreign_keys
end

#keysObject

Returns the value of attribute keys.



4
5
6
# File 'lib/dbdiff/table.rb', line 4

def keys
  @keys
end

#nameObject (readonly) Also known as: table_name

Returns the value of attribute name.



3
4
5
# File 'lib/dbdiff/table.rb', line 3

def name
  @name
end

#rowsObject

Returns the value of attribute rows.



4
5
6
# File 'lib/dbdiff/table.rb', line 4

def rows
  @rows
end

#triggersObject

Returns the value of attribute triggers.



4
5
6
# File 'lib/dbdiff/table.rb', line 4

def triggers
  @triggers
end

Instance Method Details

#==(other) ⇒ Object



26
27
28
29
30
# File 'lib/dbdiff/table.rb', line 26

def ==(other)
  self.engine    == other.engine &&
  self.collation == other.collation &&
  self.name      == other.name
end

#add_deltaObject



37
38
39
# File 'lib/dbdiff/table.rb', line 37

def add_delta
  Delta::AddTable.new(self)
end

#deep_cloneObject



32
33
34
35
# File 'lib/dbdiff/table.rb', line 32

def deep_clone
  t = Marshal::load(Marshal.dump(self))
  # must clear rows out since they won't necessary be in the copy
end

#drop_deltaObject



45
46
47
# File 'lib/dbdiff/table.rb', line 45

def drop_delta
  Delta::DropTable.new(self)
end

#modify_delta(new_element) ⇒ Object



41
42
43
# File 'lib/dbdiff/table.rb', line 41

def modify_delta(new_element)
  Delta::ModifyTable.new(new_element)
end

#primary_keyObject



21
22
23
24
# File 'lib/dbdiff/table.rb', line 21

def primary_key
  pk = keys.find{|k| k.primary}
  return (pk  ? pk.columns : nil)
end