Version1011Date20190725113607.php 2.5 KB

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