aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2020-09-18 17:08:48 +0200
committersonartech <sonartech@sonarsource.com>2020-09-29 20:07:42 +0000
commit0ecd8610552ccd59049308c1be46b03470c48538 (patch)
treed1da42fc9e90627a037696702cb30dd0e7442e6d /server/sonar-db-migration
parentbc413ee3db73258a22059816bd4766bcea66a9ca (diff)
downloadsonarqube-0ecd8610552ccd59049308c1be46b03470c48538.tar.gz
sonarqube-0ecd8610552ccd59049308c1be46b03470c48538.zip
SONAR-13862 Add a WS for dismissing analysis warning by the current user
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnMessageTypeColumnOfCeTaskMessageTable.java42
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddMessageTypeColumnToCeTaskMessageTable.java (renamed from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIsDismissibleColumnToCeTaskMessageTable.java)16
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/CreateUserDismissedMessagesTable.java102
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java10
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeMessageTypeColumnNotNullableOnCeTaskMessageTable.java (renamed from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeIsDismissibleColumnNotNullableOnCeTaskMessageTable.java)21
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/PopulateMessageTypeColumnOfCeTaskMessageTable.java (renamed from server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/PopulateIsDismissibleColumnOfCeTaskMessageTable.java)14
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnMessageTypeColumnOfCeTaskMessageTableTest.java (renamed from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIsDismissibleColumnToCeTaskMessageTableTest.java)16
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddMessageTypeColumnToCeTaskMessageTableTest.java63
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/CreateUserDismissedMessagesTableTest.java55
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeMessageTypeColumnNotNullableOnCeTaskMessageTableTest.java (renamed from server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeIsDismissibleColumnNotNullableOnCeTaskMessageTableTest.java)13
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/PopulateIsDismissibleColumnOfCeTaskMessageTableTest.java87
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/PopulateMessageTypeColumnOfCeTaskMessageTableTest.java73
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnMessageTypeColumnOfCeTaskMessageTableTest/schema.sql9
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddMessageTypeColumnToCeTaskMessageTableTest/schema.sql9
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeMessageTypeColumnNotNullableOnCeTaskMessageTableTest/schema.sql9
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/PopulateMessageTypeColumnOfCeTaskMessageTableTest/schema.sql9
16 files changed, 413 insertions, 135 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnMessageTypeColumnOfCeTaskMessageTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnMessageTypeColumnOfCeTaskMessageTable.java
new file mode 100644
index 00000000000..091289b5cc5
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnMessageTypeColumnOfCeTaskMessageTable.java
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v85;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class AddIndexOnMessageTypeColumnOfCeTaskMessageTable extends DdlChange {
+ private static final String TABLE = "ce_task_message";
+
+ public AddIndexOnMessageTypeColumnOfCeTaskMessageTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE)
+ .setName("ctm_message_type")
+ .addColumn("message_type")
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIsDismissibleColumnToCeTaskMessageTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddMessageTypeColumnToCeTaskMessageTable.java
index 674ae2f2b81..f8cf9f6c7fe 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddIsDismissibleColumnToCeTaskMessageTable.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/AddMessageTypeColumnToCeTaskMessageTable.java
@@ -21,29 +21,29 @@ package org.sonar.server.platform.db.migration.version.v85;
import java.sql.SQLException;
import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
+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;
-import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
-public class AddIsDismissibleColumnToCeTaskMessageTable extends DdlChange {
+public class AddMessageTypeColumnToCeTaskMessageTable extends DdlChange {
private static final String TABLE = "ce_task_message";
- private static final String NEW_COLUMN = "is_dismissible";
- private static final BooleanColumnDef IS_DISMISSIBLE = newBooleanColumnDefBuilder()
- .setColumnName(NEW_COLUMN)
+ private static final VarcharColumnDef MESSAGE_TYPE = newVarcharColumnDefBuilder()
+ .setColumnName("message_type")
.setIsNullable(true)
+ .setLimit(255)
.build();
- public AddIsDismissibleColumnToCeTaskMessageTable(Database db) {
+ public AddMessageTypeColumnToCeTaskMessageTable(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
context.execute(new AddColumnsBuilder(getDialect(), TABLE)
- .addColumn(IS_DISMISSIBLE)
+ .addColumn(MESSAGE_TYPE)
.build());
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/CreateUserDismissedMessagesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/CreateUserDismissedMessagesTable.java
new file mode 100644
index 00000000000..82b91108df1
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/CreateUserDismissedMessagesTable.java
@@ -0,0 +1,102 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v85;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef;
+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;
+
+import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CreateUserDismissedMessagesTable extends DdlChange {
+
+ private static final String TABLE_NAME = "user_dismissed_messages";
+
+ private static final VarcharColumnDef UUID_COLUMN = newVarcharColumnDefBuilder()
+ .setColumnName("uuid")
+ .setIsNullable(false)
+ .setLimit(UUID_SIZE)
+ .build();
+
+ private static final VarcharColumnDef USER_UUID_COLUMN = newVarcharColumnDefBuilder()
+ .setColumnName("user_uuid")
+ .setIsNullable(false)
+ .setLimit(VarcharColumnDef.USER_UUID_SIZE)
+ .build();
+
+ private static final VarcharColumnDef PROJECT_UUID = newVarcharColumnDefBuilder()
+ .setColumnName("project_uuid")
+ .setIsNullable(false)
+ .setLimit(UUID_SIZE)
+ .build();
+
+ private static final VarcharColumnDef MESSAGE_TYPE = newVarcharColumnDefBuilder()
+ .setColumnName("message_type")
+ .setIsNullable(false)
+ .setLimit(255)
+ .build();
+
+ private static final BigIntegerColumnDef CREATED_AT = newBigIntegerColumnDefBuilder()
+ .setColumnName("created_at")
+ .setIsNullable(false)
+ .build();
+
+ public CreateUserDismissedMessagesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
+ .addPkColumn(UUID_COLUMN)
+ .addColumn(USER_UUID_COLUMN)
+ .addColumn(PROJECT_UUID)
+ .addColumn(MESSAGE_TYPE)
+ .addColumn(CREATED_AT)
+ .build());
+
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE_NAME)
+ .setName("uniq_user_dismissed_messages")
+ .setUnique(true)
+ .addColumn(USER_UUID_COLUMN)
+ .addColumn(PROJECT_UUID)
+ .addColumn(MESSAGE_TYPE)
+ .build());
+
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE_NAME)
+ .setName("udm_project_uuid")
+ .addColumn(PROJECT_UUID)
+ .build());
+
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE_NAME)
+ .setName("udm_message_type")
+ .addColumn(MESSAGE_TYPE)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java
index 80ea17d33da..0396ecac844 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/DbVersion85.java
@@ -47,9 +47,11 @@ public class DbVersion85 implements DbVersion {
.add(4016, "Add 'type' column to 'plugins' table", AddTypeToPlugins.class)
.add(4017, "Populate 'type' column in 'plugins' table", PopulateTypeInPlugins.class)
.add(4018, "Alter 'type' column in 'plugins' to not nullable", AlterTypeInPluginNotNullable.class)
- .add(4019, "Add 'is_dismissible' column to `ce_task_message` table", AddIsDismissibleColumnToCeTaskMessageTable.class)
- .add(4020, "Populate 'is_dismissible' column of `ce_task_message` table", PopulateIsDismissibleColumnOfCeTaskMessageTable.class)
- .add(4021, "Make 'is_dismissible' column not nullable for `ce_task_message` table", MakeIsDismissibleColumnNotNullableOnCeTaskMessageTable.class)
- ;
+ .add(4019, "Add 'message_type' column to 'ce_task_message' table", AddMessageTypeColumnToCeTaskMessageTable.class)
+ .add(4020, "Populate 'message_type' column of 'ce_task_message' table", PopulateMessageTypeColumnOfCeTaskMessageTable.class)
+ .add(4021, "Make 'message_type' column not nullable for `ce_task_message` table", MakeMessageTypeColumnNotNullableOnCeTaskMessageTable.class)
+ .add(4022, "Add index on 'message_type' column of `ce_task_message` table", AddIndexOnMessageTypeColumnOfCeTaskMessageTable.class)
+ .add(4023, "Create 'user_dismissed_messages' table", CreateUserDismissedMessagesTable.class
+ );
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeIsDismissibleColumnNotNullableOnCeTaskMessageTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeMessageTypeColumnNotNullableOnCeTaskMessageTable.java
index 6b285203b4b..aad98f9c76a 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeIsDismissibleColumnNotNullableOnCeTaskMessageTable.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/MakeMessageTypeColumnNotNullableOnCeTaskMessageTable.java
@@ -21,30 +21,27 @@ package org.sonar.server.platform.db.migration.version.v85;
import java.sql.SQLException;
import org.sonar.db.Database;
-import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
+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;
-import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
-public class MakeIsDismissibleColumnNotNullableOnCeTaskMessageTable extends DdlChange {
-
- private static final String TABLE = "ce_task_message";
- private static final String NEW_COLUMN = "is_dismissible";
-
- private static final BooleanColumnDef IS_DISMISSIBLE = newBooleanColumnDefBuilder()
- .setColumnName(NEW_COLUMN)
+public class MakeMessageTypeColumnNotNullableOnCeTaskMessageTable extends DdlChange {
+ private static final VarcharColumnDef MESSAGE_TYPE = newVarcharColumnDefBuilder()
+ .setColumnName("message_type")
.setIsNullable(false)
+ .setLimit(255)
.build();
- public MakeIsDismissibleColumnNotNullableOnCeTaskMessageTable(Database db) {
+ public MakeMessageTypeColumnNotNullableOnCeTaskMessageTable(Database db) {
super(db);
}
@Override
public void execute(Context context) throws SQLException {
- context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
- .updateColumn(IS_DISMISSIBLE)
+ context.execute(new AlterColumnsBuilder(getDialect(), "ce_task_message")
+ .updateColumn(MESSAGE_TYPE)
.build());
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/PopulateIsDismissibleColumnOfCeTaskMessageTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/PopulateMessageTypeColumnOfCeTaskMessageTable.java
index 63863b29912..00e358dcff7 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/PopulateIsDismissibleColumnOfCeTaskMessageTable.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v85/PopulateMessageTypeColumnOfCeTaskMessageTable.java
@@ -24,20 +24,18 @@ import org.sonar.db.Database;
import org.sonar.server.platform.db.migration.step.DataChange;
import org.sonar.server.platform.db.migration.step.MassUpdate;
-public class PopulateIsDismissibleColumnOfCeTaskMessageTable extends DataChange {
-
- public PopulateIsDismissibleColumnOfCeTaskMessageTable(Database db) {
+public class PopulateMessageTypeColumnOfCeTaskMessageTable extends DataChange {
+ public PopulateMessageTypeColumnOfCeTaskMessageTable(Database db) {
super(db);
}
@Override
- protected void execute(Context context) throws SQLException {
+ protected void execute(DataChange.Context context) throws SQLException {
MassUpdate massUpdate = context.prepareMassUpdate();
- massUpdate.select("select ctm.uuid from ce_task_message ctm where ctm.is_dismissible is null");
- massUpdate.update("update ce_task_message set is_dismissible = ? where uuid = ?");
-
+ massUpdate.select("select ctm.uuid from ce_task_message ctm where ctm.message_type is null");
+ massUpdate.update("update ce_task_message set message_type = ? where uuid = ?");
massUpdate.execute((row, update) -> {
- update.setBoolean(1, false);
+ update.setString(1, "GENERIC");
update.setString(2, row.getString(1));
return true;
});
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIsDismissibleColumnToCeTaskMessageTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnMessageTypeColumnOfCeTaskMessageTableTest.java
index bc51cb03288..b5c648a79bc 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIsDismissibleColumnToCeTaskMessageTableTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddIndexOnMessageTypeColumnOfCeTaskMessageTableTest.java
@@ -17,7 +17,6 @@
* 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.v85;
import java.sql.SQLException;
@@ -26,20 +25,19 @@ import org.junit.Test;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DdlChange;
-import static java.sql.Types.BOOLEAN;
-
-public class AddIsDismissibleColumnToCeTaskMessageTableTest {
+public class AddIndexOnMessageTypeColumnOfCeTaskMessageTableTest {
+ private static final String TABLE_NAME = "ce_task_message";
+ private static final String INDEX_NAME = "ctm_message_type";
@Rule
- public CoreDbTester db = CoreDbTester.createForSchema(AddIsDismissibleColumnToCeTaskMessageTableTest.class, "schema.sql");
+ public CoreDbTester db = CoreDbTester.createForSchema(AddIndexOnMessageTypeColumnOfCeTaskMessageTableTest.class, "schema.sql");
- DdlChange underTest = new AddIsDismissibleColumnToCeTaskMessageTable(db.database());
+ DdlChange underTest = new AddIndexOnMessageTypeColumnOfCeTaskMessageTable(db.database());
@Test
- public void add_column() throws SQLException {
+ public void add_index() throws SQLException {
underTest.execute();
- db.assertColumnDefinition("ce_task_message", "is_dismissible", BOOLEAN, null, true);
+ db.assertIndex(TABLE_NAME, INDEX_NAME, "message_type");
}
-
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddMessageTypeColumnToCeTaskMessageTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddMessageTypeColumnToCeTaskMessageTableTest.java
new file mode 100644
index 00000000000..0ab65645f12
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/AddMessageTypeColumnToCeTaskMessageTableTest.java
@@ -0,0 +1,63 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v85;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddMessageTypeColumnToCeTaskMessageTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddMessageTypeColumnToCeTaskMessageTableTest.class, "schema.sql");
+
+ private final DdlChange underTest = new AddMessageTypeColumnToCeTaskMessageTable(db.database());
+
+ @Before
+ public void setup() {
+ insertTaskMessage(1L, "a1");
+ insertTaskMessage(2L, "a2");
+ insertTaskMessage(3L, "a3");
+ }
+
+ @Test
+ public void add_message_type_column_to_ce_task_message_table() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("ce_task_message", "message_type", Types.VARCHAR, 255, true);
+
+ assertThat(db.countSql("select count(uuid) from ce_task_message")).isEqualTo(3);
+ }
+
+ private void insertTaskMessage(Long id, String message) {
+ db.executeInsert("ce_task_message",
+ "uuid", "uuid-" + id,
+ "task_uuid", "task-uuid-" + id,
+ "message", message,
+ "created_at", System2.INSTANCE.now());
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/CreateUserDismissedMessagesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/CreateUserDismissedMessagesTableTest.java
new file mode 100644
index 00000000000..427fda8f9c4
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/CreateUserDismissedMessagesTableTest.java
@@ -0,0 +1,55 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v85;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.BIGINT;
+import static java.sql.Types.VARCHAR;
+
+public class CreateUserDismissedMessagesTableTest {
+ private static final String TABLE_NAME = "user_dismissed_messages";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createEmpty();
+
+ private final CreateUserDismissedMessagesTable underTest = new CreateUserDismissedMessagesTable(dbTester.database());
+
+ @Test
+ public void table_has_been_created() throws SQLException {
+ underTest.execute();
+
+ dbTester.assertTableExists(TABLE_NAME);
+ dbTester.assertPrimaryKey(TABLE_NAME, "pk_user_dismissed_messages", "uuid");
+ dbTester.assertColumnDefinition(TABLE_NAME, "uuid", VARCHAR, 40, false);
+ dbTester.assertColumnDefinition(TABLE_NAME, "user_uuid", VARCHAR, 255, false);
+ dbTester.assertColumnDefinition(TABLE_NAME, "project_uuid", VARCHAR, 40, false);
+ dbTester.assertColumnDefinition(TABLE_NAME, "message_type", VARCHAR, 255, false);
+ dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, null, false);
+ dbTester.assertUniqueIndex(TABLE_NAME, "uniq_user_dismissed_messages", "user_uuid",
+ "project_uuid", "message_type");
+ dbTester.assertIndex(TABLE_NAME, "udm_project_uuid", "project_uuid");
+ dbTester.assertIndex(TABLE_NAME, "udm_message_type", "message_type");
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeIsDismissibleColumnNotNullableOnCeTaskMessageTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeMessageTypeColumnNotNullableOnCeTaskMessageTableTest.java
index 5f49ab61888..b559adf60ef 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeIsDismissibleColumnNotNullableOnCeTaskMessageTableTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/MakeMessageTypeColumnNotNullableOnCeTaskMessageTableTest.java
@@ -25,20 +25,19 @@ import org.junit.Test;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.MigrationStep;
-import static java.sql.Types.BOOLEAN;
+import static java.sql.Types.VARCHAR;
-public class MakeIsDismissibleColumnNotNullableOnCeTaskMessageTableTest {
+public class MakeMessageTypeColumnNotNullableOnCeTaskMessageTableTest {
@Rule
- public CoreDbTester db = CoreDbTester.createForSchema(MakeIsDismissibleColumnNotNullableOnCeTaskMessageTableTest.class, "schema.sql");
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeMessageTypeColumnNotNullableOnCeTaskMessageTableTest.class, "schema.sql");
- private MigrationStep underTest = new MakeIsDismissibleColumnNotNullableOnCeTaskMessageTable(db.database());
+ private final MigrationStep underTest = new MakeMessageTypeColumnNotNullableOnCeTaskMessageTable(db.database());
@Test
- public void ce_task_message_column_is_not_null() throws SQLException {
+ public void message_type_column_is_not_null() throws SQLException {
underTest.execute();
- db.assertColumnDefinition("ce_task_message", "is_dismissible", BOOLEAN, null, false);
+ db.assertColumnDefinition("ce_task_message", "message_type", VARCHAR, 255, false);
}
-
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/PopulateIsDismissibleColumnOfCeTaskMessageTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/PopulateIsDismissibleColumnOfCeTaskMessageTableTest.java
deleted file mode 100644
index fb17fc524e8..00000000000
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/PopulateIsDismissibleColumnOfCeTaskMessageTableTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 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.v85;
-
-import java.sql.SQLException;
-import javax.annotation.Nullable;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.core.util.Uuids;
-import org.sonar.db.CoreDbTester;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class PopulateIsDismissibleColumnOfCeTaskMessageTableTest {
-
- @Rule
- public CoreDbTester db = CoreDbTester.createForSchema(PopulateIsDismissibleColumnOfCeTaskMessageTableTest.class, "schema.sql");
-
- private PopulateIsDismissibleColumnOfCeTaskMessageTable underTest = new PopulateIsDismissibleColumnOfCeTaskMessageTable(db.database());
-
- @Test
- public void execute_migration() throws SQLException {
- insertCeTaskMessage(null);
- insertCeTaskMessage(null);
- insertCeTaskMessage(null);
-
- underTest.execute();
-
- assertIsDismissibleValuesAreAllFalse();
- }
-
- @Test
- public void migrate_not_already_updated_rows() throws SQLException {
- insertCeTaskMessage(false);
- insertCeTaskMessage(false);
- insertCeTaskMessage(null);
-
- underTest.execute();
-
- assertIsDismissibleValuesAreAllFalse();
- }
-
- @Test
- public void migration_is_reentrant() throws SQLException {
- insertCeTaskMessage(null);
-
- underTest.execute();
- underTest.execute();
-
- assertIsDismissibleValuesAreAllFalse();
- }
-
- private void assertIsDismissibleValuesAreAllFalse() {
- assertThat(db.select("select is_dismissible as \"IS_DISMISSIBLE\" from ce_task_message")
- .stream()
- .map(rows -> rows.get("IS_DISMISSIBLE")))
- .containsOnly(false);
- }
-
- private String insertCeTaskMessage(@Nullable Boolean isDissmisible) {
- String uuid = Uuids.createFast();
- db.executeInsert("CE_TASK_MESSAGE",
- "UUID", uuid,
- "TASK_UUID", Uuids.createFast(),
- "MESSAGE", "message-" + uuid,
- "IS_DISMISSIBLE", isDissmisible,
- "CREATED_AT", System.currentTimeMillis());
- return uuid;
- }
-}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/PopulateMessageTypeColumnOfCeTaskMessageTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/PopulateMessageTypeColumnOfCeTaskMessageTableTest.java
new file mode 100644
index 00000000000..b5cfcec501d
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v85/PopulateMessageTypeColumnOfCeTaskMessageTableTest.java
@@ -0,0 +1,73 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.v85;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.utils.System2;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateMessageTypeColumnOfCeTaskMessageTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateMessageTypeColumnOfCeTaskMessageTableTest.class, "schema.sql");
+
+ private final DataChange underTest = new PopulateMessageTypeColumnOfCeTaskMessageTable(db.database());
+
+ @Test
+ public void add_message_type_column_on_empty_table() throws SQLException {
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from ce_task_message")).isZero();
+ }
+
+ @Test
+ public void add_message_type_column_on_non_empty_table() throws SQLException {
+ insertTaskMessage(1L, "msg1");
+ insertTaskMessage(2L, "msg2");
+ insertTaskMessage(3L, "msg3");
+ insertTaskMessage(4L, "msg4");
+
+ underTest.execute();
+
+ assertThat(db.countSql("select count(*) from ce_task_message")).isEqualTo(4);
+ assertThat(db.select("select uuid, task_uuid, message, message_type from ce_task_message"))
+ .extracting(m -> m.get("UUID"), m -> m.get("TASK_UUID"), m -> m.get("MESSAGE"), m -> m.get("MESSAGE_TYPE"))
+ .containsExactlyInAnyOrder(
+ tuple("uuid-1", "task-uuid-1", "msg1", "GENERIC"),
+ tuple("uuid-2", "task-uuid-2", "msg2", "GENERIC"),
+ tuple("uuid-3", "task-uuid-3", "msg3", "GENERIC"),
+ tuple("uuid-4", "task-uuid-4", "msg4", "GENERIC"));
+ }
+
+ private void insertTaskMessage(Long id, String message) {
+ db.executeInsert("ce_task_message",
+ "uuid", "uuid-" + id,
+ "task_uuid", "task-uuid-" + id,
+ "message", message,
+ "created_at", System2.INSTANCE.now());
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnMessageTypeColumnOfCeTaskMessageTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnMessageTypeColumnOfCeTaskMessageTableTest/schema.sql
new file mode 100644
index 00000000000..4200aab9747
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddIndexOnMessageTypeColumnOfCeTaskMessageTableTest/schema.sql
@@ -0,0 +1,9 @@
+CREATE TABLE "CE_TASK_MESSAGE"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "TASK_UUID" VARCHAR(40) NOT NULL,
+ "MESSAGE" VARCHAR(4000) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "MESSAGE_TYPE" VARCHAR(255) NOT NULL
+);
+ALTER TABLE "CE_TASK_MESSAGE" ADD CONSTRAINT "PK_CE_TASK_MESSAGE" PRIMARY KEY("UUID");
+CREATE INDEX "CE_TASK_MESSAGE_TASK" ON "CE_TASK_MESSAGE"("TASK_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddMessageTypeColumnToCeTaskMessageTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddMessageTypeColumnToCeTaskMessageTableTest/schema.sql
new file mode 100644
index 00000000000..67237e59da5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/AddMessageTypeColumnToCeTaskMessageTableTest/schema.sql
@@ -0,0 +1,9 @@
+CREATE TABLE "CE_TASK_MESSAGE" (
+ "UUID" VARCHAR(40) NOT NULL,
+ "TASK_UUID" VARCHAR(40) NOT NULL,
+ "MESSAGE" VARCHAR(4000) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+
+ CONSTRAINT "CE_TASK_MESSAGE" PRIMARY KEY ("UUID")
+);
+CREATE INDEX "CE_TASK_MESSAGE_TASK" ON "CE_TASK_MESSAGE" ("TASK_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeMessageTypeColumnNotNullableOnCeTaskMessageTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeMessageTypeColumnNotNullableOnCeTaskMessageTableTest/schema.sql
new file mode 100644
index 00000000000..c46fbbfd8c6
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/MakeMessageTypeColumnNotNullableOnCeTaskMessageTableTest/schema.sql
@@ -0,0 +1,9 @@
+CREATE TABLE "CE_TASK_MESSAGE"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "TASK_UUID" VARCHAR(40) NOT NULL,
+ "MESSAGE" VARCHAR(4000) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "MESSAGE_TYPE" VARCHAR(255)
+);
+ALTER TABLE "CE_TASK_MESSAGE" ADD CONSTRAINT "PK_CE_TASK_MESSAGE" PRIMARY KEY("UUID");
+CREATE INDEX "CE_TASK_MESSAGE_TASK" ON "CE_TASK_MESSAGE"("TASK_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/PopulateMessageTypeColumnOfCeTaskMessageTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/PopulateMessageTypeColumnOfCeTaskMessageTableTest/schema.sql
new file mode 100644
index 00000000000..c46fbbfd8c6
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v85/PopulateMessageTypeColumnOfCeTaskMessageTableTest/schema.sql
@@ -0,0 +1,9 @@
+CREATE TABLE "CE_TASK_MESSAGE"(
+ "UUID" VARCHAR(40) NOT NULL,
+ "TASK_UUID" VARCHAR(40) NOT NULL,
+ "MESSAGE" VARCHAR(4000) NOT NULL,
+ "CREATED_AT" BIGINT NOT NULL,
+ "MESSAGE_TYPE" VARCHAR(255)
+);
+ALTER TABLE "CE_TASK_MESSAGE" ADD CONSTRAINT "PK_CE_TASK_MESSAGE" PRIMARY KEY("UUID");
+CREATE INDEX "CE_TASK_MESSAGE_TASK" ON "CE_TASK_MESSAGE"("TASK_UUID");