You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Version24000Date20211222112246.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\Migrations;
  8. use Closure;
  9. use OCP\DB\ISchemaWrapper;
  10. use OCP\DB\Types;
  11. use OCP\Migration\IOutput;
  12. use OCP\Migration\SimpleMigrationStep;
  13. class Version24000Date20211222112246 extends SimpleMigrationStep {
  14. private const TABLE_NAME = 'reactions';
  15. /**
  16. * @param IOutput $output
  17. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  18. * @param array $options
  19. * @return null|ISchemaWrapper
  20. */
  21. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  22. /** @var ISchemaWrapper $schema */
  23. $schema = $schemaClosure();
  24. $action = false;
  25. $comments = $schema->getTable('comments');
  26. if (!$comments->hasColumn('reactions')) {
  27. $comments->addColumn('reactions', Types::STRING, [
  28. 'notnull' => false,
  29. 'length' => 4000,
  30. ]);
  31. $action = true;
  32. }
  33. if (!$schema->hasTable(self::TABLE_NAME)) {
  34. $table = $schema->createTable(self::TABLE_NAME);
  35. $table->addColumn('id', Types::BIGINT, [
  36. 'autoincrement' => true,
  37. 'notnull' => true,
  38. 'length' => 11,
  39. 'unsigned' => true,
  40. ]);
  41. $table->addColumn('parent_id', Types::BIGINT, [
  42. 'notnull' => true,
  43. 'length' => 11,
  44. 'unsigned' => true,
  45. ]);
  46. $table->addColumn('message_id', Types::BIGINT, [
  47. 'notnull' => true,
  48. 'length' => 11,
  49. 'unsigned' => true,
  50. ]);
  51. $table->addColumn('actor_type', Types::STRING, [
  52. 'notnull' => true,
  53. 'length' => 64,
  54. 'default' => '',
  55. ]);
  56. $table->addColumn('actor_id', Types::STRING, [
  57. 'notnull' => true,
  58. 'length' => 64,
  59. 'default' => '',
  60. ]);
  61. $table->addColumn('reaction', Types::STRING, [
  62. 'notnull' => true,
  63. 'length' => 32,
  64. ]);
  65. $table->setPrimaryKey(['id']);
  66. $table->addIndex(['reaction'], 'comment_reaction');
  67. $table->addIndex(['parent_id'], 'comment_reaction_parent_id');
  68. $table->addUniqueIndex(['parent_id', 'actor_type', 'actor_id', 'reaction'], 'comment_reaction_unique');
  69. $action = true;
  70. }
  71. return $action ? $schema : null;
  72. }
  73. }