Update schema to cope well with shared recipes

Signed-off-by: Christian Wolf <github@christianwolf.email>
This commit is contained in:
Christian Wolf 2021-07-01 11:47:04 +02:00
Родитель cc0908e75a
Коммит b85f4af5d8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 9FC3120E932F73F1
1 изменённых файлов: 43 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace OCA\Cookbook\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
/**
* Auto-generated migration step: Please modify to your needs!
*/
class Version000000Date20210701093123 extends SimpleMigrationStep {
/**
* @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): ?ISchemaWrapper {
/**
* @var ISchemaWrapper $schema
*/
$schema = $schemaClosure();
$namesTable = $schema->getTable('cookbook_names');
if ($namesTable->hasPrimaryKey()) {
$namesTable->dropPrimaryKey();
}
if (! $namesTable->hasIndex('names_recipe_idx')) {
$namesTable->addUniqueIndex([
'recipe_id',
'user_id'
], 'names_recipe_idx');
}
return $schema;
}
}