Version16000Date20190207141427.php 3.1 KB

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