diff options
author | Joas Schilling <coding@schilljs.com> | 2017-09-19 12:10:48 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-09-29 11:10:56 +0200 |
commit | 124b4374d66d6ae22d0d9ec54b17fbcd4acb5bc7 (patch) | |
tree | 962d2447bacbd9144d6c6149bdaa4ccc167df952 /lib/public/Migration | |
parent | e5d39e63d15069d10fa723c34472be4b0b95d1ad (diff) | |
download | nextcloud-server-124b4374d66d6ae22d0d9ec54b17fbcd4acb5bc7.tar.gz nextcloud-server-124b4374d66d6ae22d0d9ec54b17fbcd4acb5bc7.zip |
Add a base migration for easy updating to bigints
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/public/Migration')
-rw-r--r-- | lib/public/Migration/BigIntMigration.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/public/Migration/BigIntMigration.php b/lib/public/Migration/BigIntMigration.php new file mode 100644 index 00000000000..91722671860 --- /dev/null +++ b/lib/public/Migration/BigIntMigration.php @@ -0,0 +1,66 @@ +<?php +/** + * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Migration; + +use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Types\Type; + +/** + * @since 13.0.0 + */ +abstract class BigIntMigration extends SimpleMigrationStep { + + /** + * @return array Returns an array with the following structure + * ['table1' => ['column1', 'column2'], ...] + * @since 13.0.0 + */ + abstract protected function getColumnsByTable(); + + /** + * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `Schema` + * @param array $options + * @return null|Schema + * @since 13.0.0 + */ + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + /** @var Schema $schema */ + $schema = $schemaClosure(); + + $tables = $this->getColumnsByTable(); + + foreach ($tables as $tableName => $columns) { + $table = $schema->getTable($tableName); + + foreach ($columns as $columnName) { + $column = $table->getColumn($columnName); + if ($column->getType()->getName() !== Type::BIGINT) { + $column->setType(Type::getType(Type::BIGINT)); + $column->setOptions(['length' => 20]); + } + } + } + + return $schema; + } +} |