aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2017-07-28 10:27:21 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2017-08-07 11:44:06 +0200
commitd43366ba83a9112bfe1b320640b9afc7d171d6c4 (patch)
tree0cf109a48d6d367314ba44389f7f773b6fb821a0 /server/sonar-db-migration
parentf48a201c2a691281e689b2a4aee9df976a5f3986 (diff)
downloadsonarqube-d43366ba83a9112bfe1b320640b9afc7d171d6c4.tar.gz
sonarqube-d43366ba83a9112bfe1b320640b9afc7d171d6c4.zip
SONAR-9639 Support CE task characteristics
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristics.java84
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java4
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristicsTest.java61
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java39
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristicsTest/empty.sql0
5 files changed, 187 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristics.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristics.java
new file mode 100644
index 00000000000..79770d26fc0
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristics.java
@@ -0,0 +1,84 @@
+/*
+ * 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 static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+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.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class CreateTableCeTaskCharacteristics extends DdlChange {
+ private static final String TABLE_NAME = "ce_task_characteristics";
+
+ public CreateTableCeTaskCharacteristics(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ VarcharColumnDef uuidColumn = newVarcharColumnDefBuilder()
+ .setColumnName("uuid")
+ .setLimit(UUID_SIZE)
+ .setIsNullable(false)
+ .setIgnoreOracleUnit(true)
+ .build();
+ VarcharColumnDef ceTaskUuidColumn = newVarcharColumnDefBuilder()
+ .setColumnName("task_uuid")
+ .setLimit(UUID_SIZE)
+ .setIsNullable(false)
+ .setIgnoreOracleUnit(true)
+ .build();
+ VarcharColumnDef keyColumn = newVarcharColumnDefBuilder()
+ .setColumnName("kee")
+ .setLimit(512)
+ .setIsNullable(false)
+ .setIgnoreOracleUnit(true)
+ .build();
+ VarcharColumnDef valueColumn = newVarcharColumnDefBuilder()
+ .setColumnName("text_value")
+ .setLimit(512)
+ .setIsNullable(true)
+ .setIgnoreOracleUnit(true)
+ .build();
+
+ context.execute(
+ new CreateTableBuilder(getDialect(), TABLE_NAME)
+ .addPkColumn(uuidColumn)
+ .addColumn(ceTaskUuidColumn)
+ .addColumn(keyColumn)
+ .addColumn(valueColumn)
+ .build());
+
+ context.execute(
+ new CreateIndexBuilder(getDialect())
+ .setTable(TABLE_NAME)
+ .setName("ce_characteristics_" + ceTaskUuidColumn.getName())
+ .addColumn(ceTaskUuidColumn)
+ .setUnique(false)
+ .build());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java
index a9bb2dc26be..9ea2becfe20 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java
@@ -26,6 +26,8 @@ import org.sonar.server.platform.db.migration.version.DbVersion;
public class DbVersion66 implements DbVersion {
@Override
public void addSteps(MigrationStepRegistry registry) {
- registry.add(1800, "Add incremental column to snapthots table", AddIncrementalColumnToSnapshotsTable.class);
+ registry
+ .add(1800, "Add incremental column to snapthots table", AddIncrementalColumnToSnapshotsTable.class)
+ .add(1801, "Create table CE task characteristics", CreateTableCeTaskCharacteristics.class);
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristicsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristicsTest.java
new file mode 100644
index 00000000000..da3e2fbd9e4
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristicsTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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 static org.assertj.core.api.Assertions.assertThat;
+
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+public class CreateTableCeTaskCharacteristicsTest {
+ private static final String TABLE = "ce_task_characteristics";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(CreateTableCeTaskCharacteristicsTest.class, "empty.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private CreateTableCeTaskCharacteristics underTest = new CreateTableCeTaskCharacteristics(db.database());
+
+ @Test
+ public void creates_table_on_empty_db() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countRowsOfTable(TABLE)).isEqualTo(0);
+ db.assertPrimaryKey(TABLE, "pk_" + TABLE, "uuid");
+ db.assertColumnDefinition(TABLE, "task_uuid", Types.VARCHAR, 40, false);
+ db.assertColumnDefinition(TABLE, "kee", Types.VARCHAR, 512, false);
+ db.assertColumnDefinition(TABLE, "text_value", Types.VARCHAR, 512, true);
+ }
+
+ @Test
+ public void migration_is_not_reentrant() throws SQLException {
+ underTest.execute();
+
+ expectedException.expect(IllegalStateException.class);
+
+ underTest.execute();
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java
new file mode 100644
index 00000000000..57008442615
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66Test.java
@@ -0,0 +1,39 @@
+/*
+ * 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 static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount;
+import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
+
+import org.junit.Test;
+
+public class DbVersion66Test {
+ private DbVersion66 underTest = new DbVersion66();
+
+ @Test
+ public void migrationNumber_starts_at_1800() {
+ verifyMinimumMigrationNumber(underTest, 1800);
+ }
+
+ @Test
+ public void verify_migration_count() {
+ verifyMigrationCount(underTest, 2);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristicsTest/empty.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristicsTest/empty.sql
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v66/CreateTableCeTaskCharacteristicsTest/empty.sql