BigIntMigration.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCP\Migration;
  7. use Doctrine\DBAL\Types\Type;
  8. use Doctrine\DBAL\Types\Types;
  9. use OCP\DB\ISchemaWrapper;
  10. /**
  11. * @since 13.0.0
  12. */
  13. abstract class BigIntMigration extends SimpleMigrationStep {
  14. /**
  15. * @return array Returns an array with the following structure
  16. * ['table1' => ['column1', 'column2'], ...]
  17. * @since 13.0.0
  18. */
  19. abstract protected function getColumnsByTable();
  20. /**
  21. * @param IOutput $output
  22. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  23. * @param array $options
  24. * @return null|ISchemaWrapper
  25. * @since 13.0.0
  26. */
  27. public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
  28. /** @var ISchemaWrapper $schema */
  29. $schema = $schemaClosure();
  30. $tables = $this->getColumnsByTable();
  31. foreach ($tables as $tableName => $columns) {
  32. $table = $schema->getTable($tableName);
  33. foreach ($columns as $columnName) {
  34. $column = $table->getColumn($columnName);
  35. if ($column->getType()->getName() !== Types::BIGINT) {
  36. $column->setType(Type::getType(Types::BIGINT));
  37. $column->setOptions(['length' => 20]);
  38. }
  39. }
  40. }
  41. return $schema;
  42. }
  43. }