SchemaException.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. namespace Doctrine\DBAL\Schema;
  20. class SchemaException extends \Doctrine\DBAL\DBALException
  21. {
  22. const TABLE_DOESNT_EXIST = 10;
  23. const TABLE_ALREADY_EXISTS = 20;
  24. const COLUMN_DOESNT_EXIST = 30;
  25. const COLUMN_ALREADY_EXISTS = 40;
  26. const INDEX_DOESNT_EXIST = 50;
  27. const INDEX_ALREADY_EXISTS = 60;
  28. const SEQUENCE_DOENST_EXIST = 70;
  29. const SEQUENCE_ALREADY_EXISTS = 80;
  30. const INDEX_INVALID_NAME = 90;
  31. const FOREIGNKEY_DOESNT_EXIST = 100;
  32. /**
  33. * @param string $tableName
  34. *
  35. * @return \Doctrine\DBAL\Schema\SchemaException
  36. */
  37. static public function tableDoesNotExist($tableName)
  38. {
  39. return new self("There is no table with name '".$tableName."' in the schema.", self::TABLE_DOESNT_EXIST);
  40. }
  41. /**
  42. * @param string $indexName
  43. *
  44. * @return \Doctrine\DBAL\Schema\SchemaException
  45. */
  46. static public function indexNameInvalid($indexName)
  47. {
  48. return new self("Invalid index-name $indexName given, has to be [a-zA-Z0-9_]", self::INDEX_INVALID_NAME);
  49. }
  50. /**
  51. * @param string $indexName
  52. * @param string $table
  53. *
  54. * @return \Doctrine\DBAL\Schema\SchemaException
  55. */
  56. static public function indexDoesNotExist($indexName, $table)
  57. {
  58. return new self("Index '$indexName' does not exist on table '$table'.", self::INDEX_DOESNT_EXIST);
  59. }
  60. /**
  61. * @param string $indexName
  62. * @param string $table
  63. *
  64. * @return \Doctrine\DBAL\Schema\SchemaException
  65. */
  66. static public function indexAlreadyExists($indexName, $table)
  67. {
  68. return new self("An index with name '$indexName' was already defined on table '$table'.", self::INDEX_ALREADY_EXISTS);
  69. }
  70. /**
  71. * @param string $columnName
  72. * @param string $table
  73. *
  74. * @return \Doctrine\DBAL\Schema\SchemaException
  75. */
  76. static public function columnDoesNotExist($columnName, $table)
  77. {
  78. return new self("There is no column with name '$columnName' on table '$table'.", self::COLUMN_DOESNT_EXIST);
  79. }
  80. /**
  81. * @param string $tableName
  82. *
  83. * @return \Doctrine\DBAL\Schema\SchemaException
  84. */
  85. static public function tableAlreadyExists($tableName)
  86. {
  87. return new self("The table with name '".$tableName."' already exists.", self::TABLE_ALREADY_EXISTS);
  88. }
  89. /**
  90. * @param string $tableName
  91. * @param string $columnName
  92. *
  93. * @return \Doctrine\DBAL\Schema\SchemaException
  94. */
  95. static public function columnAlreadyExists($tableName, $columnName)
  96. {
  97. return new self(
  98. "The column '".$columnName."' on table '".$tableName."' already exists.", self::COLUMN_ALREADY_EXISTS
  99. );
  100. }
  101. /**
  102. * @param string $sequenceName
  103. *
  104. * @return \Doctrine\DBAL\Schema\SchemaException
  105. */
  106. static public function sequenceAlreadyExists($sequenceName)
  107. {
  108. return new self("The sequence '".$sequenceName."' already exists.", self::SEQUENCE_ALREADY_EXISTS);
  109. }
  110. /**
  111. * @param string $sequenceName
  112. *
  113. * @return \Doctrine\DBAL\Schema\SchemaException
  114. */
  115. static public function sequenceDoesNotExist($sequenceName)
  116. {
  117. return new self("There exists no sequence with the name '".$sequenceName."'.", self::SEQUENCE_DOENST_EXIST);
  118. }
  119. /**
  120. * @param string $fkName
  121. * @param string $table
  122. *
  123. * @return \Doctrine\DBAL\Schema\SchemaException
  124. */
  125. static public function foreignKeyDoesNotExist($fkName, $table)
  126. {
  127. return new self("There exists no foreign key with the name '$fkName' on table '$table'.", self::FOREIGNKEY_DOESNT_EXIST);
  128. }
  129. /**
  130. * @param \Doctrine\DBAL\Schema\Table $localTable
  131. * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey
  132. *
  133. * @return \Doctrine\DBAL\Schema\SchemaException
  134. */
  135. static public function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey)
  136. {
  137. return new self(
  138. "The performed schema operation on ".$localTable->getName()." requires a named foreign key, ".
  139. "but the given foreign key from (".implode(", ", $foreignKey->getColumns()).") onto foreign table ".
  140. "'".$foreignKey->getForeignTableName()."' (".implode(", ", $foreignKey->getForeignColumns()).") is currently ".
  141. "unnamed."
  142. );
  143. }
  144. /**
  145. * @param string $changeName
  146. *
  147. * @return \Doctrine\DBAL\Schema\SchemaException
  148. */
  149. static public function alterTableChangeNotSupported($changeName)
  150. {
  151. return new self ("Alter table change not supported, given '$changeName'");
  152. }
  153. }