2018-09-14 12:34:24 +02:00
|
|
|
<?php
|
2019-12-03 19:57:53 +01:00
|
|
|
|
2018-09-14 12:34:24 +02:00
|
|
|
declare(strict_types=1);
|
2019-12-03 19:57:53 +01:00
|
|
|
|
2018-09-14 12:34:24 +02:00
|
|
|
/**
|
2024-05-24 19:43:47 +02:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-09-14 12:34:24 +02:00
|
|
|
*/
|
|
|
|
namespace OC\Core\Migrations;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use OCP\DB\ISchemaWrapper;
|
2023-11-23 10:22:34 +01:00
|
|
|
use OCP\DB\Types;
|
2018-09-14 12:34:24 +02:00
|
|
|
use OCP\Migration\IOutput;
|
2019-11-22 20:52:10 +01:00
|
|
|
use OCP\Migration\SimpleMigrationStep;
|
2018-09-14 12:34:24 +02:00
|
|
|
|
2019-02-07 15:43:20 +01:00
|
|
|
class Version16000Date20190207141427 extends SimpleMigrationStep {
|
2018-09-14 12:34:24 +02:00
|
|
|
/**
|
|
|
|
* @param IOutput $output
|
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
|
|
|
|
* @param array $options
|
|
|
|
* @return null|ISchemaWrapper
|
|
|
|
*/
|
|
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
|
|
|
|
/** @var ISchemaWrapper $schema */
|
|
|
|
$schema = $schemaClosure();
|
|
|
|
|
|
|
|
if (!$schema->hasTable('collres_collections')) {
|
|
|
|
$table = $schema->createTable('collres_collections');
|
|
|
|
|
2020-06-30 22:12:06 +02:00
|
|
|
$table->addColumn('id', Types::BIGINT, [
|
2018-09-14 12:34:24 +02:00
|
|
|
'autoincrement' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
]);
|
2020-06-30 22:12:06 +02:00
|
|
|
$table->addColumn('name', Types::STRING, [
|
2018-10-24 14:25:35 +02:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 64,
|
|
|
|
]);
|
2018-09-14 12:34:24 +02:00
|
|
|
|
|
|
|
$table->setPrimaryKey(['id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$schema->hasTable('collres_resources')) {
|
|
|
|
$table = $schema->createTable('collres_resources');
|
|
|
|
|
2020-06-30 22:12:06 +02:00
|
|
|
$table->addColumn('collection_id', Types::BIGINT, [
|
2018-09-14 12:34:24 +02:00
|
|
|
'notnull' => true,
|
|
|
|
]);
|
2020-06-30 22:12:06 +02:00
|
|
|
$table->addColumn('resource_type', Types::STRING, [
|
2018-09-14 12:34:24 +02:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 64,
|
|
|
|
]);
|
2020-06-30 22:12:06 +02:00
|
|
|
$table->addColumn('resource_id', Types::STRING, [
|
2018-09-14 12:34:24 +02:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 64,
|
|
|
|
]);
|
|
|
|
|
2020-11-10 09:34:57 +01:00
|
|
|
$table->setPrimaryKey(['collection_id', 'resource_type', 'resource_id'], 'crr_pk');
|
2023-11-23 10:22:34 +01:00
|
|
|
// $table->addUniqueIndex(['collection_id', 'resource_type', 'resource_id'], 'collres_unique_res');
|
2018-09-14 12:34:24 +02:00
|
|
|
}
|
|
|
|
|
2019-02-07 15:43:20 +01:00
|
|
|
if (!$schema->hasTable('collres_accesscache')) {
|
|
|
|
$table = $schema->createTable('collres_accesscache');
|
|
|
|
|
2020-06-30 22:12:06 +02:00
|
|
|
$table->addColumn('user_id', Types::STRING, [
|
2019-02-07 15:43:20 +01:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 64,
|
|
|
|
]);
|
2020-06-30 22:12:06 +02:00
|
|
|
$table->addColumn('collection_id', Types::BIGINT, [
|
2019-02-07 15:43:20 +01:00
|
|
|
'notnull' => false,
|
2019-02-22 09:47:02 +01:00
|
|
|
'default' => 0,
|
2019-02-07 15:43:20 +01:00
|
|
|
]);
|
2020-06-30 22:12:06 +02:00
|
|
|
$table->addColumn('resource_type', Types::STRING, [
|
2019-02-22 11:37:04 +01:00
|
|
|
'notnull' => false,
|
|
|
|
'length' => 64,
|
|
|
|
'default' => '',
|
|
|
|
]);
|
2020-06-30 22:12:06 +02:00
|
|
|
$table->addColumn('resource_id', Types::STRING, [
|
2019-02-07 15:43:20 +01:00
|
|
|
'notnull' => false,
|
|
|
|
'length' => 64,
|
2019-02-22 09:47:02 +01:00
|
|
|
'default' => '',
|
2019-02-07 15:43:20 +01:00
|
|
|
]);
|
2020-06-30 22:12:06 +02:00
|
|
|
$table->addColumn('access', Types::SMALLINT, [
|
2020-11-09 10:38:47 +01:00
|
|
|
'notnull' => false,
|
2019-02-07 15:43:20 +01:00
|
|
|
'default' => 0,
|
|
|
|
]);
|
|
|
|
|
2020-11-10 09:34:57 +01:00
|
|
|
$table->setPrimaryKey(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'cra_pk');
|
2023-11-23 10:22:34 +01:00
|
|
|
// $table->addUniqueIndex(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'collres_unique_user');
|
2019-02-22 11:37:04 +01:00
|
|
|
$table->addIndex(['user_id', 'resource_type', 'resource_id'], 'collres_user_res');
|
2019-02-07 15:43:20 +01:00
|
|
|
$table->addIndex(['user_id', 'collection_id'], 'collres_user_coll');
|
|
|
|
}
|
|
|
|
|
2018-09-14 12:34:24 +02:00
|
|
|
return $schema;
|
|
|
|
}
|
|
|
|
}
|