aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2018-10-24 16:50:35 +0200
committerSonarTech <sonartech@sonarsource.com>2018-11-16 20:21:05 +0100
commite7b860647b22904459d19a2bb5f8713d20322ef0 (patch)
treea5a2256768fbbfe804543a83c0ef35c191469798 /server/sonar-db-migration
parent83144d4988f1f5ecc1f07852e3d67fcd07a8024e (diff)
downloadsonarqube-e7b860647b22904459d19a2bb5f8713d20322ef0.tar.gz
sonarqube-e7b860647b22904459d19a2bb5f8713d20322ef0.zip
SONAR-11325 Create GET api/alm_integration/list_unbound_installations
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstall.java58
-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/test/java/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstallTest.java57
-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/resources/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstallTest/almAppInstalls.sql13
5 files changed, 130 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstall.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstall.java
new file mode 100644
index 00000000000..57330a6691f
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstall.java
@@ -0,0 +1,58 @@
+/*
+ * 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.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+@SupportsBlueGreen
+public class AddUserExternalIdColumnInAlmAppInstall extends DdlChange {
+
+ private static final String ALM_APP_INSTALLS_TABLE = "alm_app_installs";
+ private static final String USER_EXTERNAL_ID_COLUMN = "user_external_id";
+
+ public AddUserExternalIdColumnInAlmAppInstall(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ VarcharColumnDef userExternalIdDef = newVarcharColumnDefBuilder()
+ .setColumnName(USER_EXTERNAL_ID_COLUMN)
+ .setLimit(255)
+ .setIsNullable(true)
+ .build();
+ context.execute(new AddColumnsBuilder(getDialect(), ALM_APP_INSTALLS_TABLE)
+ .addColumn(userExternalIdDef).build());
+ context.execute(new CreateIndexBuilder(getDialect())
+ .setTable(ALM_APP_INSTALLS_TABLE)
+ .addColumn(userExternalIdDef)
+ .setUnique(false)
+ .setName("alm_app_installs_external_id")
+ .build());
+ }
+}
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 65c33aa424e..4e019df1542 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
@@ -29,6 +29,7 @@ public class DbVersion75 implements DbVersion {
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)
;
}
}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstallTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstallTest.java
new file mode 100644
index 00000000000..827e794b9d7
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstallTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.VARCHAR;
+
+public class AddUserExternalIdColumnInAlmAppInstallTest {
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(AddUserExternalIdColumnInAlmAppInstallTest.class, "almAppInstalls.sql");
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private AddUserExternalIdColumnInAlmAppInstall underTest = new AddUserExternalIdColumnInAlmAppInstall(db.database());
+
+ @Test
+ public void column_is_added_to_table() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("alm_app_installs", "user_external_id", VARCHAR, 255, true);
+ db.assertIndex("alm_app_installs", "alm_app_installs_external_id", "user_external_id");
+ }
+
+ @Test
+ public void migration_is_not_reentrant() throws SQLException {
+ underTest.execute();
+
+ expectedException.expect(IllegalStateException.class);
+
+ underTest.execute();
+ }
+
+} \ No newline at end of file
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 0b940dbcb16..d9734d175cf 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, 2);
+ verifyMigrationCount(underTest, 3);
}
}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstallTest/almAppInstalls.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstallTest/almAppInstalls.sql
new file mode 100644
index 00000000000..d73225bde8c
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v75/AddUserExternalIdColumnInAlmAppInstallTest/almAppInstalls.sql
@@ -0,0 +1,13 @@
+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,
+ "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"); \ No newline at end of file