1
0

Version1011Date20190725113607.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016 Georg Ehrke <oc.list@georgehrke.com>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  8. * @author Georg Ehrke <oc.list@georgehrke.com>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\DAV\Migration;
  28. use OCP\DB\ISchemaWrapper;
  29. use OCP\DB\Types;
  30. use OCP\Migration\IOutput;
  31. use OCP\Migration\SimpleMigrationStep;
  32. /**
  33. * Auto-generated migration step: Please modify to your needs!
  34. */
  35. class Version1011Date20190725113607 extends SimpleMigrationStep {
  36. /**
  37. * @param IOutput $output
  38. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  39. * @param array $options
  40. * @return null|ISchemaWrapper
  41. * @since 13.0.0
  42. */
  43. public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
  44. /** @var ISchemaWrapper $schema */
  45. $schema = $schemaClosure();
  46. $types = ['resource', 'room'];
  47. foreach ($types as $type) {
  48. if (!$schema->hasTable($this->getMetadataTableName($type))) {
  49. $table = $schema->createTable($this->getMetadataTableName($type));
  50. $table->addColumn('id', Types::BIGINT, [
  51. 'autoincrement' => true,
  52. 'notnull' => true,
  53. 'length' => 11,
  54. 'unsigned' => true,
  55. ]);
  56. $table->addColumn($type . '_id', Types::BIGINT, [
  57. 'notnull' => true,
  58. 'length' => 11,
  59. 'unsigned' => true,
  60. ]);
  61. $table->addColumn('key', Types::STRING, [
  62. 'notnull' => true,
  63. 'length' => 255,
  64. ]);
  65. $table->addColumn('value', Types::STRING, [
  66. 'notnull' => false,
  67. 'length' => 4000,
  68. ]);
  69. $table->setPrimaryKey(['id']);
  70. $table->addIndex([$type . '_id', 'key'], $this->getMetadataTableName($type) . '_idk');
  71. }
  72. }
  73. return $schema;
  74. }
  75. /**
  76. * @param string $type
  77. * @return string
  78. */
  79. private function getMetadataTableName(string $type):string {
  80. return 'calendar_' . $type . 's_md';
  81. }
  82. }