mysqlmigrator.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OC\DB;
  9. use Doctrine\DBAL\Schema\Schema;
  10. class MySQLMigrator extends Migrator {
  11. /**
  12. * @param Schema $targetSchema
  13. * @param \Doctrine\DBAL\Connection $connection
  14. * @return \Doctrine\DBAL\Schema\SchemaDiff
  15. */
  16. protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
  17. $platform = $connection->getDatabasePlatform();
  18. $platform->registerDoctrineTypeMapping('enum', 'string');
  19. $platform->registerDoctrineTypeMapping('bit', 'string');
  20. $schemaDiff = parent::getDiff($targetSchema, $connection);
  21. // identifiers need to be quoted for mysql
  22. foreach ($schemaDiff->changedTables as $tableDiff) {
  23. $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
  24. foreach ($tableDiff->changedColumns as $column) {
  25. $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
  26. }
  27. }
  28. return $schemaDiff;
  29. }
  30. }