Version28000Date20230616104802.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2023 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. /**
  14. * Introduce llm_tasks table
  15. */
  16. class Version28000Date20230616104802 extends SimpleMigrationStep {
  17. /**
  18. * @param IOutput $output
  19. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  20. * @param array $options
  21. * @return null|ISchemaWrapper
  22. */
  23. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  24. /** @var ISchemaWrapper $schema */
  25. $schema = $schemaClosure();
  26. if (!$schema->hasTable('llm_tasks')) {
  27. $table = $schema->createTable('llm_tasks');
  28. $table->addColumn('id', Types::BIGINT, [
  29. 'notnull' => true,
  30. 'length' => 64,
  31. 'autoincrement' => true,
  32. ]);
  33. $table->addColumn('type', Types::STRING, [
  34. 'notnull' => true,
  35. 'length' => 255,
  36. ]);
  37. $table->addColumn('input', Types::TEXT, [
  38. 'notnull' => true,
  39. ]);
  40. $table->addColumn('output', Types::TEXT, [
  41. 'notnull' => false,
  42. ]);
  43. $table->addColumn('status', Types::INTEGER, [
  44. 'notnull' => false,
  45. 'length' => 6,
  46. 'default' => 0,
  47. ]);
  48. $table->addColumn('user_id', Types::STRING, [
  49. 'notnull' => true,
  50. 'length' => 64,
  51. ]);
  52. $table->addColumn('app_id', Types::STRING, [
  53. 'notnull' => true,
  54. 'length' => 32,
  55. 'default' => '',
  56. ]);
  57. $table->addColumn('identifier', Types::STRING, [
  58. 'notnull' => true,
  59. 'length' => 255,
  60. 'default' => '',
  61. ]);
  62. $table->addColumn('last_updated', 'integer', [
  63. 'notnull' => false,
  64. 'length' => 4,
  65. 'default' => 0,
  66. 'unsigned' => true,
  67. ]);
  68. $table->setPrimaryKey(['id'], 'llm_tasks_id_index');
  69. $table->addUniqueIndex(['status', 'type'], 'llm_tasks_status_type');
  70. $table->addIndex(['last_updated'], 'llm_tasks_updated');
  71. return $schema;
  72. }
  73. return null;
  74. }
  75. }