aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-11-09 23:55:41 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-11-14 12:18:50 +0100
commit6c69f5bcce1a3ad34924fb73400e9a8ee1449257 (patch)
treee87895cdef71c7848da9ef4de0989a0b1fa111ec /sonar-db
parent901b8810a4d2c237395eced14e467be415218249 (diff)
downloadsonarqube-6c69f5bcce1a3ad34924fb73400e9a8ee1449257.tar.gz
sonarqube-6c69f5bcce1a3ad34924fb73400e9a8ee1449257.zip
SONAR-8353 create table webhook_deliveries
Diffstat (limited to 'sonar-db')
-rw-r--r--sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java5
-rw-r--r--sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java4
-rw-r--r--sonar-db/src/main/java/org/sonar/db/version/v62/CreateTableWebhookDeliveries.java56
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql1
-rw-r--r--sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl18
-rw-r--r--sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java2
-rw-r--r--sonar-db/src/test/java/org/sonar/db/version/v62/CreateTableWebhookDeliveriesTest.java74
-rw-r--r--sonar-db/src/test/resources/org/sonar/db/version/v62/CreateTableWebhookDeliveriesTest/empty.sql0
8 files changed, 156 insertions, 4 deletions
diff --git a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
index 69753022cf2..2f6edd2493a 100644
--- a/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
+++ b/sonar-db/src/main/java/org/sonar/db/version/DatabaseVersion.java
@@ -30,7 +30,7 @@ import org.sonar.db.MyBatis;
public class DatabaseVersion {
- public static final int LAST_VERSION = 1_422;
+ public static final int LAST_VERSION = 1_423;
/**
* The minimum supported version which can be upgraded. Lower
@@ -105,7 +105,8 @@ public class DatabaseVersion {
"snapshots",
"users",
"user_roles",
- "user_tokens");
+ "user_tokens",
+ "webhook_deliveries");
private MyBatis mybatis;
diff --git a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
index 4742c008b43..568bbf1e78c 100644
--- a/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
+++ b/sonar-db/src/main/java/org/sonar/db/version/MigrationStepModule.java
@@ -166,6 +166,7 @@ import org.sonar.db.version.v62.AddOrganizationUuidToPermissionTemplates;
import org.sonar.db.version.v62.AddOrganizationUuidToUserRoles;
import org.sonar.db.version.v62.CreateDefaultOrganization;
import org.sonar.db.version.v62.CreateTableOrganizations;
+import org.sonar.db.version.v62.CreateTableWebhookDeliveries;
import org.sonar.db.version.v62.DeletePermissionShareDashboard;
import org.sonar.db.version.v62.DropIssueFiltersTables;
import org.sonar.db.version.v62.DropMeasureFiltersTables;
@@ -382,6 +383,7 @@ public class MigrationStepModule extends Module {
UpdateQualityGateConditionsOnCoverage.class,
DropRelatedDashboardTables.class,
DropMeasureFiltersTables.class,
- DropIssueFiltersTables.class);
+ DropIssueFiltersTables.class,
+ CreateTableWebhookDeliveries.class);
}
}
diff --git a/sonar-db/src/main/java/org/sonar/db/version/v62/CreateTableWebhookDeliveries.java b/sonar-db/src/main/java/org/sonar/db/version/v62/CreateTableWebhookDeliveries.java
new file mode 100644
index 00000000000..5e241a733f4
--- /dev/null
+++ b/sonar-db/src/main/java/org/sonar/db/version/v62/CreateTableWebhookDeliveries.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.version.v62;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.version.CreateTableBuilder;
+import org.sonar.db.version.DdlChange;
+
+import static org.sonar.db.version.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
+import static org.sonar.db.version.BooleanColumnDef.newBooleanColumnDefBuilder;
+import static org.sonar.db.version.ClobColumnDef.newClobColumnDefBuilder;
+import static org.sonar.db.version.IntegerColumnDef.newIntegerColumnDefBuilder;
+import static org.sonar.db.version.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CreateTableWebhookDeliveries extends DdlChange {
+ public CreateTableWebhookDeliveries(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(
+ new CreateTableBuilder(getDialect(), "webhook_deliveries")
+ .addPkColumn(newVarcharColumnDefBuilder().setColumnName("uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("component_uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("ce_task_uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("name").setLimit(100).setIsNullable(false).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("url").setLimit(2000).setIsNullable(false).build())
+ .addColumn(newBooleanColumnDefBuilder().setColumnName("success").setIsNullable(false).build())
+ .addColumn(newIntegerColumnDefBuilder().setColumnName("http_status").setIsNullable(true).build())
+ .addColumn(newIntegerColumnDefBuilder().setColumnName("duration_ms").setIsNullable(true).build())
+ .addColumn(newClobColumnDefBuilder().setColumnName("payload").setIsNullable(false).build())
+ .addColumn(newClobColumnDefBuilder().setColumnName("error_stacktrace").setIsNullable(true).build())
+ .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
+ .build());
+ }
+}
diff --git a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
index 4521f8644fa..816d7cf0041 100644
--- a/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
+++ b/sonar-db/src/main/resources/org/sonar/db/version/rows-h2.sql
@@ -511,6 +511,7 @@ INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1419');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1420');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1421');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1422');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1423');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, IS_ROOT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', true, '1418215735482', '1418215735482');
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
diff --git a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
index b21263e127f..6c4daf0f2da 100644
--- a/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
+++ b/sonar-db/src/main/resources/org/sonar/db/version/schema-h2.ddl
@@ -618,3 +618,21 @@ CREATE TABLE "USER_TOKENS" (
);
CREATE UNIQUE INDEX "USER_TOKENS_TOKEN_HASH" ON "USER_TOKENS" ("TOKEN_HASH");
CREATE UNIQUE INDEX "USER_TOKENS_LOGIN_NAME" ON "USER_TOKENS" ("LOGIN", "NAME");
+
+
+CREATE TABLE "WEBHOOK_DELIVERIES" (
+ "UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
+ "COMPONENT_UUID" VARCHAR(40) NOT NULL,
+ "CE_TASK_UUID" VARCHAR(40) NOT NULL,
+ "NAME" VARCHAR(100) NOT NULL,
+ "URL" VARCHAR(2000) NOT NULL,
+ "SUCCESS" BOOLEAN NOT NULL,
+ "HTTP_STATUS" INT,
+ "DURATION_MS" INT,
+ "PAYLOAD" CLOB NOT NULL,
+ "ERROR_STACKTRACE" CLOB,
+ "CREATED_AT" BIGINT NOT NULL
+);
+CREATE UNIQUE INDEX "PK_WEBHOOK_DELIVERIES" ON "WEBHOOK_DELIVERIES" ("UUID");
+CREATE INDEX "COMPONENT_UUID" ON "WEBHOOK_DELIVERIES" ("COMPONENT_UUID");
+CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES" ("CE_TASK_UUID");
diff --git a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java
index 6ad5962474d..c83c4d0a7a2 100644
--- a/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/version/MigrationStepModuleTest.java
@@ -29,6 +29,6 @@ public class MigrationStepModuleTest {
public void verify_count_of_added_MigrationStep_types() {
ComponentContainer container = new ComponentContainer();
new MigrationStepModule().configure(container);
- assertThat(container.size()).isEqualTo(163);
+ assertThat(container.size()).isEqualTo(164);
}
}
diff --git a/sonar-db/src/test/java/org/sonar/db/version/v62/CreateTableWebhookDeliveriesTest.java b/sonar-db/src/test/java/org/sonar/db/version/v62/CreateTableWebhookDeliveriesTest.java
new file mode 100644
index 00000000000..26e057bfc4b
--- /dev/null
+++ b/sonar-db/src/test/java/org/sonar/db/version/v62/CreateTableWebhookDeliveriesTest.java
@@ -0,0 +1,74 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.db.version.v62;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+public class CreateTableWebhookDeliveriesTest {
+
+ private static final String TABLE = "webhook_deliveries";
+
+ @Rule
+ public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, CreateTableWebhookDeliveriesTest.class, "empty.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private CreateTableWebhookDeliveries underTest = new CreateTableWebhookDeliveries(dbTester.database());
+
+ @Test
+ public void creates_table_on_empty_db() throws SQLException {
+ underTest.execute();
+
+ assertThat(dbTester.countRowsOfTable(TABLE)).isEqualTo(0);
+
+ dbTester.assertColumnDefinition(TABLE, "uuid", Types.VARCHAR, 40, false);
+ dbTester.assertColumnDefinition(TABLE, "component_uuid", Types.VARCHAR, 40, false);
+ dbTester.assertColumnDefinition(TABLE, "ce_task_uuid", Types.VARCHAR, 40, false);
+ dbTester.assertColumnDefinition(TABLE, "name", Types.VARCHAR, 100, false);
+ dbTester.assertColumnDefinition(TABLE, "url", Types.VARCHAR, 2000, false);
+ dbTester.assertColumnDefinition(TABLE, "success", Types.BOOLEAN, null, false);
+ dbTester.assertColumnDefinition(TABLE, "http_status", Types.INTEGER, null, true);
+ dbTester.assertColumnDefinition(TABLE, "duration_ms", Types.INTEGER, null, true);
+ dbTester.assertColumnDefinition(TABLE, "payload", Types.CLOB, null, false);
+ dbTester.assertColumnDefinition(TABLE, "error_stacktrace", Types.CLOB, null, true);
+ dbTester.assertColumnDefinition(TABLE, "created_at", Types.BIGINT, null, false);
+ dbTester.assertPrimaryKey(TABLE, "pk_" + TABLE, "uuid");
+ }
+
+ @Test
+ public void migration_is_not_reentrant() throws SQLException {
+ underTest.execute();
+
+ expectedException.expect(IllegalStateException.class);
+
+ underTest.execute();
+ }
+
+
+}
diff --git a/sonar-db/src/test/resources/org/sonar/db/version/v62/CreateTableWebhookDeliveriesTest/empty.sql b/sonar-db/src/test/resources/org/sonar/db/version/v62/CreateTableWebhookDeliveriesTest/empty.sql
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sonar-db/src/test/resources/org/sonar/db/version/v62/CreateTableWebhookDeliveriesTest/empty.sql