From d5df033ede1f2b19b87c365b1f808130023edf17 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Nov 2020 09:34:57 +0100 Subject: Create primary keys on all tables and add a command to create the afterwards Signed-off-by: Joas Schilling --- core/Application.php | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'core/Application.php') diff --git a/core/Application.php b/core/Application.php index a452ca9677f..d9d6b92a2ad 100644 --- a/core/Application.php +++ b/core/Application.php @@ -42,6 +42,7 @@ use OC\Authentication\Notifications\Notifier as AuthenticationNotifier; use OC\Core\Notification\RemoveLinkSharesNotifier; use OC\DB\MissingColumnInformation; use OC\DB\MissingIndexInformation; +use OC\DB\MissingPrimaryKeyInformation; use OC\DB\SchemaWrapper; use OCP\AppFramework\App; use OCP\EventDispatcher\IEventDispatcher; @@ -181,6 +182,63 @@ class Application extends App { } ); + $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT, + function (GenericEvent $event) use ($container) { + /** @var MissingPrimaryKeyInformation $subject */ + $subject = $event->getSubject(); + + $schema = new SchemaWrapper($container->query(IDBConnection::class)); + + if ($schema->hasTable('federated_reshares')) { + $table = $schema->getTable('federated_reshares'); + + if (!$table->hasPrimaryKey()) { + $subject->addHintForMissingSubject($table->getName()); + } + } + + if ($schema->hasTable('systemtag_object_mapping')) { + $table = $schema->getTable('systemtag_object_mapping'); + + if (!$table->hasPrimaryKey()) { + $subject->addHintForMissingSubject($table->getName()); + } + } + + if ($schema->hasTable('comments_read_markers')) { + $table = $schema->getTable('comments_read_markers'); + + if (!$table->hasPrimaryKey()) { + $subject->addHintForMissingSubject($table->getName()); + } + } + + if ($schema->hasTable('collres_resources')) { + $table = $schema->getTable('collres_resources'); + + if (!$table->hasPrimaryKey()) { + $subject->addHintForMissingSubject($table->getName()); + } + } + + if ($schema->hasTable('collres_accesscache')) { + $table = $schema->getTable('collres_accesscache'); + + if (!$table->hasPrimaryKey()) { + $subject->addHintForMissingSubject($table->getName()); + } + } + + if ($schema->hasTable('filecache_extended')) { + $table = $schema->getTable('filecache_extended'); + + if (!$table->hasPrimaryKey()) { + $subject->addHintForMissingSubject($table->getName()); + } + } + } + ); + $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT, function (GenericEvent $event) use ($container) { /** @var MissingColumnInformation $subject */ -- cgit v1.2.3