OracleMigrator.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OC\DB;
  25. use Doctrine\DBAL\Schema\ColumnDiff;
  26. use Doctrine\DBAL\Schema\Schema;
  27. class OracleMigrator extends NoCheckMigrator {
  28. /**
  29. * @param Schema $targetSchema
  30. * @param \Doctrine\DBAL\Connection $connection
  31. * @return \Doctrine\DBAL\Schema\SchemaDiff
  32. */
  33. protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
  34. $schemaDiff = parent::getDiff($targetSchema, $connection);
  35. // oracle forces us to quote the identifiers
  36. foreach ($schemaDiff->changedTables as $tableDiff) {
  37. $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
  38. foreach ($tableDiff->changedColumns as $column) {
  39. $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
  40. // auto increment is not relevant for oracle and can anyhow not be applied on change
  41. $column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']);
  42. }
  43. $tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) {
  44. return count($column->changedProperties) > 0;
  45. });
  46. }
  47. return $schemaDiff;
  48. }
  49. /**
  50. * @param string $name
  51. * @return string
  52. */
  53. protected function generateTemporaryTableName($name) {
  54. return 'oc_' . uniqid();
  55. }
  56. /**
  57. * @param $statement
  58. * @return string
  59. */
  60. protected function convertStatementToScript($statement) {
  61. if (substr($statement, -1) === ';') {
  62. return $statement . PHP_EOL . '/' . PHP_EOL;
  63. }
  64. $script = $statement . ';';
  65. $script .= PHP_EOL;
  66. $script .= PHP_EOL;
  67. return $script;
  68. }
  69. protected function getFilterExpression() {
  70. return '/^"' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
  71. }
  72. }