Commit c9041d60 authored by Benjamin Eberlei's avatar Benjamin Eberlei

DBAL-28 - Better error messages on SchemaException

parent 360bdf6f
......@@ -37,27 +37,27 @@ class SchemaException extends \Doctrine\DBAL\DBALException
* @param string $indexName
* @return SchemaException
*/
static public function indexDoesNotExist($indexName)
static public function indexDoesNotExist($indexName, $table)
{
return new self("Index '".$indexName."' does not exist.", self::INDEX_DOESNT_EXIST);
return new self("Index '$indexName' does not exist on table '$table'.", self::INDEX_DOESNT_EXIST);
}
/**
* @param string $indexName
* @return SchemaException
*/
static public function indexAlreadyExists($indexName)
static public function indexAlreadyExists($indexName, $table)
{
return new self("An index with name $indexName was already defined.", self::INDEX_ALREADY_EXISTS);
return new self("An index with name '$indexName' was already defined on table '$table'.", self::INDEX_ALREADY_EXISTS);
}
/**
* @param string $columnName
* @return SchemaException
*/
static public function columnDoesNotExist($columnName)
static public function columnDoesNotExist($columnName, $table)
{
return new self("An unknown column-name $columnName was given.", self::COLUMN_DOESNT_EXIST);
return new self("There is no column with name '$columnName' on table '$table'.", self::COLUMN_DOESNT_EXIST);
}
/**
......@@ -105,12 +105,12 @@ class SchemaException extends \Doctrine\DBAL\DBALException
* @param string $fkName
* @return SchemaException
*/
static public function foreignKeyDoesNotExist($fkName)
static public function foreignKeyDoesNotExist($fkName, $table)
{
return new self("There exists no foreign key with the name '".$fkName."'.", self::FOREIGNKEY_DOESNT_EXIST);
return new self("There exists no foreign key with the name '$fkName' on table '$table'.", self::FOREIGNKEY_DOESNT_EXIST);
}
static public function namedForeignKeyRequired($localTable, $foreignKey)
static public function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey)
{
return new self(
"The performed schema operation on ".$localTable->getName()." requires a named foreign key, ".
......
......@@ -220,7 +220,7 @@ class Table extends AbstractAsset
}
if ( ! $this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName);
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
}
}
$this->_addIndex(new Index($indexName, $columnNames, $isUnique, $isPrimary));
......@@ -336,7 +336,7 @@ class Table extends AbstractAsset
foreach ($foreignColumnNames AS $columnName) {
if ( ! $foreignTable->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName);
throw SchemaException::columnDoesNotExist($columnName, $foreignTable->getName());
}
}
} else {
......@@ -345,7 +345,7 @@ class Table extends AbstractAsset
foreach ($localColumnNames AS $columnName) {
if ( ! $this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName);
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
}
}
......@@ -403,7 +403,7 @@ class Table extends AbstractAsset
$indexName = strtolower($indexName);
if (isset($this->_indexes[$indexName]) || ($this->_primaryKeyName != false && $index->isPrimary())) {
throw SchemaException::indexAlreadyExists($indexName);
throw SchemaException::indexAlreadyExists($indexName, $this->_name);
}
if ($index->isPrimary()) {
......@@ -453,7 +453,7 @@ class Table extends AbstractAsset
{
$constraintName = strtolower($constraintName);
if(!$this->hasForeignKey($constraintName)) {
throw SchemaException::foreignKeyDoesNotExist($constraintName);
throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name);
}
return $this->_fkConstraints[$constraintName];
......@@ -507,7 +507,7 @@ class Table extends AbstractAsset
{
$columnName = strtolower($columnName);
if (!$this->hasColumn($columnName)) {
throw SchemaException::columnDoesNotExist($columnName);
throw SchemaException::columnDoesNotExist($columnName, $this->_name);
}
return $this->_columns[$columnName];
......@@ -539,7 +539,7 @@ class Table extends AbstractAsset
{
$indexName = strtolower($indexName);
if (!$this->hasIndex($indexName)) {
throw SchemaException::indexDoesNotExist($indexName);
throw SchemaException::indexDoesNotExist($indexName, $this->_name);
}
return $this->_indexes[$indexName];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment