From 9a6f7cc8cb5aef8d0c9dfb29fbed4a02e331e647 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon <blizzz@arthur-schiwon.de>
Date: Thu, 8 Aug 2019 10:29:17 +0200
Subject: [PATCH] add scope table for workflows and switch to migrations

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
---
 apps/workflowengine/appinfo/database.xml      |  90 ----------------
 .../composer/composer/autoload_classmap.php   |   1 +
 .../composer/composer/autoload_static.php     |   1 +
 .../Version2019Date20190808074233.php         | 100 ++++++++++++++++++
 4 files changed, 102 insertions(+), 90 deletions(-)
 delete mode 100644 apps/workflowengine/appinfo/database.xml
 create mode 100644 apps/workflowengine/lib/Migration/Version2019Date20190808074233.php

diff --git a/apps/workflowengine/appinfo/database.xml b/apps/workflowengine/appinfo/database.xml
deleted file mode 100644
index b67a41faed2..00000000000
--- a/apps/workflowengine/appinfo/database.xml
+++ /dev/null
@@ -1,90 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1" ?>
-<database>
-	<name>*dbname*</name>
-	<create>true</create>
-	<overwrite>false</overwrite>
-	<charset>utf8</charset>
-
-	<table>
-		<name>*dbprefix*flow_checks</name>
-		<declaration>
-			<field>
-				<name>id</name>
-				<type>integer</type>
-				<default>0</default>
-				<notnull>true</notnull>
-				<autoincrement>1</autoincrement>
-				<length>4</length>
-			</field>
-
-			<field>
-				<name>class</name>
-				<type>text</type>
-				<notnull>true</notnull>
-				<length>256</length>
-			</field>
-			<field>
-				<name>operator</name>
-				<type>text</type>
-				<notnull>true</notnull>
-				<length>16</length>
-			</field>
-			<field>
-				<name>value</name>
-				<type>clob</type>
-				<notnull>false</notnull>
-			</field>
-			<field>
-				<name>hash</name>
-				<type>text</type>
-				<notnull>true</notnull>
-				<length>32</length>
-			</field>
-
-			<index>
-				<name>flow_unique_hash</name>
-				<unique>true</unique>
-				<field>
-					<name>hash</name>
-				</field>
-			</index>
-		</declaration>
-	</table>
-
-	<table>
-		<name>*dbprefix*flow_operations</name>
-		<declaration>
-			<field>
-				<name>id</name>
-				<type>integer</type>
-				<default>0</default>
-				<notnull>true</notnull>
-				<autoincrement>1</autoincrement>
-				<length>4</length>
-			</field>
-
-			<field>
-				<name>class</name>
-				<type>text</type>
-				<notnull>true</notnull>
-				<length>256</length>
-			</field>
-			<field>
-				<name>name</name>
-				<type>text</type>
-				<notnull>true</notnull>
-				<length>256</length>
-			</field>
-			<field>
-				<name>checks</name>
-				<type>clob</type>
-				<notnull>false</notnull>
-			</field>
-			<field>
-				<name>operation</name>
-				<type>clob</type>
-				<notnull>false</notnull>
-			</field>
-		</declaration>
-	</table>
-</database>
diff --git a/apps/workflowengine/composer/composer/autoload_classmap.php b/apps/workflowengine/composer/composer/autoload_classmap.php
index 7d73b3a6241..14fca1fce4d 100644
--- a/apps/workflowengine/composer/composer/autoload_classmap.php
+++ b/apps/workflowengine/composer/composer/autoload_classmap.php
@@ -21,5 +21,6 @@ return array(
     'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => $baseDir . '/../lib/Controller/GlobalWorkflowsController.php',
     'OCA\\WorkflowEngine\\Controller\\RequestTime' => $baseDir . '/../lib/Controller/RequestTime.php',
     'OCA\\WorkflowEngine\\Manager' => $baseDir . '/../lib/Manager.php',
+    'OCA\\WorkflowEngine\\Migration\\Version2019Date20190808074233' => $baseDir . '/../lib/Migration/Version2019Date20190808074233.php',
     'OCA\\WorkflowEngine\\Settings\\Section' => $baseDir . '/../lib/Settings/Section.php',
 );
diff --git a/apps/workflowengine/composer/composer/autoload_static.php b/apps/workflowengine/composer/composer/autoload_static.php
index 8d54000260c..7af16f53701 100644
--- a/apps/workflowengine/composer/composer/autoload_static.php
+++ b/apps/workflowengine/composer/composer/autoload_static.php
@@ -36,6 +36,7 @@ class ComposerStaticInitWorkflowEngine
         'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => __DIR__ . '/..' . '/../lib/Controller/GlobalWorkflowsController.php',
         'OCA\\WorkflowEngine\\Controller\\RequestTime' => __DIR__ . '/..' . '/../lib/Controller/RequestTime.php',
         'OCA\\WorkflowEngine\\Manager' => __DIR__ . '/..' . '/../lib/Manager.php',
+        'OCA\\WorkflowEngine\\Migration\\Version2019Date20190808074233' => __DIR__ . '/..' . '/../lib/Migration/Version2019Date20190808074233.php',
         'OCA\\WorkflowEngine\\Settings\\Section' => __DIR__ . '/..' . '/../lib/Settings/Section.php',
     );
 
diff --git a/apps/workflowengine/lib/Migration/Version2019Date20190808074233.php b/apps/workflowengine/lib/Migration/Version2019Date20190808074233.php
new file mode 100644
index 00000000000..cedee43a9eb
--- /dev/null
+++ b/apps/workflowengine/lib/Migration/Version2019Date20190808074233.php
@@ -0,0 +1,100 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OCA\WorkflowEngine\Migration;
+
+use Closure;
+use Doctrine\DBAL\Types\Type;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\SimpleMigrationStep;
+use OCP\Migration\IOutput;
+
+class Version2019Date20190808074233 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) {
+		/** @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,
+			]);
+			$table->addColumn('operator', Type::STRING, [
+				'notnull' => true,
+				'length' => 16,
+			]);
+			$table->addColumn('value', Type::TEXT, [
+				'notnull' => false,
+			]);
+			$table->addColumn('hash', Type::STRING, [
+				'notnull' => true,
+				'length' => 32,
+			]);
+			$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,
+			]);
+			$table->addColumn('name', Type::STRING, [
+				'notnull' => true,
+				'length' => 256,
+			]);
+			$table->addColumn('checks', Type::TEXT, [
+				'notnull' => false,
+			]);
+			$table->addColumn('operation', Type::TEXT, [
+				'notnull' => false,
+			]);
+			$table->setPrimaryKey(['id']);
+		}
+
+		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,
+			]);
+			$table->addColumn('type', Type::INTEGER, [
+				'notnull' => true,
+				'length' => 4,
+			]);
+			$table->addColumn('value', Type::STRING, [
+				'notnull' => false,
+				'length' => 64,
+			]);
+			$table->setPrimaryKey(['id']);
+			$table->addUniqueIndex(['operation_id', 'type', 'value'], 'flow_unique_scope');
+		}
+
+		return $schema;
+	}
+}
-- 
GitLab