Skip to content

Commit

Permalink
SONARCLOUD-156 Set IS_OWNER_USER not nullable in ALM_APP_INSTALLS
Browse files Browse the repository at this point in the history
  • Loading branch information
julienlancelot authored and SonarTech committed Nov 16, 2018
1 parent e86e8c1 commit c21cf18
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 19 deletions.
Expand Up @@ -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,
Expand Down
Expand Up @@ -62,10 +62,6 @@ public Optional<AlmAppInstallDto> selectByInstallationId(DbSession dbSession, AL
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);
}
Expand Down
Expand Up @@ -92,12 +92,11 @@ public AlmAppInstallDto setInstallId(String installId) {
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;
}
Expand Down
Expand Up @@ -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,
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -30,6 +30,7 @@ public void addSteps(MigrationStepRegistry registry) {
.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)
;
}
}
@@ -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());
}
}
Expand Up @@ -35,6 +35,6 @@ public void migrationNumber_starts_at_2400() {

@Test
public void verify_migration_count() {
verifyMigrationCount(underTest, 3);
verifyMigrationCount(underTest, 4);
}
}
@@ -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();
}

}
@@ -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");

0 comments on commit c21cf18

Please sign in to comment.