forked from doctrine/dbal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TableDiff.php
156 lines (137 loc) · 4.46 KB
/
TableDiff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Schema;
use function array_filter;
/**
* Table Diff.
*/
class TableDiff
{
/**
* Constructs a TableDiff object.
*
* @internal The diff can be only instantiated by a {@see Comparator}.
*
* @param array<ForeignKeyConstraint> $droppedForeignKeys
* @param array<Column> $addedColumns
* @param array<ColumnDiff> $modifiedColumns
* @param array<Column> $droppedColumns
* @param array<string, Column> $renamedColumns
* @param array<Index> $addedIndexes
* @param array<Index> $modifiedIndexes
* @param array<Index> $droppedIndexes
* @param array<string, Index> $renamedIndexes
* @param array<ForeignKeyConstraint> $addedForeignKeys
* @param array<ForeignKeyConstraint> $modifiedForeignKeys
*/
public function __construct(
private readonly Table $oldTable,
private readonly array $addedColumns,
private readonly array $modifiedColumns,
private readonly array $droppedColumns,
private readonly array $renamedColumns,
private array $addedIndexes,
private readonly array $modifiedIndexes,
private array $droppedIndexes,
private readonly array $renamedIndexes,
private readonly array $addedForeignKeys,
private readonly array $modifiedForeignKeys,
private array $droppedForeignKeys,
) {
}
public function getOldTable(): Table
{
return $this->oldTable;
}
/** @return array<Column> */
public function getAddedColumns(): array
{
return $this->addedColumns;
}
/** @return array<ColumnDiff> */
public function getModifiedColumns(): array
{
return $this->modifiedColumns;
}
/** @return array<Column> */
public function getDroppedColumns(): array
{
return $this->droppedColumns;
}
/** @return array<string,Column> */
public function getRenamedColumns(): array
{
return $this->renamedColumns;
}
/** @return array<Index> */
public function getAddedIndexes(): array
{
return $this->addedIndexes;
}
/**
* @internal This method exists only for compatibility with the current implementation of schema managers
* that modify the diff while processing it.
*/
public function unsetAddedIndex(Index $index): void
{
$this->addedIndexes = array_filter(
$this->addedIndexes,
static function (Index $addedIndex) use ($index): bool {
return $addedIndex !== $index;
},
);
}
/** @return array<Index> */
public function getModifiedIndexes(): array
{
return $this->modifiedIndexes;
}
/** @return array<Index> */
public function getDroppedIndexes(): array
{
return $this->droppedIndexes;
}
/**
* @internal This method exists only for compatibility with the current implementation of schema managers
* that modify the diff while processing it.
*/
public function unsetDroppedIndex(Index $index): void
{
$this->droppedIndexes = array_filter(
$this->droppedIndexes,
static function (Index $droppedIndex) use ($index): bool {
return $droppedIndex !== $index;
},
);
}
/** @return array<string,Index> */
public function getRenamedIndexes(): array
{
return $this->renamedIndexes;
}
/** @return array<ForeignKeyConstraint> */
public function getAddedForeignKeys(): array
{
return $this->addedForeignKeys;
}
/** @return array<ForeignKeyConstraint> */
public function getModifiedForeignKeys(): array
{
return $this->modifiedForeignKeys;
}
/** @return array<ForeignKeyConstraint> */
public function getDroppedForeignKeys(): array
{
return $this->droppedForeignKeys;
}
/** @internal This method exists only for compatibility with the current implementation of the schema comparator. */
public function unsetDroppedForeignKey(ForeignKeyConstraint $foreignKey): void
{
$this->droppedForeignKeys = array_filter(
$this->droppedForeignKeys,
static function (ForeignKeyConstraint $droppedForeignKey) use ($foreignKey): bool {
return $droppedForeignKey !== $foreignKey;
},
);
}
}