You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Version16000Date20190207141427.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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 OC\Core\Migrations;
  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 Version16000Date20190207141427 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('collres_collections')) {
  43. $table = $schema->createTable('collres_collections');
  44. $table->addColumn('id', Types::BIGINT, [
  45. 'autoincrement' => true,
  46. 'notnull' => true,
  47. ]);
  48. $table->addColumn('name', Types::STRING, [
  49. 'notnull' => true,
  50. 'length' => 64,
  51. ]);
  52. $table->setPrimaryKey(['id']);
  53. }
  54. if (!$schema->hasTable('collres_resources')) {
  55. $table = $schema->createTable('collres_resources');
  56. $table->addColumn('collection_id', Types::BIGINT, [
  57. 'notnull' => true,
  58. ]);
  59. $table->addColumn('resource_type', Types::STRING, [
  60. 'notnull' => true,
  61. 'length' => 64,
  62. ]);
  63. $table->addColumn('resource_id', Types::STRING, [
  64. 'notnull' => true,
  65. 'length' => 64,
  66. ]);
  67. $table->setPrimaryKey(['collection_id', 'resource_type', 'resource_id'], 'crr_pk');
  68. // $table->addUniqueIndex(['collection_id', 'resource_type', 'resource_id'], 'collres_unique_res');
  69. }
  70. if (!$schema->hasTable('collres_accesscache')) {
  71. $table = $schema->createTable('collres_accesscache');
  72. $table->addColumn('user_id', Types::STRING, [
  73. 'notnull' => true,
  74. 'length' => 64,
  75. ]);
  76. $table->addColumn('collection_id', Types::BIGINT, [
  77. 'notnull' => false,
  78. 'default' => 0,
  79. ]);
  80. $table->addColumn('resource_type', Types::STRING, [
  81. 'notnull' => false,
  82. 'length' => 64,
  83. 'default' => '',
  84. ]);
  85. $table->addColumn('resource_id', Types::STRING, [
  86. 'notnull' => false,
  87. 'length' => 64,
  88. 'default' => '',
  89. ]);
  90. $table->addColumn('access', Types::SMALLINT, [
  91. 'notnull' => false,
  92. 'default' => 0,
  93. ]);
  94. $table->setPrimaryKey(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'cra_pk');
  95. // $table->addUniqueIndex(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'collres_unique_user');
  96. $table->addIndex(['user_id', 'resource_type', 'resource_id'], 'collres_user_res');
  97. $table->addIndex(['user_id', 'collection_id'], 'collres_user_coll');
  98. }
  99. return $schema;
  100. }
  101. }