Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
compare.php
1<?php
2namespace Bitrix\Perfmon\Sql;
3
4class Compare
5{
6 private $difference = [];
7
21 public static function diff(Schema $source, Schema $target)
22 {
23 $compare = new Compare;
24 $compare->compareSequences($source, $target);
25 $compare->compareProcedures($source, $target);
26 $compare->compareTables($source, $target);
27 return $compare->difference;
28 }
29
38 private function compareSequences(Schema $source, Schema $target)
39 {
40 foreach ($source->sequences->compare($target->sequences) as $pair)
41 {
42 $this->difference[] = $pair;
43 }
44 }
45
54 private function compareProcedures(Schema $source, Schema $target)
55 {
56 foreach ($source->procedures->compare($target->procedures) as $pair)
57 {
58 $this->difference[] = $pair;
59 }
60 }
61
70 private function compareTables(Schema $source, Schema $target)
71 {
72 foreach ($source->tables->compare($target->tables, false) as $pair)
73 {
74 if (isset($pair[0]) && isset($pair[1]))
75 {
76 $this->compareTable($pair[0], $pair[1]);
77 }
78 elseif (!isset($pair[0]) && isset($pair[1])) //Table created
79 {
80 $this->difference[] = $pair;
81
82 $emptyCollection = new Collection;
83 foreach ($emptyCollection->compare($pair[1]->triggers) as $pair2)
84 {
85 $this->difference[] = $pair2;
86 }
87 }
88 else
89 {
90 $this->difference[] = $pair;
91 }
92 }
93 }
94
103 private function compareTable(Table $source, Table $target)
104 {
105 foreach ($source->columns->compare($target->columns) as $pair)
106 {
107 if (isset($pair[0]) && isset($pair[1]))
108 {
109 $this->compareColumn($pair[0], $pair[1]);
110 }
111 else
112 {
113 $this->difference[] = $pair;
114 }
115 }
116 foreach ($source->indexes->compare($target->indexes) as $pair)
117 {
118 $this->difference[] = $pair;
119 }
120 foreach ($source->constraints->compare($target->constraints) as $pair)
121 {
122 $this->difference[] = $pair;
123 }
124 foreach ($source->triggers->compare($target->triggers) as $pair)
125 {
126 $this->difference[] = $pair;
127 }
128 }
129
138 private function compareColumn(Column $source, Column $target)
139 {
140 if (
141 $source->type !== $target->type
142 || $source->unsigned !== $target->unsigned
143 || $source->length !== $target->length
144 || $source->nullable !== $target->nullable
145 || $source->default !== $target->default
146 )
147 {
148 $this->difference[] = [$source, $target];
149 }
150 }
151}
static diff(Schema $source, Schema $target)
Definition compare.php:21