Version1020Date20221114144058.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files_Versions\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. /**
  14. * Auto-generated migration step: Please modify to your needs!
  15. */
  16. class Version1020Date20221114144058 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("files_versions")) {
  27. return null;
  28. }
  29. $table = $schema->createTable("files_versions");
  30. $table->addColumn('id', Types::BIGINT, [
  31. 'autoincrement' => true,
  32. 'notnull' => true,
  33. 'length' => 20,
  34. ]);
  35. $table->addColumn('file_id', Types::BIGINT, [
  36. 'notnull' => true,
  37. 'length' => 20,
  38. ]);
  39. $table->addColumn('timestamp', Types::BIGINT, [
  40. 'notnull' => true,
  41. 'length' => 20,
  42. ]);
  43. $table->addColumn('size', Types::BIGINT, [
  44. 'notnull' => true,
  45. 'length' => 20,
  46. ]);
  47. $table->addColumn('mimetype', Types::BIGINT, [
  48. 'notnull' => true,
  49. 'length' => 20,
  50. ]);
  51. $table->addColumn('metadata', Types::JSON, [
  52. 'notnull' => true,
  53. ]);
  54. $table->setPrimaryKey(['id']);
  55. $table->addUniqueIndex(['file_id', 'timestamp'], 'files_versions_uniq_index');
  56. return $schema;
  57. }
  58. }