aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration/src/main/java/org/sonar
diff options
context:
space:
mode:
authorEric Hartmann <hartmann.eric@gmail.com>2017-09-27 16:44:33 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-10-17 15:13:58 +0200
commit332cb13bb6a20434d358db772386a4e87200a9a4 (patch)
treec06b7a2a022667d50ca45e4c9209d86a04f478ac /server/sonar-db-migration/src/main/java/org/sonar
parent1613b1f008e306b4dd218b37e19685ec610c5db4 (diff)
downloadsonarqube-332cb13bb6a20434d358db772386a4e87200a9a4.tar.gz
sonarqube-332cb13bb6a20434d358db772386a4e87200a9a4.zip
SONAR-9880 Add ANALYSIS_UUID on WEBHOOK_DELIVERIES
Diffstat (limited to 'server/sonar-db-migration/src/main/java/org/sonar')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/PopulateAnalysisUuidColumnOnWebhookDeliveries.java56
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/UpdateCeTaskUuidColumnToNullableOnWebhookDeliveries.java47
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/AddAnalysisUuidToWebhookDeliveries.java49
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java2
4 files changed, 153 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/PopulateAnalysisUuidColumnOnWebhookDeliveries.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/PopulateAnalysisUuidColumnOnWebhookDeliveries.java
new file mode 100644
index 00000000000..05b4bd7f1bf
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/PopulateAnalysisUuidColumnOnWebhookDeliveries.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v66;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+import org.sonar.server.platform.db.migration.step.Select;
+import org.sonar.server.platform.db.migration.step.SqlStatement;
+
+public class PopulateAnalysisUuidColumnOnWebhookDeliveries extends DataChange {
+
+ public PopulateAnalysisUuidColumnOnWebhookDeliveries(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select("SELECT wd.uuid, ca.analysis_uuid " +
+ " FROM webhook_deliveries wd " +
+ " INNER JOIN ce_activity ca ON ca.uuid=wd.ce_task_uuid " +
+ " WHERE wd.analysis_uuid IS NULL AND ca.analysis_uuid IS NOT NULL");
+ massUpdate.update("UPDATE webhook_deliveries SET analysis_uuid=? WHERE uuid=?");
+ massUpdate.rowPluralName("webhook_deliveries");
+ massUpdate.execute(PopulateAnalysisUuidColumnOnWebhookDeliveries::handle);
+ }
+
+ private static boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+ String uuid = row.getString(1);
+ String analysisUuid = row.getString(2);
+
+ update.setString(1, analysisUuid);
+ update.setString(2, uuid);
+
+ return true;
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/UpdateCeTaskUuidColumnToNullableOnWebhookDeliveries.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/UpdateCeTaskUuidColumnToNullableOnWebhookDeliveries.java
new file mode 100644
index 00000000000..236b3cb61be
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/UpdateCeTaskUuidColumnToNullableOnWebhookDeliveries.java
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.platform.db.migration.version.v66;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class UpdateCeTaskUuidColumnToNullableOnWebhookDeliveries extends DdlChange {
+
+ public static final String TABLE_WEBHOOK_DELIVERIES = "webhook_deliveries";
+
+ public UpdateCeTaskUuidColumnToNullableOnWebhookDeliveries(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE_WEBHOOK_DELIVERIES)
+ .updateColumn(VarcharColumnDef.newVarcharColumnDefBuilder()
+ .setColumnName("ce_task_uuid")
+ .setLimit(40)
+ .setIsNullable(true)
+ .build())
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/AddAnalysisUuidToWebhookDeliveries.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/AddAnalysisUuidToWebhookDeliveries.java
new file mode 100644
index 00000000000..058adf56345
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/AddAnalysisUuidToWebhookDeliveries.java
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.platform.db.migration.version.v67;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class AddAnalysisUuidToWebhookDeliveries extends DdlChange {
+
+ public static final String TABLE = "webhook_deliveries";
+
+ public static final VarcharColumnDef ANALYSIS_UUID_COLUMN = VarcharColumnDef.newVarcharColumnDefBuilder()
+ .setColumnName("analysis_uuid")
+ .setLimit(40)
+ .setIsNullable(true)
+ .build();
+
+ public AddAnalysisUuidToWebhookDeliveries(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(ANALYSIS_UUID_COLUMN)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java
index b02a6065997..e5b479e4d1d 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java
@@ -27,6 +27,6 @@ public class DbVersion67 implements DbVersion {
public void addSteps(MigrationStepRegistry registry) {
registry
.add(1830, "Copy deprecated server ID", CopyDeprecatedServerId.class)
- ;
+ .add(1831, "Add webhook_deliveries.analysis_uuid", AddAnalysisUuidToWebhookDeliveries.class);
}
}