oraclemigrator.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\Schema;
  26. class OracleMigrator extends NoCheckMigrator {
  27. /**
  28. * @param Schema $targetSchema
  29. * @param \Doctrine\DBAL\Connection $connection
  30. * @return \Doctrine\DBAL\Schema\SchemaDiff
  31. */
  32. protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
  33. $schemaDiff = parent::getDiff($targetSchema, $connection);
  34. // oracle forces us to quote the identifiers
  35. foreach ($schemaDiff->changedTables as $tableDiff) {
  36. $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
  37. foreach ($tableDiff->changedColumns as $column) {
  38. $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
  39. }
  40. }
  41. return $schemaDiff;
  42. }
  43. /**
  44. * @param string $name
  45. * @return string
  46. */
  47. protected function generateTemporaryTableName($name) {
  48. return 'oc_' . uniqid();
  49. }
  50. /**
  51. * @param $statement
  52. * @return string
  53. */
  54. protected function convertStatementToScript($statement) {
  55. if (substr($statement, -1) === ';') {
  56. return $statement . PHP_EOL . '/' . PHP_EOL;
  57. }
  58. $script = $statement . ';';
  59. $script .= PHP_EOL;
  60. $script .= PHP_EOL;
  61. return $script;
  62. }
  63. protected function getFilterExpression() {
  64. return '/^"' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/';
  65. }
  66. }