Permalink
Browse files

Merge pull request #473 from deeky666/DBAL-234

[DBAL-234] [DBAL-566] Add support for renaming indexes
  • Loading branch information...
2 parents fba268b + 7ed642d commit 6d0e8e2a8598f121cdb136507022915247fc98b8 @deeky666 deeky666 committed Dec 29, 2013
Showing with 858 additions and 7 deletions.
  1. +1 −0 docs/en/reference/platforms.rst
  2. +29 −0 lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
  3. +8 −1 lib/Doctrine/DBAL/Platforms/DB2Platform.php
  4. +281 −0 lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php
  5. +50 −0 lib/Doctrine/DBAL/Platforms/MySQL57Platform.php
  6. +8 −0 lib/Doctrine/DBAL/Platforms/OraclePlatform.php
  7. +9 −0 lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
  8. +10 −0 lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
  9. +15 −1 lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
  10. +2 −1 lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
  11. +5 −0 lib/Doctrine/DBAL/Schema/Comparator.php
  12. +46 −0 lib/Doctrine/DBAL/Schema/Table.php
  13. +7 −0 lib/Doctrine/DBAL/Schema/TableDiff.php
  14. +3 −0 lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php
  15. +16 −2 tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
  16. +64 −0 tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
  17. +21 −0 tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php
  18. +37 −0 tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php
  19. +24 −0 tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
  20. +21 −0 tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
  21. +21 −0 tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php
  22. +21 −0 tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
  23. +21 −0 tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php
  24. +31 −0 tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
  25. +7 −2 tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
  26. +100 −0 tests/Doctrine/Tests/DBAL/Schema/TableTest.php
