Version1011Date20190725113607.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Migration;
  8. use OCP\DB\ISchemaWrapper;
  9. use OCP\DB\Types;
  10. use OCP\Migration\IOutput;
  11. use OCP\Migration\SimpleMigrationStep;
  12. /**
  13. * Auto-generated migration step: Please modify to your needs!
  14. */
  15. class Version1011Date20190725113607 extends SimpleMigrationStep {
  16. /**
  17. * @param IOutput $output
  18. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  19. * @param array $options
  20. * @return null|ISchemaWrapper
  21. * @since 13.0.0
  22. */
  23. public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
  24. /** @var ISchemaWrapper $schema */
  25. $schema = $schemaClosure();
  26. $types = ['resource', 'room'];
  27. foreach ($types as $type) {
  28. if (!$schema->hasTable($this->getMetadataTableName($type))) {
  29. $table = $schema->createTable($this->getMetadataTableName($type));
  30. $table->addColumn('id', Types::BIGINT, [
  31. 'autoincrement' => true,
  32. 'notnull' => true,
  33. 'length' => 11,
  34. 'unsigned' => true,
  35. ]);
  36. $table->addColumn($type . '_id', Types::BIGINT, [
  37. 'notnull' => true,
  38. 'length' => 11,
  39. 'unsigned' => true,
  40. ]);
  41. $table->addColumn('key', Types::STRING, [
  42. 'notnull' => true,
  43. 'length' => 255,
  44. ]);
  45. $table->addColumn('value', Types::STRING, [
  46. 'notnull' => false,
  47. 'length' => 4000,
  48. ]);
  49. $table->setPrimaryKey(['id']);
  50. $table->addIndex([$type . '_id', 'key'], $this->getMetadataTableName($type) . '_idk');
  51. }
  52. }
  53. return $schema;
  54. }
  55. /**
  56. * @param string $type
  57. * @return string
  58. */
  59. private function getMetadataTableName(string $type):string {
  60. return 'calendar_' . $type . 's_md';
  61. }
  62. }