diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2018-11-09 14:05:59 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-11-16 20:21:06 +0100 |
commit | c21cf184eda604c802b549e98b162191e769241a (patch) | |
tree | 1a1207d174e432eb55da09f23111ec4bbb3fc56f /server/sonar-db-migration | |
parent | e86e8c1fe6f96ea84d2f38ee01b3610d21eebe94 (diff) | |
download | sonarqube-c21cf184eda604c802b549e98b162191e769241a.tar.gz sonarqube-c21cf184eda604c802b549e98b162191e769241a.zip |
SONARCLOUD-156 Set IS_OWNER_USER not nullable in ALM_APP_INSTALLS
Diffstat (limited to 'server/sonar-db-migration')
5 files changed, 116 insertions, 1 deletions
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 |