|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Doctrine\DBAL\Schema; |
|
21
|
|
|
|
|
22
|
|
|
use function implode; |
|
23
|
|
|
use function sprintf; |
|
24
|
|
|
|
|
25
|
|
|
class SchemaException extends \Doctrine\DBAL\DBALException |
|
26
|
|
|
{ |
|
27
|
|
|
const TABLE_DOESNT_EXIST = 10; |
|
28
|
|
|
const TABLE_ALREADY_EXISTS = 20; |
|
29
|
|
|
const COLUMN_DOESNT_EXIST = 30; |
|
30
|
|
|
const COLUMN_ALREADY_EXISTS = 40; |
|
31
|
|
|
const INDEX_DOESNT_EXIST = 50; |
|
32
|
|
|
const INDEX_ALREADY_EXISTS = 60; |
|
33
|
|
|
const SEQUENCE_DOENST_EXIST = 70; |
|
34
|
|
|
const SEQUENCE_ALREADY_EXISTS = 80; |
|
35
|
|
|
const INDEX_INVALID_NAME = 90; |
|
36
|
|
|
const FOREIGNKEY_DOESNT_EXIST = 100; |
|
37
|
|
|
const NAMESPACE_ALREADY_EXISTS = 110; |
|
38
|
|
|
const VIEW_DOENST_EXIST = 120; |
|
39
|
|
|
const VIEW_ALREADY_EXISTS = 130; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $tableName |
|
43
|
|
|
* |
|
44
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
45
|
|
|
*/ |
|
46
|
20 |
|
public static function tableDoesNotExist($tableName) |
|
47
|
|
|
{ |
|
48
|
20 |
|
return new self("There is no table with name '".$tableName."' in the schema.", self::TABLE_DOESNT_EXIST); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param string $indexName |
|
53
|
|
|
* |
|
54
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
55
|
|
|
*/ |
|
56
|
20 |
|
public static function indexNameInvalid($indexName) |
|
57
|
|
|
{ |
|
58
|
20 |
|
return new self("Invalid index-name $indexName given, has to be [a-zA-Z0-9_]", self::INDEX_INVALID_NAME); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param string $indexName |
|
63
|
|
|
* @param string $table |
|
64
|
|
|
* |
|
65
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
66
|
|
|
*/ |
|
67
|
40 |
|
public static function indexDoesNotExist($indexName, $table) |
|
68
|
|
|
{ |
|
69
|
40 |
|
return new self("Index '$indexName' does not exist on table '$table'.", self::INDEX_DOESNT_EXIST); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param string $indexName |
|
74
|
|
|
* @param string $table |
|
75
|
|
|
* |
|
76
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
77
|
|
|
*/ |
|
78
|
60 |
|
public static function indexAlreadyExists($indexName, $table) |
|
79
|
|
|
{ |
|
80
|
60 |
|
return new self("An index with name '$indexName' was already defined on table '$table'.", self::INDEX_ALREADY_EXISTS); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param string $columnName |
|
85
|
|
|
* @param string $table |
|
86
|
|
|
* |
|
87
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
88
|
|
|
*/ |
|
89
|
80 |
|
public static function columnDoesNotExist($columnName, $table) |
|
90
|
|
|
{ |
|
91
|
80 |
|
return new self("There is no column with name '$columnName' on table '$table'.", self::COLUMN_DOESNT_EXIST); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @param string $namespaceName |
|
96
|
|
|
* |
|
97
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
98
|
|
|
*/ |
|
99
|
20 |
|
public static function namespaceAlreadyExists($namespaceName) |
|
100
|
|
|
{ |
|
101
|
20 |
|
return new self( |
|
102
|
20 |
|
sprintf("The namespace with name '%s' already exists.", $namespaceName), |
|
103
|
20 |
|
self::NAMESPACE_ALREADY_EXISTS |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param string $tableName |
|
109
|
|
|
* |
|
110
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
111
|
|
|
*/ |
|
112
|
20 |
|
public static function tableAlreadyExists($tableName) |
|
113
|
|
|
{ |
|
114
|
20 |
|
return new self("The table with name '".$tableName."' already exists.", self::TABLE_ALREADY_EXISTS); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param string $tableName |
|
119
|
|
|
* @param string $columnName |
|
120
|
|
|
* |
|
121
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
122
|
|
|
*/ |
|
123
|
20 |
|
public static function columnAlreadyExists($tableName, $columnName) |
|
124
|
|
|
{ |
|
125
|
20 |
|
return new self( |
|
126
|
20 |
|
"The column '".$columnName."' on table '".$tableName."' already exists.", self::COLUMN_ALREADY_EXISTS |
|
127
|
|
|
); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param string $sequenceName |
|
132
|
|
|
* |
|
133
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
134
|
|
|
*/ |
|
135
|
20 |
|
public static function sequenceAlreadyExists($sequenceName) |
|
136
|
|
|
{ |
|
137
|
20 |
|
return new self("The sequence '".$sequenceName."' already exists.", self::SEQUENCE_ALREADY_EXISTS); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param string $sequenceName |
|
142
|
|
|
* |
|
143
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
144
|
|
|
*/ |
|
145
|
20 |
|
public static function sequenceDoesNotExist($sequenceName) |
|
146
|
|
|
{ |
|
147
|
20 |
|
return new self("There exists no sequence with the name '".$sequenceName."'.", self::SEQUENCE_DOENST_EXIST); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @param string $fkName |
|
152
|
|
|
* @param string $table |
|
153
|
|
|
* |
|
154
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
155
|
|
|
*/ |
|
156
|
|
|
public static function foreignKeyDoesNotExist($fkName, $table) |
|
157
|
|
|
{ |
|
158
|
|
|
return new self("There exists no foreign key with the name '$fkName' on table '$table'.", self::FOREIGNKEY_DOESNT_EXIST); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
/** |
|
162
|
|
|
* @param \Doctrine\DBAL\Schema\Table $localTable |
|
163
|
|
|
* @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey |
|
164
|
|
|
* |
|
165
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
166
|
|
|
*/ |
|
167
|
|
|
public static function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey) |
|
168
|
|
|
{ |
|
169
|
|
|
return new self( |
|
170
|
|
|
"The performed schema operation on ".$localTable->getName()." requires a named foreign key, ". |
|
171
|
|
|
"but the given foreign key from (".implode(", ", $foreignKey->getColumns()).") onto foreign table ". |
|
172
|
|
|
"'".$foreignKey->getForeignTableName()."' (".implode(", ", $foreignKey->getForeignColumns()).") is currently ". |
|
173
|
|
|
"unnamed." |
|
174
|
|
|
); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @param string $changeName |
|
179
|
|
|
* |
|
180
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
181
|
|
|
*/ |
|
182
|
|
|
public static function alterTableChangeNotSupported($changeName) |
|
183
|
|
|
{ |
|
184
|
|
|
return new self("Alter table change not supported, given '$changeName'"); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @param string $viewName |
|
189
|
|
|
* |
|
190
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
191
|
|
|
*/ |
|
192
|
20 |
|
static public function viewAlreadyExists($viewName) |
|
|
|
|
|
|
193
|
|
|
{ |
|
194
|
20 |
|
return new self("The view '".$viewName."' already exists.", self::VIEW_ALREADY_EXISTS); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* @param string $viewName |
|
199
|
|
|
* |
|
200
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
|
201
|
|
|
*/ |
|
202
|
20 |
|
static public function viewDoesNotExist($viewName) |
|
|
|
|
|
|
203
|
|
|
{ |
|
204
|
20 |
|
return new self("There exists no view with the name '".$viewName."'.", self::VIEW_DOENST_EXIST); |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|