Version1011Date20200630192246.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files_External\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. class Version1011Date20200630192246 extends SimpleMigrationStep {
  14. /**
  15. * @param IOutput $output
  16. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  17. * @param array $options
  18. * @return null|ISchemaWrapper
  19. */
  20. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
  21. /** @var ISchemaWrapper $schema */
  22. $schema = $schemaClosure();
  23. if (!$schema->hasTable('external_mounts')) {
  24. $table = $schema->createTable('external_mounts');
  25. $table->addColumn('mount_id', Types::BIGINT, [
  26. 'autoincrement' => true,
  27. 'notnull' => true,
  28. 'length' => 6,
  29. ]);
  30. $table->addColumn('mount_point', Types::STRING, [
  31. 'notnull' => true,
  32. 'length' => 128,
  33. ]);
  34. $table->addColumn('storage_backend', Types::STRING, [
  35. 'notnull' => true,
  36. 'length' => 64,
  37. ]);
  38. $table->addColumn('auth_backend', Types::STRING, [
  39. 'notnull' => true,
  40. 'length' => 64,
  41. ]);
  42. $table->addColumn('priority', Types::INTEGER, [
  43. 'notnull' => true,
  44. 'length' => 4,
  45. 'default' => 100,
  46. ]);
  47. $table->addColumn('type', Types::INTEGER, [
  48. 'notnull' => true,
  49. 'length' => 4,
  50. ]);
  51. $table->setPrimaryKey(['mount_id']);
  52. }
  53. if (!$schema->hasTable('external_applicable')) {
  54. $table = $schema->createTable('external_applicable');
  55. $table->addColumn('applicable_id', Types::BIGINT, [
  56. 'autoincrement' => true,
  57. 'notnull' => true,
  58. 'length' => 6,
  59. ]);
  60. $table->addColumn('mount_id', Types::BIGINT, [
  61. 'notnull' => true,
  62. 'length' => 6,
  63. ]);
  64. $table->addColumn('type', Types::INTEGER, [
  65. 'notnull' => true,
  66. 'length' => 4,
  67. ]);
  68. $table->addColumn('value', Types::STRING, [
  69. 'notnull' => false,
  70. 'length' => 64,
  71. ]);
  72. $table->setPrimaryKey(['applicable_id']);
  73. $table->addIndex(['mount_id'], 'applicable_mount');
  74. $table->addUniqueIndex(['type', 'value', 'mount_id'], 'applicable_type_value_mount');
  75. }
  76. if (!$schema->hasTable('external_config')) {
  77. $table = $schema->createTable('external_config');
  78. $table->addColumn('config_id', Types::BIGINT, [
  79. 'autoincrement' => true,
  80. 'notnull' => true,
  81. 'length' => 6,
  82. ]);
  83. $table->addColumn('mount_id', Types::BIGINT, [
  84. 'notnull' => true,
  85. 'length' => 6,
  86. ]);
  87. $table->addColumn('key', Types::STRING, [
  88. 'notnull' => true,
  89. 'length' => 64,
  90. ]);
  91. $table->addColumn('value', Types::STRING, [
  92. 'notnull' => false,
  93. 'length' => 4000,
  94. ]);
  95. $table->setPrimaryKey(['config_id']);
  96. $table->addUniqueIndex(['mount_id', 'key'], 'config_mount_key');
  97. } else {
  98. $table = $schema->getTable('external_config');
  99. $table->changeColumn('value', [
  100. 'notnull' => false,
  101. 'length' => 4000,
  102. ]);
  103. }
  104. if (!$schema->hasTable('external_options')) {
  105. $table = $schema->createTable('external_options');
  106. $table->addColumn('option_id', Types::BIGINT, [
  107. 'autoincrement' => true,
  108. 'notnull' => true,
  109. 'length' => 6,
  110. ]);
  111. $table->addColumn('mount_id', Types::BIGINT, [
  112. 'notnull' => true,
  113. 'length' => 6,
  114. ]);
  115. $table->addColumn('key', Types::STRING, [
  116. 'notnull' => true,
  117. 'length' => 64,
  118. ]);
  119. $table->addColumn('value', Types::STRING, [
  120. 'notnull' => true,
  121. 'length' => 256,
  122. ]);
  123. $table->setPrimaryKey(['option_id']);
  124. $table->addUniqueIndex(['mount_id', 'key'], 'option_mount_key');
  125. }
  126. return $schema;
  127. }
  128. }