@@ -34,6 +34,7 @@ MySQL
^^^^^
- ``MySqlPlatform`` for version 5.0 and above.
+- ``MySQL57Platform`` for version 5.7 and above.
Oracle
^^^^^^
@@ -21,6 +21,7 @@
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Connection;
+use Doctrine\DBAL\Schema\Identifier;
use Doctrine\DBAL\Types;
use Doctrine\DBAL\Schema\Constraint;
use Doctrine\DBAL\Schema\Sequence;
@@ -1823,10 +1824,12 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
: $diff->getName()->getQuotedName($this);
$sql = array();
+
if ($this->supportsForeignKeyConstraints()) {
foreach ($diff->addedForeignKeys as $foreignKey) {
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName);
}
+
foreach ($diff->changedForeignKeys as $foreignKey) {
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName);
}
@@ -1835,13 +1838,39 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
foreach ($diff->addedIndexes as $index) {
$sql[] = $this->getCreateIndexSQL($index, $tableName);
}
+
foreach ($diff->changedIndexes as $index) {
$sql[] = $this->getCreateIndexSQL($index, $tableName);
}
+ foreach ($diff->renamedIndexes as $oldIndexName => $index) {
+ $oldIndexName = new Identifier($oldIndexName);
+ $sql = array_merge(
+ $sql,
+ $this->getRenameIndexSQL($oldIndexName->getQuotedName($this), $index, $tableName)
+ );
+ }
+
return $sql;
}
+ /**
+ * Returns the SQL for renaming an index on a table.
+ *
+ * @param string $oldIndexName The name of the index to rename from.
+ * @param \Doctrine\DBAL\Schema\Index $index The definition of the index to rename to.
+ * @param string $tableName The table to rename the given index on.
+ *
+ * @return array The sequence of SQL statements for renaming the given index.
+ */
+ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
+ {
+ return array(
+ $this->getDropIndexSQL($oldIndexName, $tableName),
+ $this->getCreateIndexSQL($index, $tableName)
+ );
+ }
+
/**
* Common code for alter table statement generation that updates the changed Index and Foreign Key definitions.
*
@@ -19,7 +19,6 @@
namespace Doctrine\DBAL\Platforms;
-use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\TableDiff;
@@ -575,6 +574,14 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
return $sql;
}
+ /**
+ * {@inheritdoc}
+ */
+ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
+ {
+ return array('RENAME INDEX ' . $oldIndexName . ' TO ' . $index->getQuotedName($this));
+ }
+
/**
* {@inheritDoc}
*/
@@ -0,0 +1,281 @@
+<?php
+/*
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the MIT license. For more information, see
+ * <http://www.doctrine-project.org>.
+ */
+
+namespace Doctrine\DBAL\Platforms\Keywords;
+
+/**
+ * MySQL 5.7 reserved keywords list.
+ *
+ * @author Steve Müller <st.mueller@dzh-online.de>
+ * @link www.doctrine-project.org
+ * @since 2.5
+ */
+class MySQL57Keywords extends MySQLKeywords
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return 'MySQL57';
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * @link http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-7.html
+ */
+ protected function getKeywords()
+ {
+ return array(
+ 'ACCESSIBLE',
+ 'ADD',
+ 'ALL',
+ 'ALTER',
+ 'ANALYZE',
+ 'AND',
+ 'AS',
+ 'ASC',
+ 'ASENSITIVE',
+ 'BEFORE',
+ 'BETWEEN',
+ 'BIGINT',
+ 'BINARY',
+ 'BLOB',
+ 'BOTH',
+ 'BY',
+ 'CALL',
+ 'CASCADE',
+ 'CASE',
+ 'CHANGE',
+ 'CHAR',
+ 'CHARACTER',
+ 'CHECK',
+ 'COLLATE',
+ 'COLUMN',
+ 'CONDITION',
+ 'CONSTRAINT',
+ 'CONTINUE',
+ 'CONVERT',
+ 'CREATE',
+ 'CROSS',
+ 'CURRENT_DATE',
+ 'CURRENT_TIME',
+ 'CURRENT_TIMESTAMP',
+ 'CURRENT_USER',
+ 'CURSOR',
+ 'DATABASE',
+ 'DATABASES',
+ 'DAY_HOUR',
+ 'DAY_MICROSECOND',
+ 'DAY_MINUTE',
+ 'DAY_SECOND',
+ 'DEC',
+ 'DECIMAL',
+ 'DECLARE',
+ 'DEFAULT',
+ 'DELAYED',
+ 'DELETE',
+ 'DESC',
+ 'DESCRIBE',
+ 'DETERMINISTIC',
+ 'DISTINCT',
+ 'DIS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NONBLOCKING',
+ 'NOT',
+ 'NULL',
+ 'NUMERIC',
+ 'ON',
+ 'OPTIMIZE',
+ 'OPTION',
+ 'OPTIONALLY',
+ 'OR',
+ 'ORDER',
+ 'OUT',
+ 'OUTER',
+ 'OUTFILE',
+ 'PARTITION',
+ 'PRECISION',
+ 'PRIMARY',
+ 'PROCEDURE',
+ 'PURGE',
+ 'RANGE',
+ 'READ',
+ 'READ_WRITE',
+ 'READS',
+ 'REAL',
+ 'REFERENCES',
+ 'REGEXP',
+ 'RELEASE',
+ 'RENAME',
+ 'REPEAT',
+ 'REPLACE',
+ 'REQUIRE',
+ 'RESIGNAL',
+ 'RESTRICT',
+ 'RETURN',
+ 'REVOKE',
+ 'RIGHT',
+ 'RLIKE',
+ 'SCHEMA',
+ 'SCHEMAS',
+ 'SECOND_MICROSECOND',
+ 'SELECT',
+ 'SENSITIVE',
+ 'SEPARATOR',
+ 'SET',
+ 'SHOW',
+ 'SIGNAL',
+ 'SMALLINT',
+ 'SPATIAL',
+ 'SPECIFIC',
+ 'SQL',
+ 'SQL_BIG_RESULT',
+ 'SQL_CALC_FOUND_ROWS',
+ 'SQL_SMALL_RESULT',
+ 'SQLEXCEPTION',
+ 'SQLSTATE',
+ 'SQLWARNING',
+ 'SSL',
+ 'STARTING',
+ 'STRAIGHT_JOIN',
+ 'TABLE',
+ 'TERMINATED',
+ 'THEN',
+ 'TINYBLOB',
+ 'TINYINT',
+ 'TINYTEXT',
+ 'TO',
+ 'TRAILING',
+ 'TRIGGER',
+ 'TRUE',
+ 'UNDO',
+ 'UNION',
+ 'UNIQUE',
+ 'UNLOCK',
+ 'UNSIGNED',
+ 'UPDATE',
+ 'USAGE',
+ 'USE',
+ 'USING',
+ 'UTC_DATE',
+ 'UTC_TIME',
+ 'UTC_TIMESTAMP',
+ 'VALUES',
+ 'VARBINARY',
+ 'VARCHAR',
+ 'VARCHARACTER',
+ 'VARYING',
+ 'WHEN',
+ 'WHERE',
+ 'WHILE',
+ 'WITH',
+ 'WRITE',
+ 'XOR',
+ 'YEAR_MONTH',
+ 'ZEROFILL',
+ );
+ }
+}
Oops, something went wrong.

0 comments on commit 6d0e8e2

Please sign in to comment.