aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2018-11-09 14:05:59 +0100
committerSonarTech <sonartech@sonarsource.com>2018-11-16 20:21:06 +0100
commitc21cf184eda604c802b549e98b162191e769241a (patch)
tree1a1207d174e432eb55da09f23111ec4bbb3fc56f /server
parente86e8c1fe6f96ea84d2f38ee01b3610d21eebe94 (diff)
downloadsonarqube-c21cf184eda604c802b549e98b162191e769241a.tar.gz
sonarqube-c21cf184eda604c802b549e98b162191e769241a.zip
SONARCLOUD-156 Set IS_OWNER_USER not nullable in ALM_APP_INSTALLS
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl2
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java4
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java5
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml8
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75.java1
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstalls.java46
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75Test.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstallsTest.java53
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstallsTest/almAppInstalls.sql15
10 files changed, 119 insertions, 19 deletions
diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
index 0f81c976ee7..d828099bb83 100644
--- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
+++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl
@@ -868,7 +868,7 @@ CREATE TABLE "ALM_APP_INSTALLS" (
"UUID" VARCHAR(40) NOT NULL,
"ALM_ID" VARCHAR(40) NOT NULL,
"OWNER_ID" VARCHAR(4000) NOT NULL,
- "IS_OWNER_USER" BOOLEAN,
+ "IS_OWNER_USER" BOOLEAN NOT NULL,
"INSTALL_ID" VARCHAR(4000) NOT NULL,
"USER_EXTERNAL_ID" VARCHAR(255),
"CREATED_AT" BIGINT NOT NULL,
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java
index 308f827baaf..63a6846f8a4 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDao.java
@@ -62,10 +62,6 @@ public class AlmAppInstallDao implements Dao {
return Optional.ofNullable(mapper.selectByInstallationId(alm.getId(), installationId));
}
- public List<AlmAppInstallDto> findAllWithNoOwnerType(DbSession dbSession) {
- return getMapper(dbSession).selectAllWithNoOwnerType();
- }
-
public List<AlmAppInstallDto> selectUnboundByUserExternalId(DbSession dbSession, String userExternalId) {
return getMapper(dbSession).selectUnboundByUserExternalId(userExternalId);
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java
index cbd55953279..70c95bd8864 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallDto.java
@@ -92,12 +92,11 @@ public class AlmAppInstallDto {
return this;
}
- @Nullable
- public Boolean isOwnerUser() {
+ public boolean isOwnerUser() {
return isOwnerUser;
}
- public AlmAppInstallDto setIsOwnerUser(@Nullable Boolean isOwnerUser) {
+ public AlmAppInstallDto setIsOwnerUser(boolean isOwnerUser) {
this.isOwnerUser = isOwnerUser;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java
index 01fab249383..11668864c4e 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/alm/AlmAppInstallMapper.java
@@ -35,8 +35,6 @@ public interface AlmAppInstallMapper {
@CheckForNull
AlmAppInstallDto selectByUuid(@Param("uuid") String uuid);
- List<AlmAppInstallDto> selectAllWithNoOwnerType();
-
List<AlmAppInstallDto> selectUnboundByUserExternalId(@Param("userExternalId") String userExternalId);
void insert(@Param("uuid") String uuid, @Param("almId") String almId, @Param("ownerId") String ownerId,
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml
index c9512fb9345..fbfb720b866 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/alm/AlmAppInstallMapper.xml
@@ -40,14 +40,6 @@
uuid = #{uuid, jdbcType=VARCHAR}
</select>
- <select id="selectAllWithNoOwnerType" parameterType="Map" resultType="org.sonar.db.alm.AlmAppInstallDto">
- select <include refid="sqlColumns" />
- from
- alm_app_installs aai
- where
- is_owner_user is null
- </select>
-
<select id="selectUnboundByUserExternalId" parameterType="Map" resultType="org.sonar.db.alm.AlmAppInstallDto">
select <include refid="sqlColumns" />
from
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75.java
index 4e019df1542..62e1425c68e 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75.java
@@ -30,6 +30,7 @@ public class DbVersion75 implements DbVersion {
.add(2400, "Add column IS_OWNER_USER in ALM_APP_INSTALLS", AddIsOwnerUserColumnInAlmAppInstall.class)
.add(2401, "Create ORGANIZATION_ALM_BINDINGS table", CreateOrganizationsAlmBindingsTable.class)
.add(2402, "Add column USER_EXTERNAL_ID in ALM_APP_INSTALLS", AddUserExternalIdColumnInAlmAppInstall.class)
+ .add(2403, "Set IS_OWNER_USER not nullable in ALM_APP_INSTALLS", SetIsOwnerUserNotNullableInAlmAppInstalls.class)
;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstalls.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstalls.java
new file mode 100644
index 00000000000..2515d5e9d58
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstalls.java
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.v75;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.SupportsBlueGreen;
+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;
+
+@SupportsBlueGreen
+public class SetIsOwnerUserNotNullableInAlmAppInstalls extends DdlChange {
+
+ public SetIsOwnerUserNotNullableInAlmAppInstalls(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), "alm_app_installs")
+ .updateColumn(newBooleanColumnDefBuilder()
+ .setColumnName("is_owner_user")
+ .setIsNullable(false)
+ .build())
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75Test.java
index d9734d175cf..557f3035af7 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75Test.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/DbVersion75Test.java
@@ -35,6 +35,6 @@ public class DbVersion75Test {
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 3);
+ verifyMigrationCount(underTest, 4);
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstallsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstallsTest.java
new file mode 100644
index 00000000000..f2f138877c5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstallsTest.java
@@ -0,0 +1,53 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 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.v75;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.BOOLEAN;
+
+public class SetIsOwnerUserNotNullableInAlmAppInstallsTest {
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(SetIsOwnerUserNotNullableInAlmAppInstallsTest.class, "almAppInstalls.sql");
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private SetIsOwnerUserNotNullableInAlmAppInstalls underTest = new SetIsOwnerUserNotNullableInAlmAppInstalls(db.database());
+
+ @Test
+ public void columns_are_updated() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("alm_app_installs", "is_owner_user", BOOLEAN, null, false);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ underTest.execute();
+
+ underTest.execute();
+ }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstallsTest/almAppInstalls.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstallsTest/almAppInstalls.sql
new file mode 100644
index 00000000000..ac7b9bcbbc1
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v75/SetIsOwnerUserNotNullableInAlmAppInstallsTest/almAppInstalls.sql
@@ -0,0 +1,15 @@
+CREATE TABLE "ALM_APP_INSTALLS" (
+ "UUID" VARCHAR(40) NOT NULL,
+ "ALM_ID" VARCHAR(40) NOT NULL,
+ "OWNER_ID" VARCHAR(4000) NOT NULL,
+ "IS_OWNER_USER" BOOLEAN,
+ "INSTALL_ID" VARCHAR(4000) NOT NULL,
+ "USER_EXTERNAL_ID" VARCHAR(255),
+ "CREATED_AT" BIGINT NOT NULL,
+ "UPDATED_AT" BIGINT NOT NULL,
+
+ CONSTRAINT "PK_ALM_APP_INSTALLS" PRIMARY KEY ("UUID")
+);
+CREATE UNIQUE INDEX "ALM_APP_INSTALLS_OWNER" ON "ALM_APP_INSTALLS" ("ALM_ID", "OWNER_ID");
+CREATE UNIQUE INDEX "ALM_APP_INSTALLS_INSTALL" ON "ALM_APP_INSTALLS" ("ALM_ID", "INSTALL_ID");
+CREATE INDEX "ALM_APP_INSTALLS_EXTERNAL_ID" ON "ALM_APP_INSTALLS" ("USER_EXTERNAL_ID"); \ No newline at end of file