AddMissingIndices.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
  5. *
  6. * @author Bjoern Schiessle <bjoern@schiessle.org>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Mario Danic <mario@lovelyhq.com>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin Appelman <robin@icewind.nl>
  13. * @author Roeland Jago Douma <roeland@famdouma.nl>
  14. * @author Thomas Citharel <nextcloud@tcit.fr>
  15. *
  16. * @license GNU AGPL version 3 or any later version
  17. *
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License as
  20. * published by the Free Software Foundation, either version 3 of the
  21. * License, or (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. *
  31. */
  32. namespace OC\Core\Command\Db;
  33. use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
  34. use OC\DB\Connection;
  35. use OC\DB\SchemaWrapper;
  36. use OCP\DB\Events\AddMissingIndicesEvent;
  37. use OCP\EventDispatcher\IEventDispatcher;
  38. use OCP\IDBConnection;
  39. use Symfony\Component\Console\Command\Command;
  40. use Symfony\Component\Console\Input\InputOption;
  41. use Symfony\Component\Console\Input\InputInterface;
  42. use Symfony\Component\Console\Output\OutputInterface;
  43. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  44. use Symfony\Component\EventDispatcher\GenericEvent;
  45. /**
  46. * Class AddMissingIndices
  47. *
  48. * if you added any new indices to the database, this is the right place to add
  49. * your update routine for existing instances
  50. *
  51. * @package OC\Core\Command\Db
  52. */
  53. class AddMissingIndices extends Command {
  54. private Connection $connection;
  55. private IEventDispatcher $eventDispatcher;
  56. private EventDispatcherInterface $dispatcher;
  57. public function __construct(Connection $connection, IEventDispatcher $eventDispatcher, EventDispatcherInterface $dispatcher) {
  58. parent::__construct();
  59. $this->connection = $connection;
  60. $this->eventDispatcher = $eventDispatcher;
  61. $this->dispatcher = $dispatcher;
  62. }
  63. protected function configure() {
  64. $this
  65. ->setName('db:add-missing-indices')
  66. ->setDescription('Add missing indices to the database tables')
  67. ->addOption('dry-run', null, InputOption::VALUE_NONE, "Output the SQL queries instead of running them.");
  68. }
  69. protected function execute(InputInterface $input, OutputInterface $output): int {
  70. $dryRun = $input->getOption('dry-run');
  71. $this->addCoreIndexes($output, $dryRun);
  72. // Dispatch event so apps can also update indexes if needed
  73. $event = new GenericEvent($output);
  74. $this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event);
  75. $event = new AddMissingIndicesEvent();
  76. $this->eventDispatcher->dispatchTyped($event);
  77. $missingIndices = $event->getMissingIndices();
  78. if ($missingIndices !== []) {
  79. $schema = new SchemaWrapper($this->connection);
  80. foreach ($missingIndices as $missingIndex) {
  81. if ($schema->hasTable($missingIndex['tableName'])) {
  82. $table = $schema->getTable($missingIndex['tableName']);
  83. if (!$table->hasIndex($missingIndex['indexName'])) {
  84. $output->writeln('<info>Adding additional ' . $missingIndex['indexName'] . ' index to the ' . $table->getName() . ' table, this can take some time...</info>');
  85. $table->addIndex($missingIndex['columns'], $missingIndex['indexName']);
  86. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  87. if ($dryRun && $sqlQueries !== null) {
  88. $output->writeln($sqlQueries);
  89. }
  90. $output->writeln('<info>' . $table->getName() . ' table updated successfully.</info>');
  91. }
  92. }
  93. }
  94. }
  95. return 0;
  96. }
  97. /**
  98. * add missing indices to the share table
  99. *
  100. * @param OutputInterface $output
  101. * @param bool $dryRun If true, will return the sql queries instead of running them.
  102. * @throws \Doctrine\DBAL\Schema\SchemaException
  103. */
  104. private function addCoreIndexes(OutputInterface $output, bool $dryRun): void {
  105. $output->writeln('<info>Check indices of the share table.</info>');
  106. $schema = new SchemaWrapper($this->connection);
  107. $updated = false;
  108. if ($schema->hasTable('share')) {
  109. $table = $schema->getTable('share');
  110. if (!$table->hasIndex('share_with_index')) {
  111. $output->writeln('<info>Adding additional share_with index to the share table, this can take some time...</info>');
  112. $table->addIndex(['share_with'], 'share_with_index');
  113. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  114. if ($dryRun && $sqlQueries !== null) {
  115. $output->writeln($sqlQueries);
  116. }
  117. $updated = true;
  118. $output->writeln('<info>Share table updated successfully.</info>');
  119. }
  120. if (!$table->hasIndex('parent_index')) {
  121. $output->writeln('<info>Adding additional parent index to the share table, this can take some time...</info>');
  122. $table->addIndex(['parent'], 'parent_index');
  123. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  124. if ($dryRun && $sqlQueries !== null) {
  125. $output->writeln($sqlQueries);
  126. }
  127. $updated = true;
  128. $output->writeln('<info>Share table updated successfully.</info>');
  129. }
  130. if (!$table->hasIndex('owner_index')) {
  131. $output->writeln('<info>Adding additional owner index to the share table, this can take some time...</info>');
  132. $table->addIndex(['uid_owner'], 'owner_index');
  133. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  134. if ($dryRun && $sqlQueries !== null) {
  135. $output->writeln($sqlQueries);
  136. }
  137. $updated = true;
  138. $output->writeln('<info>Share table updated successfully.</info>');
  139. }
  140. if (!$table->hasIndex('initiator_index')) {
  141. $output->writeln('<info>Adding additional initiator index to the share table, this can take some time...</info>');
  142. $table->addIndex(['uid_initiator'], 'initiator_index');
  143. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  144. if ($dryRun && $sqlQueries !== null) {
  145. $output->writeln($sqlQueries);
  146. }
  147. $updated = true;
  148. $output->writeln('<info>Share table updated successfully.</info>');
  149. }
  150. }
  151. $output->writeln('<info>Check indices of the filecache table.</info>');
  152. if ($schema->hasTable('filecache')) {
  153. $table = $schema->getTable('filecache');
  154. if (!$table->hasIndex('fs_mtime')) {
  155. $output->writeln('<info>Adding additional mtime index to the filecache table, this can take some time...</info>');
  156. $table->addIndex(['mtime'], 'fs_mtime');
  157. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  158. if ($dryRun && $sqlQueries !== null) {
  159. $output->writeln($sqlQueries);
  160. }
  161. $updated = true;
  162. $output->writeln('<info>Filecache table updated successfully.</info>');
  163. }
  164. if (!$table->hasIndex('fs_size')) {
  165. $output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>');
  166. $table->addIndex(['size'], 'fs_size');
  167. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  168. if ($dryRun && $sqlQueries !== null) {
  169. $output->writeln($sqlQueries);
  170. }
  171. $updated = true;
  172. $output->writeln('<info>Filecache table updated successfully.</info>');
  173. }
  174. if (!$table->hasIndex('fs_id_storage_size')) {
  175. $output->writeln('<info>Adding additional size index to the filecache table, this can take some time...</info>');
  176. $table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size');
  177. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  178. if ($dryRun && $sqlQueries !== null) {
  179. $output->writeln($sqlQueries);
  180. }
  181. $updated = true;
  182. $output->writeln('<info>Filecache table updated successfully.</info>');
  183. }
  184. if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
  185. $output->writeln('<info>Adding additional path index to the filecache table, this can take some time...</info>');
  186. $table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]);
  187. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  188. if ($dryRun && $sqlQueries !== null) {
  189. $output->writeln($sqlQueries);
  190. }
  191. $updated = true;
  192. $output->writeln('<info>Filecache table updated successfully.</info>');
  193. }
  194. if (!$table->hasIndex('fs_parent')) {
  195. $output->writeln('<info>Adding additional parent index to the filecache table, this can take some time...</info>');
  196. $table->addIndex(['parent'], 'fs_parent');
  197. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  198. if ($dryRun && $sqlQueries !== null) {
  199. $output->writeln($sqlQueries);
  200. }
  201. $updated = true;
  202. $output->writeln('<info>Filecache table updated successfully.</info>');
  203. }
  204. }
  205. $output->writeln('<info>Check indices of the twofactor_providers table.</info>');
  206. if ($schema->hasTable('twofactor_providers')) {
  207. $table = $schema->getTable('twofactor_providers');
  208. if (!$table->hasIndex('twofactor_providers_uid')) {
  209. $output->writeln('<info>Adding additional twofactor_providers_uid index to the twofactor_providers table, this can take some time...</info>');
  210. $table->addIndex(['uid'], 'twofactor_providers_uid');
  211. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  212. if ($dryRun && $sqlQueries !== null) {
  213. $output->writeln($sqlQueries);
  214. }
  215. $updated = true;
  216. $output->writeln('<info>Twofactor_providers table updated successfully.</info>');
  217. }
  218. }
  219. $output->writeln('<info>Check indices of the login_flow_v2 table.</info>');
  220. if ($schema->hasTable('login_flow_v2')) {
  221. $table = $schema->getTable('login_flow_v2');
  222. if (!$table->hasIndex('poll_token')) {
  223. $output->writeln('<info>Adding additional indeces to the login_flow_v2 table, this can take some time...</info>');
  224. foreach ($table->getIndexes() as $index) {
  225. $columns = $index->getColumns();
  226. if ($columns === ['poll_token'] ||
  227. $columns === ['login_token'] ||
  228. $columns === ['timestamp']) {
  229. $table->dropIndex($index->getName());
  230. }
  231. }
  232. $table->addUniqueIndex(['poll_token'], 'poll_token');
  233. $table->addUniqueIndex(['login_token'], 'login_token');
  234. $table->addIndex(['timestamp'], 'timestamp');
  235. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  236. if ($dryRun && $sqlQueries !== null) {
  237. $output->writeln($sqlQueries);
  238. }
  239. $updated = true;
  240. $output->writeln('<info>login_flow_v2 table updated successfully.</info>');
  241. }
  242. }
  243. $output->writeln('<info>Check indices of the whats_new table.</info>');
  244. if ($schema->hasTable('whats_new')) {
  245. $table = $schema->getTable('whats_new');
  246. if (!$table->hasIndex('version')) {
  247. $output->writeln('<info>Adding version index to the whats_new table, this can take some time...</info>');
  248. foreach ($table->getIndexes() as $index) {
  249. if ($index->getColumns() === ['version']) {
  250. $table->dropIndex($index->getName());
  251. }
  252. }
  253. $table->addUniqueIndex(['version'], 'version');
  254. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  255. if ($dryRun && $sqlQueries !== null) {
  256. $output->writeln($sqlQueries);
  257. }
  258. $updated = true;
  259. $output->writeln('<info>whats_new table updated successfully.</info>');
  260. }
  261. }
  262. $output->writeln('<info>Check indices of the cards table.</info>');
  263. $cardsUpdated = false;
  264. if ($schema->hasTable('cards')) {
  265. $table = $schema->getTable('cards');
  266. if ($table->hasIndex('addressbookid_uri_index')) {
  267. if ($table->hasIndex('cards_abiduri')) {
  268. $table->dropIndex('addressbookid_uri_index');
  269. } else {
  270. $output->writeln('<info>Renaming addressbookid_uri_index index to cards_abiduri in the cards table, this can take some time...</info>');
  271. foreach ($table->getIndexes() as $index) {
  272. if ($index->getColumns() === ['addressbookid', 'uri']) {
  273. $table->renameIndex('addressbookid_uri_index', 'cards_abiduri');
  274. }
  275. }
  276. }
  277. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  278. if ($dryRun && $sqlQueries !== null) {
  279. $output->writeln($sqlQueries);
  280. }
  281. $cardsUpdated = true;
  282. }
  283. if (!$table->hasIndex('cards_abid')) {
  284. $output->writeln('<info>Adding cards_abid index to the cards table, this can take some time...</info>');
  285. foreach ($table->getIndexes() as $index) {
  286. if ($index->getColumns() === ['addressbookid']) {
  287. $table->dropIndex($index->getName());
  288. }
  289. }
  290. $table->addIndex(['addressbookid'], 'cards_abid');
  291. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  292. if ($dryRun && $sqlQueries !== null) {
  293. $output->writeln($sqlQueries);
  294. }
  295. $cardsUpdated = true;
  296. }
  297. if (!$table->hasIndex('cards_abiduri')) {
  298. $output->writeln('<info>Adding cards_abiduri index to the cards table, this can take some time...</info>');
  299. foreach ($table->getIndexes() as $index) {
  300. if ($index->getColumns() === ['addressbookid', 'uri']) {
  301. $table->dropIndex($index->getName());
  302. }
  303. }
  304. $table->addIndex(['addressbookid', 'uri'], 'cards_abiduri');
  305. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  306. if ($dryRun && $sqlQueries !== null) {
  307. $output->writeln($sqlQueries);
  308. }
  309. $cardsUpdated = true;
  310. }
  311. if ($cardsUpdated) {
  312. $updated = true;
  313. $output->writeln('<info>cards table updated successfully.</info>');
  314. }
  315. }
  316. $output->writeln('<info>Check indices of the cards_properties table.</info>');
  317. if ($schema->hasTable('cards_properties')) {
  318. $table = $schema->getTable('cards_properties');
  319. if (!$table->hasIndex('cards_prop_abid')) {
  320. $output->writeln('<info>Adding cards_prop_abid index to the cards_properties table, this can take some time...</info>');
  321. foreach ($table->getIndexes() as $index) {
  322. if ($index->getColumns() === ['addressbookid']) {
  323. $table->dropIndex($index->getName());
  324. }
  325. }
  326. $table->addIndex(['addressbookid'], 'cards_prop_abid');
  327. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  328. if ($dryRun && $sqlQueries !== null) {
  329. $output->writeln($sqlQueries);
  330. }
  331. $updated = true;
  332. $output->writeln('<info>cards_properties table updated successfully.</info>');
  333. }
  334. }
  335. $output->writeln('<info>Check indices of the calendarobjects_props table.</info>');
  336. if ($schema->hasTable('calendarobjects_props')) {
  337. $table = $schema->getTable('calendarobjects_props');
  338. if (!$table->hasIndex('calendarobject_calid_index')) {
  339. $output->writeln('<info>Adding calendarobject_calid_index index to the calendarobjects_props table, this can take some time...</info>');
  340. $table->addIndex(['calendarid', 'calendartype'], 'calendarobject_calid_index');
  341. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  342. if ($dryRun && $sqlQueries !== null) {
  343. $output->writeln($sqlQueries);
  344. }
  345. $updated = true;
  346. $output->writeln('<info>calendarobjects_props table updated successfully.</info>');
  347. }
  348. }
  349. $output->writeln('<info>Check indices of the schedulingobjects table.</info>');
  350. if ($schema->hasTable('schedulingobjects')) {
  351. $table = $schema->getTable('schedulingobjects');
  352. if (!$table->hasIndex('schedulobj_principuri_index')) {
  353. $output->writeln('<info>Adding schedulobj_principuri_index index to the schedulingobjects table, this can take some time...</info>');
  354. $table->addIndex(['principaluri'], 'schedulobj_principuri_index');
  355. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  356. if ($dryRun && $sqlQueries !== null) {
  357. $output->writeln($sqlQueries);
  358. }
  359. $updated = true;
  360. $output->writeln('<info>schedulingobjects table updated successfully.</info>');
  361. }
  362. }
  363. $output->writeln('<info>Check indices of the oc_properties table.</info>');
  364. if ($schema->hasTable('properties')) {
  365. $table = $schema->getTable('properties');
  366. $propertiesUpdated = false;
  367. if (!$table->hasIndex('properties_path_index')) {
  368. $output->writeln('<info>Adding properties_path_index index to the oc_properties table, this can take some time...</info>');
  369. $table->addIndex(['userid', 'propertypath'], 'properties_path_index');
  370. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  371. if ($dryRun && $sqlQueries !== null) {
  372. $output->writeln($sqlQueries);
  373. }
  374. $propertiesUpdated = true;
  375. }
  376. if (!$table->hasIndex('properties_pathonly_index')) {
  377. $output->writeln('<info>Adding properties_pathonly_index index to the oc_properties table, this can take some time...</info>');
  378. $table->addIndex(['propertypath'], 'properties_pathonly_index');
  379. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  380. if ($dryRun && $sqlQueries !== null) {
  381. $output->writeln($sqlQueries);
  382. }
  383. $propertiesUpdated = true;
  384. }
  385. if ($propertiesUpdated) {
  386. $updated = true;
  387. $output->writeln('<info>oc_properties table updated successfully.</info>');
  388. }
  389. }
  390. $output->writeln('<info>Check indices of the oc_jobs table.</info>');
  391. if ($schema->hasTable('jobs')) {
  392. $table = $schema->getTable('jobs');
  393. if (!$table->hasIndex('job_lastcheck_reserved')) {
  394. $output->writeln('<info>Adding job_lastcheck_reserved index to the oc_jobs table, this can take some time...</info>');
  395. $table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved');
  396. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  397. if ($dryRun && $sqlQueries !== null) {
  398. $output->writeln($sqlQueries);
  399. }
  400. $updated = true;
  401. $output->writeln('<info>oc_properties table updated successfully.</info>');
  402. }
  403. }
  404. $output->writeln('<info>Check indices of the oc_direct_edit table.</info>');
  405. if ($schema->hasTable('direct_edit')) {
  406. $table = $schema->getTable('direct_edit');
  407. if (!$table->hasIndex('direct_edit_timestamp')) {
  408. $output->writeln('<info>Adding direct_edit_timestamp index to the oc_direct_edit table, this can take some time...</info>');
  409. $table->addIndex(['timestamp'], 'direct_edit_timestamp');
  410. $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
  411. if ($dryRun && $sqlQueries !== null) {
  412. $output->writeln($sqlQueries);
  413. }
  414. $updated = true;
  415. $output->writeln('<info>oc_direct_edit table updated successfully.</info>');
  416. }
  417. }
  418. $output->writeln('<info>Check indices of the oc_preferences table.</info>');
  419. if ($schema->hasTable('preferences')) {
  420. $table = $schema->getTable('preferences');
  421. if (!$table->hasIndex('preferences_app_key')) {
  422. $output->writeln('<info>Adding preferences_app_key index to the oc_preferences table, this can take some time...</info>');
  423. $table->addIndex(['appid', 'configkey'], 'preferences_app_key');
  424. $this->connection->migrateToSchema($schema->getWrappedSchema());
  425. $updated = true;
  426. $output->writeln('<info>oc_properties table updated successfully.</info>');
  427. }
  428. }
  429. $output->writeln('<info>Check indices of the oc_mounts table.</info>');
  430. if ($schema->hasTable('mounts')) {
  431. $table = $schema->getTable('mounts');
  432. if (!$table->hasIndex('mounts_class_index')) {
  433. $output->writeln('<info>Adding mounts_class_index index to the oc_mounts table, this can take some time...</info>');
  434. $table->addIndex(['mount_provider_class'], 'mounts_class_index');
  435. $this->connection->migrateToSchema($schema->getWrappedSchema());
  436. $updated = true;
  437. $output->writeln('<info>oc_mounts table updated successfully.</info>');
  438. }
  439. if (!$table->hasIndex('mounts_user_root_path_index')) {
  440. $output->writeln('<info>Adding mounts_user_root_path_index index to the oc_mounts table, this can take some time...</info>');
  441. $table->addIndex(['user_id', 'root_id', 'mount_point'], 'mounts_user_root_path_index', [], ['lengths' => [null, null, 128]]);
  442. $this->connection->migrateToSchema($schema->getWrappedSchema());
  443. $updated = true;
  444. $output->writeln('<info>oc_mounts table updated successfully.</info>');
  445. }
  446. }
  447. $output->writeln('<info>Check indices of the oc_systemtag_object_mapping table.</info>');
  448. if ($schema->hasTable('systemtag_object_mapping')) {
  449. $table = $schema->getTable('systemtag_object_mapping');
  450. if (!$table->hasIndex('systag_by_tagid')) {
  451. $output->writeln('<info>Adding systag_by_tagid index to the oc_systemtag_object_mapping table, this can take some time...</info>');
  452. $table->addIndex(['systemtagid', 'objecttype'], 'systag_by_tagid');
  453. $this->connection->migrateToSchema($schema->getWrappedSchema());
  454. $updated = true;
  455. $output->writeln('<info>oc_systemtag_object_mapping table updated successfully.</info>');
  456. }
  457. }
  458. if (!$updated) {
  459. $output->writeln('<info>Done.</info>');
  460. }
  461. }
  462. }