From b07a825a513cecf05c8557a303fa3e8715010cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Gieling?= Date: Sun, 7 Mar 2021 19:34:07 +0100 Subject: [PATCH] change migration (#1469) change migration --- CHANGELOG.md | 9 +- appinfo/info.xml | 6 +- .../Version0108Date20210207134703.php | 67 ---------- .../Version0108Date20210307130001.php | 114 ++++++++++++++++++ ....php => Version0108Date20210307130003.php} | 32 ++++- ....php => Version0108Date20210307130009.php} | 55 +++++++-- 6 files changed, 195 insertions(+), 88 deletions(-) delete mode 100644 lib/Migration/Version0108Date20210207134703.php create mode 100644 lib/Migration/Version0108Date20210307130001.php rename lib/Migration/{Version0108Date20210127135802.php => Version0108Date20210307130003.php} (72%) rename lib/Migration/{Version0108Date20210117010101.php => Version0108Date20210307130009.php} (50%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 989033e34..2981cc675 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. -## [2.0.0] - tbd -### supported NC version 21 -Same as 1.8.0 - -## [1.8.0] - tbd -### supported NC versions 19 - 20 +## [1.8.0 - beta1] - 2021-03-07 - [ux] #1164 - Wording: use list and table layout instead of desktop and mobile (#1443) - [ux] #1430 - Move poll informations to icon bar (info icon) (#1443) - - [ux] #1418 - Allow changing emailaddress in public polls (#1431) + - [ux] #1418 - Allow changing emailaddress in public polls (#1431) - [ux] #1401 - Change registation dialog layout (#1429) - [ux] #1400 - Optimizations for registration dialog on mobiles (#1429) - [enhancement] #325 - added markdown support for poll description (#1443) diff --git a/appinfo/info.xml b/appinfo/info.xml index 2511410a0..c65259f3d 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -23,19 +23,15 @@ https://raw.githubusercontent.com/nextcloud/polls/master/screenshots/vote.png https://raw.githubusercontent.com/nextcloud/polls/master/screenshots/edit-poll.png - + OCA\Polls\Cron\NotificationCron - OCA\Polls\Migration\RemoveIndices OCA\Polls\Migration\DeleteDuplicates - - OCA\Polls\Migration\CreateIndices - diff --git a/lib/Migration/Version0108Date20210207134703.php b/lib/Migration/Version0108Date20210207134703.php deleted file mode 100644 index 5d47bf252..000000000 --- a/lib/Migration/Version0108Date20210207134703.php +++ /dev/null @@ -1,67 +0,0 @@ - - * - * @author René Gieling - * - * @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 . - * - */ - -namespace OCA\Polls\Migration; - -use OCP\DB\ISchemaWrapper; -use OCP\IConfig; -use OCP\IDBConnection; -use OCP\Migration\SimpleMigrationStep; -use OCP\Migration\IOutput; - -class Version0108Date20210207134703 extends SimpleMigrationStep { - - /** @var IDBConnection */ - protected $connection; - - /** @var IConfig */ - protected $config; - - public function __construct(IDBConnection $connection, IConfig $config) { - $this->connection = $connection; - $this->config = $config; - } - - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { - /** @var ISchemaWrapper $schema */ - $schema = $schemaClosure(); - if ($schema->hasTable('polls_polls')) { - $table = $schema->getTable('polls_polls'); - if (!$table->hasColumn('allow_comment')) { - $table->addColumn('allow_comment', 'integer', [ - 'length' => 11, - 'notnull' => true, - 'default' => 1 - ]); - } - if (!$table->hasColumn('hide_booked_up')) { - $table->addColumn('hide_booked_up', 'integer', [ - 'length' => 11, - 'notnull' => true, - 'default' => 1 - ]); - } - } - return $schema; - } -} diff --git a/lib/Migration/Version0108Date20210307130001.php b/lib/Migration/Version0108Date20210307130001.php new file mode 100644 index 000000000..e029e4503 --- /dev/null +++ b/lib/Migration/Version0108Date20210307130001.php @@ -0,0 +1,114 @@ + + * + * @author René Gieling + * + * @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 . + * + */ + +namespace OCA\Polls\Migration; + +use OCP\DB\ISchemaWrapper; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +class Version0108Date20210307130001 extends SimpleMigrationStep { + + /** @var IDBConnection */ + protected $connection; + + /** @var IConfig */ + protected $config; + + public function __construct(IDBConnection $connection, IConfig $config) { + $this->connection = $connection; + $this->config = $config; + } + + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + if ($schema->hasTable('polls_options')) { + $table = $schema->getTable('polls_options'); + foreach ($table->getIndexes() as $index) { + if (strpos($index->getName(), 'UNIQ_') === 0) { + $table->dropIndex($index->getName()); + } + } + } + + if ($schema->hasTable('polls_log')) { + $table = $schema->getTable('polls_log'); + foreach ($table->getIndexes() as $index) { + if (strpos($index->getName(), 'UNIQ_') === 0) { + $table->dropIndex($index->getName()); + } + } + } + + if ($schema->hasTable('polls_notif')) { + $table = $schema->getTable('polls_notif'); + foreach ($table->getIndexes() as $index) { + if (strpos($index->getName(), 'UNIQ_') === 0) { + $table->dropIndex($index->getName()); + } + } + } + + if ($schema->hasTable('polls_share')) { + $table = $schema->getTable('polls_share'); + foreach ($table->getIndexes() as $index) { + if (strpos($index->getName(), 'UNIQ_') === 0) { + $table->dropIndex($index->getName()); + } + } + } + + if ($schema->hasTable('polls_votes')) { + $table = $schema->getTable('polls_votes'); + foreach ($table->getIndexes() as $index) { + if (strpos($index->getName(), 'UNIQ_') === 0) { + $table->dropIndex($index->getName()); + } + } + } + + if ($schema->hasTable('polls_preferences')) { + $table = $schema->getTable('polls_preferences'); + foreach ($table->getIndexes() as $index) { + if (strpos($index->getName(), 'UNIQ_') === 0) { + $table->dropIndex($index->getName()); + } + } + } + + if ($schema->hasTable('polls_watch')) { + $table = $schema->getTable('polls_watch'); + foreach ($table->getIndexes() as $index) { + if (strpos($index->getName(), 'UNIQ_') === 0) { + $table->dropIndex($index->getName()); + } + } + } + + return $schema; + } +} diff --git a/lib/Migration/Version0108Date20210127135802.php b/lib/Migration/Version0108Date20210307130003.php similarity index 72% rename from lib/Migration/Version0108Date20210127135802.php rename to lib/Migration/Version0108Date20210307130003.php index 75c23fbdb..c629c5298 100644 --- a/lib/Migration/Version0108Date20210127135802.php +++ b/lib/Migration/Version0108Date20210307130003.php @@ -29,7 +29,7 @@ use OCP\IDBConnection; use OCP\Migration\SimpleMigrationStep; use OCP\Migration\IOutput; -class Version0108Date20210127135802 extends SimpleMigrationStep { +class Version0108Date20210307130003 extends SimpleMigrationStep { /** @var IDBConnection */ protected $connection; @@ -45,6 +45,36 @@ class Version0108Date20210127135802 extends SimpleMigrationStep { public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); + if ($schema->hasTable('polls_polls')) { + $table = $schema->getTable('polls_polls'); + if (!$table->hasColumn('allow_comment')) { + $table->addColumn('allow_comment', 'integer', [ + 'length' => 11, + 'notnull' => true, + 'default' => 1 + ]); + } + if (!$table->hasColumn('hide_booked_up')) { + $table->addColumn('hide_booked_up', 'integer', [ + 'length' => 11, + 'notnull' => true, + 'default' => 1 + ]); + } + } + + if ($schema->hasTable('polls_options')) { + $table = $schema->getTable('polls_options'); + + if (!$table->hasColumn('duration')) { + $table->addColumn('duration', 'integer', [ + 'length' => 11, + 'notnull' => true, + 'default' => 0 + ]); + } + } + if (!$schema->hasTable('polls_watch')) { $table = $schema->createTable('polls_watch'); $table->addColumn('id', 'integer', [ diff --git a/lib/Migration/Version0108Date20210117010101.php b/lib/Migration/Version0108Date20210307130009.php similarity index 50% rename from lib/Migration/Version0108Date20210117010101.php rename to lib/Migration/Version0108Date20210307130009.php index 2d91fbac7..8f7bf109a 100644 --- a/lib/Migration/Version0108Date20210117010101.php +++ b/lib/Migration/Version0108Date20210307130009.php @@ -29,7 +29,7 @@ use OCP\IDBConnection; use OCP\Migration\SimpleMigrationStep; use OCP\Migration\IOutput; -class Version0108Date20210117010101 extends SimpleMigrationStep { +class Version0108Date20210307130009 extends SimpleMigrationStep { /** @var IDBConnection */ protected $connection; @@ -45,17 +45,56 @@ class Version0108Date20210117010101 extends SimpleMigrationStep { public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); + if ($schema->hasTable('polls_options')) { $table = $schema->getTable('polls_options'); - - if (!$table->hasColumn('duration')) { - $table->addColumn('duration', 'integer', [ - 'length' => 11, - 'notnull' => true, - 'default' => 0 - ]); + if (!$table->hasIndex('UNIQ_options')) { + $table->addUniqueIndex(['poll_id', 'poll_option_text', 'timestamp'], 'UNIQ_options'); } } + + if ($schema->hasTable('polls_log')) { + $table = $schema->getTable('polls_log'); + if (!$table->hasIndex('UNIQ_unprocessed')) { + $table->addUniqueIndex(['processed', 'poll_id', 'user_id', 'message_id'], 'UNIQ_unprocessed'); + } + } + + if ($schema->hasTable('polls_notif')) { + $table = $schema->getTable('polls_notif'); + if (!$table->hasIndex('UNIQ_subscription')) { + $table->addUniqueIndex(['poll_id', 'user_id'], 'UNIQ_subscription'); + } + } + + if ($schema->hasTable('polls_share')) { + $table = $schema->getTable('polls_share'); + if (!$table->hasIndex('UNIQ_shares')) { + $table->addUniqueIndex(['poll_id', 'user_id'], 'UNIQ_shares'); + } + } + + if ($schema->hasTable('polls_votes')) { + $table = $schema->getTable('polls_votes'); + if (!$table->hasIndex('UNIQ_votes')) { + $table->addUniqueIndex(['poll_id', 'user_id', 'vote_option_text'], 'UNIQ_votes'); + } + } + + if ($schema->hasTable('polls_preferences')) { + $table = $schema->getTable('polls_preferences'); + if (!$table->hasIndex('UNIQ_preferences')) { + $table->addUniqueIndex(['user_id'], 'UNIQ_preferences'); + } + } + + if ($schema->hasTable('polls_watch')) { + $table = $schema->getTable('polls_watch'); + if (!$table->hasIndex('UNIQ_watch')) { + $table->addUniqueIndex(['poll_id', 'table'], 'UNIQ_watch'); + } + } + return $schema; } }