|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL\Schema; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\DBALException; |
|
8
|
|
|
use function implode; |
|
9
|
|
|
use function sprintf; |
|
10
|
|
|
|
|
11
|
|
|
class SchemaException extends DBALException |
|
12
|
|
|
{ |
|
13
|
|
|
public const TABLE_DOESNT_EXIST = 10; |
|
14
|
|
|
public const TABLE_ALREADY_EXISTS = 20; |
|
15
|
|
|
public const COLUMN_DOESNT_EXIST = 30; |
|
16
|
|
|
public const COLUMN_ALREADY_EXISTS = 40; |
|
17
|
|
|
public const INDEX_DOESNT_EXIST = 50; |
|
18
|
|
|
public const INDEX_ALREADY_EXISTS = 60; |
|
19
|
|
|
public const SEQUENCE_DOENST_EXIST = 70; |
|
20
|
|
|
public const SEQUENCE_ALREADY_EXISTS = 80; |
|
21
|
|
|
public const INDEX_INVALID_NAME = 90; |
|
22
|
|
|
public const FOREIGNKEY_DOESNT_EXIST = 100; |
|
23
|
|
|
public const CONSTRAINT_DOESNT_EXIST = 110; |
|
24
|
|
|
public const NAMESPACE_ALREADY_EXISTS = 120; |
|
25
|
|
|
|
|
26
|
|
|
public static function tableDoesNotExist(string $tableName) : self |
|
27
|
|
|
{ |
|
28
|
|
|
return new self("There is no table with name '" . $tableName . "' in the schema.", self::TABLE_DOESNT_EXIST); |
|
29
|
385 |
|
} |
|
30
|
|
|
|
|
31
|
385 |
|
public static function indexNameInvalid(string $indexName) : self |
|
32
|
|
|
{ |
|
33
|
|
|
return new self( |
|
34
|
|
|
sprintf('Invalid index-name %s given, has to be [a-zA-Z0-9_]', $indexName), |
|
35
|
|
|
self::INDEX_INVALID_NAME |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
145 |
|
public static function indexDoesNotExist(string $indexName, string $table) : self |
|
40
|
|
|
{ |
|
41
|
145 |
|
return new self( |
|
42
|
145 |
|
sprintf("Index '%s' does not exist on table '%s'.", $indexName, $table), |
|
43
|
145 |
|
self::INDEX_DOESNT_EXIST |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function indexAlreadyExists(string $indexName, string $table) : self |
|
48
|
|
|
{ |
|
49
|
|
|
return new self( |
|
50
|
|
|
sprintf("An index with name '%s' was already defined on table '%s'.", $indexName, $table), |
|
51
|
|
|
self::INDEX_ALREADY_EXISTS |
|
52
|
|
|
); |
|
53
|
218 |
|
} |
|
54
|
|
|
|
|
55
|
218 |
|
public static function columnDoesNotExist(string $columnName, string $table) : self |
|
56
|
218 |
|
{ |
|
57
|
218 |
|
return new self( |
|
58
|
|
|
sprintf("There is no column with name '%s' on table '%s'.", $columnName, $table), |
|
59
|
|
|
self::COLUMN_DOESNT_EXIST |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public static function namespaceAlreadyExists(string $namespaceName) : self |
|
64
|
|
|
{ |
|
65
|
|
|
return new self( |
|
66
|
|
|
sprintf("The namespace with name '%s' already exists.", $namespaceName), |
|
67
|
195 |
|
self::NAMESPACE_ALREADY_EXISTS |
|
68
|
|
|
); |
|
69
|
195 |
|
} |
|
70
|
195 |
|
|
|
71
|
195 |
|
public static function tableAlreadyExists(string $tableName) : self |
|
72
|
|
|
{ |
|
73
|
|
|
return new self("The table with name '" . $tableName . "' already exists.", self::TABLE_ALREADY_EXISTS); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public static function columnAlreadyExists(string $tableName, string $columnName) : self |
|
77
|
|
|
{ |
|
78
|
|
|
return new self( |
|
79
|
|
|
"The column '" . $columnName . "' on table '" . $tableName . "' already exists.", |
|
80
|
|
|
self::COLUMN_ALREADY_EXISTS |
|
81
|
268 |
|
); |
|
82
|
|
|
} |
|
83
|
268 |
|
|
|
84
|
268 |
|
public static function sequenceAlreadyExists(string $sequenceName) : self |
|
85
|
268 |
|
{ |
|
86
|
|
|
return new self("The sequence '" . $sequenceName . "' already exists.", self::SEQUENCE_ALREADY_EXISTS); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public static function sequenceDoesNotExist(string $sequenceName) : self |
|
90
|
|
|
{ |
|
91
|
|
|
return new self("There exists no sequence with the name '" . $sequenceName . "'.", self::SEQUENCE_DOENST_EXIST); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
289 |
|
public static function uniqueConstraintDoesNotExist(string $constraintName, string $table) : self |
|
95
|
|
|
{ |
|
96
|
289 |
|
return new self(sprintf( |
|
97
|
289 |
|
'There exists no unique constraint with the name "%s" on table "%s".', |
|
98
|
289 |
|
$constraintName, |
|
99
|
|
|
$table |
|
100
|
|
|
), self::CONSTRAINT_DOESNT_EXIST); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public static function foreignKeyDoesNotExist(string $fkName, string $table) : self |
|
104
|
|
|
{ |
|
105
|
|
|
return new self( |
|
106
|
|
|
sprintf("There exists no foreign key with the name '%s' on table '%s'.", $fkName, $table), |
|
107
|
361 |
|
self::FOREIGNKEY_DOESNT_EXIST |
|
108
|
|
|
); |
|
109
|
361 |
|
} |
|
110
|
|
|
|
|
111
|
|
|
public static function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey) : self |
|
112
|
|
|
{ |
|
113
|
|
|
return new self( |
|
114
|
|
|
'The performed schema operation on ' . $localTable->getName() . ' requires a named foreign key, ' . |
|
115
|
|
|
'but the given foreign key from (' . implode(', ', $foreignKey->getColumns()) . ') onto foreign table ' . |
|
116
|
|
|
"'" . $foreignKey->getForeignTableName() . "' (" . implode(', ', $foreignKey->getForeignColumns()) . ') is currently ' . |
|
117
|
|
|
'unnamed.' |
|
118
|
241 |
|
); |
|
119
|
|
|
} |
|
120
|
241 |
|
|
|
121
|
241 |
|
public static function namedIndexRequired(Table $table, Index $index) : self |
|
122
|
241 |
|
{ |
|
123
|
|
|
return new self( |
|
124
|
|
|
sprintf( |
|
125
|
|
|
'The performed schema operation on %s requires a named index, but the given index on (%s) is currently unnamed.', |
|
126
|
|
|
$table->getName(), |
|
127
|
|
|
implode(', ', $index->getColumns()) |
|
128
|
|
|
) |
|
129
|
|
|
); |
|
130
|
|
|
} |
|
131
|
313 |
|
|
|
132
|
|
|
public static function alterTableChangeNotSupported(string $changeName) : self |
|
133
|
313 |
|
{ |
|
134
|
|
|
return new self( |
|
135
|
|
|
sprintf("Alter table change not supported, given '%s'", $changeName) |
|
136
|
|
|
); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
|