Version1029Date20231004091403.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 OCA\DAV\Migration;
  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 Version1029Date20231004091403 extends SimpleMigrationStep {
  14. /**
  15. * @param IOutput $output
  16. * @param Closure(): ISchemaWrapper $schemaClosure
  17. * @param array $options
  18. * @return null|ISchemaWrapper
  19. */
  20. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  21. /** @var ISchemaWrapper $schema */
  22. $schema = $schemaClosure();
  23. if (!$schema->hasTable('dav_absence')) {
  24. $table = $schema->createTable('dav_absence');
  25. $table->addColumn('id', Types::INTEGER, [
  26. 'autoincrement' => true,
  27. 'notnull' => true,
  28. 'length' => 4,
  29. ]);
  30. $table->addColumn('user_id', Types::STRING, [
  31. 'notnull' => true,
  32. 'length' => 64,
  33. ]);
  34. $table->addColumn('first_day', Types::STRING, [
  35. 'length' => 10,
  36. 'notnull' => true,
  37. ]);
  38. $table->addColumn('last_day', Types::STRING, [
  39. 'length' => 10,
  40. 'notnull' => true,
  41. ]);
  42. $table->addColumn('status', Types::STRING, [
  43. 'length' => 100,
  44. 'notnull' => true,
  45. ]);
  46. $table->addColumn('message', Types::TEXT, [
  47. 'notnull' => true,
  48. ]);
  49. $table->addUniqueIndex(['user_id'], 'dav_absence_uid_idx');
  50. } else {
  51. $table = $schema->getTable('dav_absence');
  52. }
  53. if ($table->getPrimaryKey() === null) {
  54. $table->setPrimaryKey(['id'], 'dav_absence_id_idx');
  55. }
  56. return $schema;
  57. }
  58. }