Version16000Date20190207141427.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\Core\Migrations;
  26. use Closure;
  27. use Doctrine\DBAL\Types\Types;
  28. use OCP\DB\ISchemaWrapper;
  29. use OCP\Migration\IOutput;
  30. use OCP\Migration\SimpleMigrationStep;
  31. class Version16000Date20190207141427 extends SimpleMigrationStep {
  32. /**
  33. * @param IOutput $output
  34. * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  35. * @param array $options
  36. * @return null|ISchemaWrapper
  37. */
  38. public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
  39. /** @var ISchemaWrapper $schema */
  40. $schema = $schemaClosure();
  41. if (!$schema->hasTable('collres_collections')) {
  42. $table = $schema->createTable('collres_collections');
  43. $table->addColumn('id', Types::BIGINT, [
  44. 'autoincrement' => true,
  45. 'notnull' => true,
  46. ]);
  47. $table->addColumn('name', Types::STRING, [
  48. 'notnull' => true,
  49. 'length' => 64,
  50. ]);
  51. $table->setPrimaryKey(['id']);
  52. }
  53. if (!$schema->hasTable('collres_resources')) {
  54. $table = $schema->createTable('collres_resources');
  55. $table->addColumn('collection_id', Types::BIGINT, [
  56. 'notnull' => true,
  57. ]);
  58. $table->addColumn('resource_type', Types::STRING, [
  59. 'notnull' => true,
  60. 'length' => 64,
  61. ]);
  62. $table->addColumn('resource_id', Types::STRING, [
  63. 'notnull' => true,
  64. 'length' => 64,
  65. ]);
  66. $table->addUniqueIndex(['collection_id', 'resource_type', 'resource_id'], 'collres_unique_res');
  67. }
  68. if (!$schema->hasTable('collres_accesscache')) {
  69. $table = $schema->createTable('collres_accesscache');
  70. $table->addColumn('user_id', Types::STRING, [
  71. 'notnull' => true,
  72. 'length' => 64,
  73. ]);
  74. $table->addColumn('collection_id', Types::BIGINT, [
  75. 'notnull' => false,
  76. 'default' => 0,
  77. ]);
  78. $table->addColumn('resource_type', Types::STRING, [
  79. 'notnull' => false,
  80. 'length' => 64,
  81. 'default' => '',
  82. ]);
  83. $table->addColumn('resource_id', Types::STRING, [
  84. 'notnull' => false,
  85. 'length' => 64,
  86. 'default' => '',
  87. ]);
  88. $table->addColumn('access', Types::SMALLINT, [
  89. 'notnull' => true,
  90. 'default' => 0,
  91. ]);
  92. $table->addUniqueIndex(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'collres_unique_user');
  93. $table->addIndex(['user_id', 'resource_type', 'resource_id'], 'collres_user_res');
  94. $table->addIndex(['user_id', 'collection_id'], 'collres_user_coll');
  95. }
  96. return $schema;
  97. }
  98. }