2019-08-08 11:29:17 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\WorkflowEngine\Migration;
|
|
|
|
|
|
|
|
use Closure;
|
2019-08-27 18:51:10 +03:00
|
|
|
use Doctrine\DBAL\Schema\Table;
|
2019-08-08 11:29:17 +03:00
|
|
|
use Doctrine\DBAL\Types\Type;
|
|
|
|
use OCP\DB\ISchemaWrapper;
|
|
|
|
use OCP\Migration\IOutput;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Migration\SimpleMigrationStep;
|
2019-08-08 11:29:17 +03:00
|
|
|
|
2019-09-24 12:01:18 +03:00
|
|
|
class Version2000Date20190808074233 extends SimpleMigrationStep {
|
2019-08-08 11:29:17 +03: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('flow_checks')) {
|
|
|
|
$table = $schema->createTable('flow_checks');
|
|
|
|
$table->addColumn('id', Type::INTEGER, [
|
|
|
|
'autoincrement' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 4,
|
|
|
|
]);
|
|
|
|
$table->addColumn('class', Type::STRING, [
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 256,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => '',
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
|
|
|
$table->addColumn('operator', Type::STRING, [
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 16,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => '',
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
|
|
|
$table->addColumn('value', Type::TEXT, [
|
|
|
|
'notnull' => false,
|
|
|
|
]);
|
|
|
|
$table->addColumn('hash', Type::STRING, [
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 32,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => '',
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
|
|
|
$table->setPrimaryKey(['id']);
|
|
|
|
$table->addUniqueIndex(['hash'], 'flow_unique_hash');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$schema->hasTable('flow_operations')) {
|
|
|
|
$table = $schema->createTable('flow_operations');
|
|
|
|
$table->addColumn('id', Type::INTEGER, [
|
|
|
|
'autoincrement' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 4,
|
|
|
|
]);
|
|
|
|
$table->addColumn('class', Type::STRING, [
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 256,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => '',
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
|
|
|
$table->addColumn('name', Type::STRING, [
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 256,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => '',
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
|
|
|
$table->addColumn('checks', Type::TEXT, [
|
|
|
|
'notnull' => false,
|
|
|
|
]);
|
|
|
|
$table->addColumn('operation', Type::TEXT, [
|
|
|
|
'notnull' => false,
|
|
|
|
]);
|
2019-08-29 00:56:21 +03:00
|
|
|
$this->ensureEntityColumns($table);
|
2019-08-08 11:29:17 +03:00
|
|
|
$table->setPrimaryKey(['id']);
|
2019-08-27 18:51:10 +03:00
|
|
|
} else {
|
|
|
|
$table = $schema->getTable('flow_operations');
|
2019-08-29 00:56:21 +03:00
|
|
|
$this->ensureEntityColumns($table);
|
2019-08-08 11:29:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$schema->hasTable('flow_operations_scope')) {
|
|
|
|
$table = $schema->createTable('flow_operations_scope');
|
|
|
|
$table->addColumn('id', Type::BIGINT, [
|
|
|
|
'autoincrement' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 4,
|
|
|
|
]);
|
|
|
|
$table->addColumn('operation_id', Type::INTEGER, [
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 4,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => 0,
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
|
|
|
$table->addColumn('type', Type::INTEGER, [
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 4,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => 0,
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
|
|
|
$table->addColumn('value', Type::STRING, [
|
|
|
|
'notnull' => false,
|
|
|
|
'length' => 64,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => '',
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
|
|
|
$table->setPrimaryKey(['id']);
|
|
|
|
$table->addUniqueIndex(['operation_id', 'type', 'value'], 'flow_unique_scope');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $schema;
|
|
|
|
}
|
2019-08-27 18:51:10 +03:00
|
|
|
|
2019-08-29 00:56:21 +03:00
|
|
|
protected function ensureEntityColumns(Table $table) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if (!$table->hasColumn('entity')) {
|
2019-08-29 00:56:21 +03:00
|
|
|
$table->addColumn('entity', Type::STRING, [
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 256,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => '',
|
2019-08-29 00:56:21 +03:00
|
|
|
]);
|
|
|
|
}
|
2020-04-10 15:19:56 +03:00
|
|
|
if (!$table->hasColumn('events')) {
|
2019-08-29 00:56:21 +03:00
|
|
|
$table->addColumn('events', Type::TEXT, [
|
|
|
|
'notnull' => true,
|
|
|
|
'default' => '[]',
|
|
|
|
]);
|
|
|
|
}
|
2019-08-27 18:51:10 +03:00
|
|
|
}
|
2019-08-08 11:29:17 +03:00
|
|
|
}
|