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