1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\DBAL\Schema; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\DBALException; |
6
|
|
|
use function implode; |
7
|
|
|
use function sprintf; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @psalm-immutable |
11
|
|
|
*/ |
12
|
|
|
class SchemaException extends DBALException |
13
|
|
|
{ |
14
|
|
|
public const TABLE_DOESNT_EXIST = 10; |
15
|
|
|
public const TABLE_ALREADY_EXISTS = 20; |
16
|
|
|
public const COLUMN_DOESNT_EXIST = 30; |
17
|
|
|
public const COLUMN_ALREADY_EXISTS = 40; |
18
|
|
|
public const INDEX_DOESNT_EXIST = 50; |
19
|
|
|
public const INDEX_ALREADY_EXISTS = 60; |
20
|
|
|
public const SEQUENCE_DOENST_EXIST = 70; |
21
|
|
|
public const SEQUENCE_ALREADY_EXISTS = 80; |
22
|
|
|
public const INDEX_INVALID_NAME = 90; |
23
|
|
|
public const FOREIGNKEY_DOESNT_EXIST = 100; |
24
|
|
|
public const CONSTRAINT_DOESNT_EXIST = 110; |
25
|
|
|
public const NAMESPACE_ALREADY_EXISTS = 120; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param string $tableName |
29
|
|
|
* |
30
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
31
|
|
|
*/ |
32
|
23 |
|
public static function tableDoesNotExist($tableName) |
33
|
|
|
{ |
34
|
23 |
|
return new self("There is no table with name '" . $tableName . "' in the schema.", self::TABLE_DOESNT_EXIST); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $indexName |
39
|
|
|
* |
40
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
41
|
|
|
*/ |
42
|
23 |
|
public static function indexNameInvalid($indexName) |
43
|
|
|
{ |
44
|
23 |
|
return new self( |
45
|
23 |
|
sprintf('Invalid index-name %s given, has to be [a-zA-Z0-9_]', $indexName), |
46
|
23 |
|
self::INDEX_INVALID_NAME |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $indexName |
52
|
|
|
* @param string $table |
53
|
|
|
* |
54
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
55
|
|
|
*/ |
56
|
46 |
|
public static function indexDoesNotExist($indexName, $table) |
57
|
|
|
{ |
58
|
46 |
|
return new self( |
59
|
46 |
|
sprintf("Index '%s' does not exist on table '%s'.", $indexName, $table), |
60
|
46 |
|
self::INDEX_DOESNT_EXIST |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param string $indexName |
66
|
|
|
* @param string $table |
67
|
|
|
* |
68
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
69
|
|
|
*/ |
70
|
69 |
|
public static function indexAlreadyExists($indexName, $table) |
71
|
|
|
{ |
72
|
69 |
|
return new self( |
73
|
69 |
|
sprintf("An index with name '%s' was already defined on table '%s'.", $indexName, $table), |
74
|
69 |
|
self::INDEX_ALREADY_EXISTS |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $columnName |
80
|
|
|
* @param string $table |
81
|
|
|
* |
82
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
83
|
|
|
*/ |
84
|
92 |
|
public static function columnDoesNotExist($columnName, $table) |
85
|
|
|
{ |
86
|
92 |
|
return new self( |
87
|
92 |
|
sprintf("There is no column with name '%s' on table '%s'.", $columnName, $table), |
88
|
92 |
|
self::COLUMN_DOESNT_EXIST |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $namespaceName |
94
|
|
|
* |
95
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
96
|
|
|
*/ |
97
|
23 |
|
public static function namespaceAlreadyExists($namespaceName) |
98
|
|
|
{ |
99
|
23 |
|
return new self( |
100
|
23 |
|
sprintf("The namespace with name '%s' already exists.", $namespaceName), |
101
|
23 |
|
self::NAMESPACE_ALREADY_EXISTS |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param string $tableName |
107
|
|
|
* |
108
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
109
|
|
|
*/ |
110
|
23 |
|
public static function tableAlreadyExists($tableName) |
111
|
|
|
{ |
112
|
23 |
|
return new self("The table with name '" . $tableName . "' already exists.", self::TABLE_ALREADY_EXISTS); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string $tableName |
117
|
|
|
* @param string $columnName |
118
|
|
|
* |
119
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
120
|
|
|
*/ |
121
|
23 |
|
public static function columnAlreadyExists($tableName, $columnName) |
122
|
|
|
{ |
123
|
23 |
|
return new self( |
124
|
23 |
|
"The column '" . $columnName . "' on table '" . $tableName . "' already exists.", |
125
|
23 |
|
self::COLUMN_ALREADY_EXISTS |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $sequenceName |
131
|
|
|
* |
132
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
133
|
|
|
*/ |
134
|
23 |
|
public static function sequenceAlreadyExists($sequenceName) |
135
|
|
|
{ |
136
|
23 |
|
return new self("The sequence '" . $sequenceName . "' already exists.", self::SEQUENCE_ALREADY_EXISTS); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param string $sequenceName |
141
|
|
|
* |
142
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
143
|
|
|
*/ |
144
|
23 |
|
public static function sequenceDoesNotExist($sequenceName) |
145
|
|
|
{ |
146
|
23 |
|
return new self("There exists no sequence with the name '" . $sequenceName . "'.", self::SEQUENCE_DOENST_EXIST); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param string $constraintName |
151
|
|
|
* @param string $table |
152
|
|
|
* |
153
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
154
|
|
|
*/ |
155
|
|
|
public static function uniqueConstraintDoesNotExist($constraintName, $table) |
156
|
|
|
{ |
157
|
|
|
return new self( |
158
|
|
|
sprintf('There exists no unique constraint with the name "%s" on table "%s".', $constraintName, $table), |
159
|
|
|
self::CONSTRAINT_DOESNT_EXIST |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param string $fkName |
165
|
|
|
* @param string $table |
166
|
|
|
* |
167
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
168
|
|
|
*/ |
169
|
|
|
public static function foreignKeyDoesNotExist($fkName, $table) |
170
|
|
|
{ |
171
|
|
|
return new self( |
172
|
|
|
sprintf("There exists no foreign key with the name '%s' on table '%s'.", $fkName, $table), |
173
|
|
|
self::FOREIGNKEY_DOESNT_EXIST |
174
|
|
|
); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
179
|
|
|
*/ |
180
|
|
|
public static function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey) |
181
|
|
|
{ |
182
|
|
|
return new self( |
183
|
|
|
'The performed schema operation on ' . $localTable->getName() . ' requires a named foreign key, ' . |
184
|
|
|
'but the given foreign key from (' . implode(', ', $foreignKey->getColumns()) . ') onto foreign table ' . |
185
|
|
|
"'" . $foreignKey->getForeignTableName() . "' (" . implode(', ', $foreignKey->getForeignColumns()) . ') is currently ' . |
186
|
|
|
'unnamed.' |
187
|
|
|
); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param string $changeName |
192
|
|
|
* |
193
|
|
|
* @return \Doctrine\DBAL\Schema\SchemaException |
194
|
|
|
*/ |
195
|
|
|
public static function alterTableChangeNotSupported($changeName) |
196
|
|
|
{ |
197
|
|
|
return new self( |
198
|
|
|
sprintf("Alter table change not supported, given '%s'", $changeName) |
199
|
|
|
); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|