Version10000Date20230725162149.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\FilesReminders\Migration;
  8. use Closure;
  9. use OCA\FilesReminders\Db\ReminderMapper;
  10. use OCP\DB\ISchemaWrapper;
  11. use OCP\DB\Types;
  12. use OCP\Migration\IOutput;
  13. use OCP\Migration\SimpleMigrationStep;
  14. class Version10000Date20230725162149 extends SimpleMigrationStep {
  15. /**
  16. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  17. */
  18. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
  19. /** @var ISchemaWrapper $schema */
  20. $schema = $schemaClosure();
  21. if ($schema->hasTable(ReminderMapper::TABLE_NAME)) {
  22. return null;
  23. }
  24. $table = $schema->createTable(ReminderMapper::TABLE_NAME);
  25. $table->addColumn('id', Types::BIGINT, [
  26. 'autoincrement' => true,
  27. 'notnull' => true,
  28. 'length' => 20,
  29. 'unsigned' => true,
  30. ]);
  31. $table->addColumn('user_id', Types::STRING, [
  32. 'notnull' => true,
  33. 'length' => 64,
  34. ]);
  35. $table->addColumn('file_id', Types::BIGINT, [
  36. 'notnull' => true,
  37. 'length' => 20,
  38. 'unsigned' => true,
  39. ]);
  40. $table->addColumn('due_date', Types::DATETIME, [
  41. 'notnull' => true,
  42. ]);
  43. $table->addColumn('updated_at', Types::DATETIME, [
  44. 'notnull' => true,
  45. ]);
  46. $table->addColumn('created_at', Types::DATETIME, [
  47. 'notnull' => true,
  48. ]);
  49. $table->addColumn('notified', Types::BOOLEAN, [
  50. 'notnull' => false,
  51. 'default' => false,
  52. ]);
  53. $table->setPrimaryKey(['id']);
  54. $table->addUniqueIndex(['user_id', 'file_id', 'due_date'], 'reminders_uniq_idx');
  55. return $schema;
  56. }
  57. }