From 56a402e9bc4d866954e8e2bd20300fd750016cbf Mon Sep 17 00:00:00 2001
From: kfilippopolitis <kostasfilippop@gmail.com>
Date: Fri, 11 Jun 2021 03:20:12 -0700
Subject: [PATCH 1/3] Small fix in migration script

---
 src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql b/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql
index 6f0380aee..81b7fbcc6 100644
--- a/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql
+++ b/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql
@@ -23,8 +23,8 @@ DROP COLUMN model_slug;
 
 ALTER TABLE experiment RENAME algorithms TO algorithm;
 UPDATE experiment SET algorithm = (algorithm::json ->> 0);
-UPDATE experiment SET algorithmId = (algorithm::json ->> 'name');
 ALTER TABLE experiment ADD COLUMN algorithmId text;
+UPDATE experiment SET algorithmId = (algorithm::json ->> 'name');
 UPDATE experiment SET result = result::json #>>'{0,result}' WHERE (algorithm::json->>'type') <> 'workflow';
 
 ALTER TABLE experiment
-- 
GitLab


From a5613d1c74f7f840833c7d9f6f54783ae779c002 Mon Sep 17 00:00:00 2001
From: kfilippopolitis <kostasfilippop@gmail.com>
Date: Fri, 11 Jun 2021 04:28:13 -0700
Subject: [PATCH 2/3] Reverting back changes to 7_0 migration script.Adding the
 new changes to a new 7_1 migration script.

---
 .../migration/V7_0__NewDatabaseStructure.sql  | 33 ++++++++++++-------
 .../V7_1__NewExperimentResultFormat.sql       |  1 +
 2 files changed, 23 insertions(+), 11 deletions(-)
 create mode 100644 src/main/resources/db/migration/V7_1__NewExperimentResultFormat.sql

diff --git a/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql b/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql
index 81b7fbcc6..a3f5866f6 100644
--- a/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql
+++ b/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql
@@ -1,3 +1,8 @@
+UPDATE experiment
+SET algorithms =
+        (
+            SELECT SUBSTR(algorithms, 2, LENGTH(algorithms) - 2)
+        );
 
 UPDATE experiment
 SET workflowstatus = 'error'
@@ -21,21 +26,27 @@ DROP COLUMN hasservererror,
 DROP COLUMN validations,
 DROP COLUMN model_slug;
 
-ALTER TABLE experiment RENAME algorithms TO algorithm;
-UPDATE experiment SET algorithm = (algorithm::json ->> 0);
-ALTER TABLE experiment ADD COLUMN algorithmId text;
-UPDATE experiment SET algorithmId = (algorithm::json ->> 'name');
-UPDATE experiment SET result = result::json #>>'{0,result}' WHERE (algorithm::json->>'type') <> 'workflow';
-
 ALTER TABLE experiment
-RENAME createdby_username TO created_by_username;
+    RENAME algorithms TO algorithm;
+ALTER TABLE experiment
+ALTER COLUMN algorithm TYPE json USING algorithm::json;
 ALTER TABLE experiment
-RENAME workflowhistoryid TO workflow_history_id;
+    RENAME createdby_username TO created_by_username;
 ALTER TABLE experiment
-RENAME resultsviewed TO viewed;
+    RENAME workflowhistoryid TO workflow_history_id;
 ALTER TABLE experiment
-RENAME workflowstatus TO status;
+    RENAME resultsviewed TO viewed;
+ALTER TABLE experiment
+    RENAME workflowstatus TO status;
 
+ALTER TABLE experiment
+    ADD COLUMN algorithmId text;
+
+UPDATE experiment
+SET algorithmId = (algorithm ->> 'name');
+
+ALTER TABLE experiment
+ALTER COLUMN algorithm TYPE text;
 ALTER TABLE experiment
 ADD COLUMN updated timestamp without time zone;
 
@@ -70,4 +81,4 @@ DROP TABLE "query";
 DROP TABLE "dataset";
 DROP TABLE "config";
 DROP TABLE "vote", "app";
-DROP TABLE "user_roles", "user_languages";
+DROP TABLE "user_roles", "user_languages";
\ No newline at end of file
diff --git a/src/main/resources/db/migration/V7_1__NewExperimentResultFormat.sql b/src/main/resources/db/migration/V7_1__NewExperimentResultFormat.sql
new file mode 100644
index 000000000..d124f9458
--- /dev/null
+++ b/src/main/resources/db/migration/V7_1__NewExperimentResultFormat.sql
@@ -0,0 +1 @@
+UPDATE experiment SET result = result::json #>>'{0,result}' WHERE (algorithm::json->>'type') <> 'workflow';
\ No newline at end of file
-- 
GitLab


From 3822e50d14de7a86a728b1d979f54cb78a1bb85a Mon Sep 17 00:00:00 2001
From: kfilippopolitis <kostasfilippop@gmail.com>
Date: Fri, 11 Jun 2021 04:30:44 -0700
Subject: [PATCH 3/3] Removing tabs

---
 .../migration/V7_0__NewDatabaseStructure.sql   | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql b/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql
index a3f5866f6..6a3beee93 100644
--- a/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql
+++ b/src/main/resources/db/migration/V7_0__NewDatabaseStructure.sql
@@ -1,8 +1,8 @@
 UPDATE experiment
 SET algorithms =
-        (
-            SELECT SUBSTR(algorithms, 2, LENGTH(algorithms) - 2)
-        );
+    (
+        SELECT SUBSTR(algorithms, 2, LENGTH(algorithms) - 2)
+    );
 
 UPDATE experiment
 SET workflowstatus = 'error'
@@ -27,20 +27,20 @@ DROP COLUMN validations,
 DROP COLUMN model_slug;
 
 ALTER TABLE experiment
-    RENAME algorithms TO algorithm;
+RENAME algorithms TO algorithm;
 ALTER TABLE experiment
 ALTER COLUMN algorithm TYPE json USING algorithm::json;
 ALTER TABLE experiment
-    RENAME createdby_username TO created_by_username;
+RENAME createdby_username TO created_by_username;
 ALTER TABLE experiment
-    RENAME workflowhistoryid TO workflow_history_id;
+RENAME workflowhistoryid TO workflow_history_id;
 ALTER TABLE experiment
-    RENAME resultsviewed TO viewed;
+RENAME resultsviewed TO viewed;
 ALTER TABLE experiment
-    RENAME workflowstatus TO status;
+RENAME workflowstatus TO status;
 
 ALTER TABLE experiment
-    ADD COLUMN algorithmId text;
+ADD COLUMN algorithmId text;
 
 UPDATE experiment
 SET algorithmId = (algorithm ->> 'name');
-- 
GitLab