1
0

Version1011Date20200630192246.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Vincent Petry <vincent@nextcloud.com>
  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\Files_External\Migration;
  27. use Closure;
  28. use OCP\DB\Types;
  29. use OCP\DB\ISchemaWrapper;
  30. use OCP\Migration\IOutput;
  31. use OCP\Migration\SimpleMigrationStep;
  32. class Version1011Date20200630192246 extends SimpleMigrationStep {
  33. /**
  34. * @param IOutput $output
  35. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  36. * @param array $options
  37. * @return null|ISchemaWrapper
  38. */
  39. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
  40. /** @var ISchemaWrapper $schema */
  41. $schema = $schemaClosure();
  42. if (!$schema->hasTable('external_mounts')) {
  43. $table = $schema->createTable('external_mounts');
  44. $table->addColumn('mount_id', Types::BIGINT, [
  45. 'autoincrement' => true,
  46. 'notnull' => true,
  47. 'length' => 6,
  48. ]);
  49. $table->addColumn('mount_point', Types::STRING, [
  50. 'notnull' => true,
  51. 'length' => 128,
  52. ]);
  53. $table->addColumn('storage_backend', Types::STRING, [
  54. 'notnull' => true,
  55. 'length' => 64,
  56. ]);
  57. $table->addColumn('auth_backend', Types::STRING, [
  58. 'notnull' => true,
  59. 'length' => 64,
  60. ]);
  61. $table->addColumn('priority', Types::INTEGER, [
  62. 'notnull' => true,
  63. 'length' => 4,
  64. 'default' => 100,
  65. ]);
  66. $table->addColumn('type', Types::INTEGER, [
  67. 'notnull' => true,
  68. 'length' => 4,
  69. ]);
  70. $table->setPrimaryKey(['mount_id']);
  71. }
  72. if (!$schema->hasTable('external_applicable')) {
  73. $table = $schema->createTable('external_applicable');
  74. $table->addColumn('applicable_id', Types::BIGINT, [
  75. 'autoincrement' => true,
  76. 'notnull' => true,
  77. 'length' => 6,
  78. ]);
  79. $table->addColumn('mount_id', Types::BIGINT, [
  80. 'notnull' => true,
  81. 'length' => 6,
  82. ]);
  83. $table->addColumn('type', Types::INTEGER, [
  84. 'notnull' => true,
  85. 'length' => 4,
  86. ]);
  87. $table->addColumn('value', Types::STRING, [
  88. 'notnull' => false,
  89. 'length' => 64,
  90. ]);
  91. $table->setPrimaryKey(['applicable_id']);
  92. $table->addIndex(['mount_id'], 'applicable_mount');
  93. $table->addUniqueIndex(['type', 'value', 'mount_id'], 'applicable_type_value_mount');
  94. }
  95. if (!$schema->hasTable('external_config')) {
  96. $table = $schema->createTable('external_config');
  97. $table->addColumn('config_id', Types::BIGINT, [
  98. 'autoincrement' => true,
  99. 'notnull' => true,
  100. 'length' => 6,
  101. ]);
  102. $table->addColumn('mount_id', Types::BIGINT, [
  103. 'notnull' => true,
  104. 'length' => 6,
  105. ]);
  106. $table->addColumn('key', Types::STRING, [
  107. 'notnull' => true,
  108. 'length' => 64,
  109. ]);
  110. $table->addColumn('value', Types::STRING, [
  111. 'notnull' => false,
  112. 'length' => 4000,
  113. ]);
  114. $table->setPrimaryKey(['config_id']);
  115. $table->addUniqueIndex(['mount_id', 'key'], 'config_mount_key');
  116. } else {
  117. $table = $schema->getTable('external_config');
  118. $table->changeColumn('value', [
  119. 'notnull' => false,
  120. 'length' => 4000,
  121. ]);
  122. }
  123. if (!$schema->hasTable('external_options')) {
  124. $table = $schema->createTable('external_options');
  125. $table->addColumn('option_id', Types::BIGINT, [
  126. 'autoincrement' => true,
  127. 'notnull' => true,
  128. 'length' => 6,
  129. ]);
  130. $table->addColumn('mount_id', Types::BIGINT, [
  131. 'notnull' => true,
  132. 'length' => 6,
  133. ]);
  134. $table->addColumn('key', Types::STRING, [
  135. 'notnull' => true,
  136. 'length' => 64,
  137. ]);
  138. $table->addColumn('value', Types::STRING, [
  139. 'notnull' => true,
  140. 'length' => 256,
  141. ]);
  142. $table->setPrimaryKey(['option_id']);
  143. $table->addUniqueIndex(['mount_id', 'key'], 'option_mount_key');
  144. }
  145. return $schema;
  146. }
  147. }