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;
|
2020-06-30 23:12:06 +03:00
|
|
|
use Doctrine\DBAL\Types\Types;
|
2019-08-08 11:29:17 +03:00
|
|
|
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');
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('id', Types::INTEGER, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'autoincrement' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 4,
|
|
|
|
]);
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('class', Types::STRING, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 256,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => '',
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('operator', Types::STRING, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 16,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => '',
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('value', Types::TEXT, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'notnull' => false,
|
|
|
|
]);
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('hash', Types::STRING, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'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');
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('id', Types::INTEGER, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'autoincrement' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 4,
|
|
|
|
]);
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('class', Types::STRING, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 256,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => '',
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('name', Types::STRING, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 256,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => '',
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('checks', Types::TEXT, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'notnull' => false,
|
|
|
|
]);
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('operation', Types::TEXT, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'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');
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('id', Types::BIGINT, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'autoincrement' => true,
|
|
|
|
'notnull' => true,
|
|
|
|
'length' => 4,
|
|
|
|
]);
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('operation_id', Types::INTEGER, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 4,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => 0,
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('type', Types::INTEGER, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'length' => 4,
|
2019-09-24 12:01:18 +03:00
|
|
|
'default' => 0,
|
2019-08-08 11:29:17 +03:00
|
|
|
]);
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('value', Types::STRING, [
|
2019-08-08 11:29:17 +03:00
|
|
|
'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')) {
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('entity', Types::STRING, [
|
2019-08-29 00:56:21 +03:00
|
|
|
'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')) {
|
2020-06-30 23:12:06 +03:00
|
|
|
$table->addColumn('events', Types::TEXT, [
|
2019-08-29 00:56:21 +03:00
|
|
|
'notnull' => true,
|
|
|
|
'default' => '[]',
|
|
|
|
]);
|
|
|
|
}
|
2019-08-27 18:51:10 +03:00
|
|
|
}
|
2019-08-08 11:29:17 +03:00
|
|
|
}
|