Version1029Date20231004091403.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023 Richard Steinmetz <richard@steinmetz.cloud>
  5. *
  6. * @author Richard Steinmetz <richard@steinmetz.cloud>
  7. *
  8. * @license AGPL-3.0-or-later
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\Migration;
  25. use Closure;
  26. use OCP\DB\ISchemaWrapper;
  27. use OCP\DB\Types;
  28. use OCP\Migration\IOutput;
  29. use OCP\Migration\SimpleMigrationStep;
  30. class Version1029Date20231004091403 extends SimpleMigrationStep {
  31. /**
  32. * @param IOutput $output
  33. * @param Closure(): ISchemaWrapper $schemaClosure
  34. * @param array $options
  35. * @return null|ISchemaWrapper
  36. */
  37. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  38. /** @var ISchemaWrapper $schema */
  39. $schema = $schemaClosure();
  40. if (!$schema->hasTable('dav_absence')) {
  41. $table = $schema->createTable('dav_absence');
  42. $table->addColumn('id', Types::INTEGER, [
  43. 'autoincrement' => true,
  44. 'notnull' => true,
  45. 'length' => 4,
  46. ]);
  47. $table->addColumn('user_id', Types::STRING, [
  48. 'notnull' => true,
  49. 'length' => 64,
  50. ]);
  51. $table->addColumn('first_day', Types::STRING, [
  52. 'length' => 10,
  53. 'notnull' => true,
  54. ]);
  55. $table->addColumn('last_day', Types::STRING, [
  56. 'length' => 10,
  57. 'notnull' => true,
  58. ]);
  59. $table->addColumn('status', Types::STRING, [
  60. 'length' => 100,
  61. 'notnull' => true,
  62. ]);
  63. $table->addColumn('message', Types::TEXT, [
  64. 'notnull' => true,
  65. ]);
  66. $table->addUniqueIndex(['user_id'], 'dav_absence_uid_idx');
  67. } else {
  68. $table = $schema->getTable('dav_absence');
  69. }
  70. if ($table->getPrimaryKey() === null) {
  71. $table->setPrimaryKey(['id'], 'dav_absence_id_idx');
  72. }
  73. return $schema;
  74. }
  75. }