Version30000Date20240429122720.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2024 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\Attributes\AddIndex;
  12. use OCP\Migration\Attributes\CreateTable;
  13. use OCP\Migration\Attributes\IndexType;
  14. use OCP\Migration\IOutput;
  15. use OCP\Migration\SimpleMigrationStep;
  16. /**
  17. *
  18. */
  19. #[CreateTable(table: 'taskprocessing_tasks')]
  20. #[AddIndex(table: 'taskprocessing_tasks', type: IndexType::PRIMARY)]
  21. #[AddIndex(table: 'taskprocessing_tasks', type: IndexType::INDEX)]
  22. #[AddIndex(table: 'taskprocessing_tasks', type: IndexType::INDEX)]
  23. #[AddIndex(table: 'taskprocessing_tasks', type: IndexType::INDEX)]
  24. class Version30000Date20240429122720 extends SimpleMigrationStep {
  25. /**
  26. * @param IOutput $output
  27. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  28. * @param array $options
  29. * @return null|ISchemaWrapper
  30. */
  31. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  32. /** @var ISchemaWrapper $schema */
  33. $schema = $schemaClosure();
  34. if (!$schema->hasTable('taskprocessing_tasks')) {
  35. $table = $schema->createTable('taskprocessing_tasks');
  36. $table->addColumn('id', Types::BIGINT, [
  37. 'notnull' => true,
  38. 'length' => 64,
  39. 'autoincrement' => true,
  40. ]);
  41. $table->addColumn('type', Types::STRING, [
  42. 'notnull' => true,
  43. 'length' => 255,
  44. ]);
  45. $table->addColumn('input', Types::TEXT, [
  46. 'notnull' => true,
  47. ]);
  48. $table->addColumn('output', Types::TEXT, [
  49. 'notnull' => false,
  50. ]);
  51. $table->addColumn('status', Types::INTEGER, [
  52. 'notnull' => false,
  53. 'length' => 6,
  54. 'default' => 0,
  55. ]);
  56. $table->addColumn('user_id', Types::STRING, [
  57. 'notnull' => false,
  58. 'length' => 64,
  59. ]);
  60. $table->addColumn('app_id', Types::STRING, [
  61. 'notnull' => true,
  62. 'length' => 32,
  63. 'default' => '',
  64. ]);
  65. $table->addColumn('custom_id', Types::STRING, [
  66. 'notnull' => false,
  67. 'length' => 255,
  68. 'default' => '',
  69. ]);
  70. $table->addColumn('last_updated', Types::INTEGER, [
  71. 'notnull' => false,
  72. 'length' => 4,
  73. 'default' => 0,
  74. 'unsigned' => true,
  75. ]);
  76. $table->addColumn('completion_expected_at', Types::DATETIME, [
  77. 'notnull' => false,
  78. ]);
  79. $table->addColumn('progress', Types::FLOAT, [
  80. 'notnull' => false,
  81. 'default' => 0,
  82. ]);
  83. $table->addColumn('error_message', Types::STRING, [
  84. 'notnull' => false,
  85. 'length' => 255,
  86. ]);
  87. $table->setPrimaryKey(['id'], 'taskp_tasks_id_index');
  88. $table->addIndex(['status', 'type'], 'taskp_tasks_status_type');
  89. $table->addIndex(['last_updated'], 'taskp_tasks_updated');
  90. $table->addIndex(['user_id', 'app_id', 'custom_id'], 'taskp_tasks_uid_appid_cid');
  91. return $schema;
  92. }
  93. return null;
  94. }
  95. }