Version16000Date20190207141427.php 3.5 KB

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