diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2019-04-18 22:30:24 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-04-29 20:21:06 +0200 |
commit | d73b2ba4be5145af6eaf408d840ceb3149cc2bbc (patch) | |
tree | 45fd200e5437c6f97898185d1208e65393e01a91 /server/sonar-db-migration | |
parent | 31f945a7200c941e23debb675b649ecf6fe2eef9 (diff) | |
download | sonarqube-d73b2ba4be5145af6eaf408d840ceb3149cc2bbc.tar.gz sonarqube-d73b2ba4be5145af6eaf408d840ceb3149cc2bbc.zip |
SONAR-12000 add DB column webhooks.secret
Diffstat (limited to 'server/sonar-db-migration')
4 files changed, 117 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v78/AddWebhooksSecret.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v78/AddWebhooksSecret.java new file mode 100644 index 00000000000..72b18c9c0a9 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v78/AddWebhooksSecret.java @@ -0,0 +1,47 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.v78; + +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.AddColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; + +@SupportsBlueGreen +public class AddWebhooksSecret extends DdlChange { + + public AddWebhooksSecret(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddColumnsBuilder(getDialect(), "webhooks") + .addColumn(newVarcharColumnDefBuilder() + .setColumnName("secret") + .setIsNullable(true) + .setLimit(200) + .build()) + .build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v78/DbVersion78.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v78/DbVersion78.java index 36168736d6d..41460ea4e82 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v78/DbVersion78.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v78/DbVersion78.java @@ -28,6 +28,7 @@ public class DbVersion78 implements DbVersion { public void addSteps(MigrationStepRegistry registry) { registry .add(2700, "Drop overall subscriptions on notifications about new and resolved issues", DeleteOverallSubscriptionsOnNewAndResolvedIssuesNotifications.class) - .add(2701, "Add index to org_qprofile.parent_uuid", AddIndexToOrgQProfileParentUuid.class); + .add(2701, "Add index to org_qprofile.parent_uuid", AddIndexToOrgQProfileParentUuid.class) + .add(2702, "Add column webhooks.secret", AddWebhooksSecret.class); } } diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v78/AddWebhooksSecretTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v78/AddWebhooksSecretTest.java new file mode 100644 index 00000000000..0e2e6f7081c --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v78/AddWebhooksSecretTest.java @@ -0,0 +1,55 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 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.v78; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.db.CoreDbTester; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static java.sql.Types.VARCHAR; + +public class AddWebhooksSecretTest { + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(AddWebhooksSecretTest.class, "webhooks.sql"); + + private DdlChange underTest = new AddWebhooksSecret(db.database()); + + @Test + public void creates_table_on_empty_db() throws SQLException { + underTest.execute(); + + db.assertColumnDefinition("webhooks", "secret", VARCHAR, 200, true); + } + + @Test + public void migration_is_not_reentrant() throws SQLException { + underTest.execute(); + + expectedException.expect(IllegalStateException.class); + + underTest.execute(); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v78/AddWebhooksSecretTest/webhooks.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v78/AddWebhooksSecretTest/webhooks.sql new file mode 100644 index 00000000000..f78c777760b --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v78/AddWebhooksSecretTest/webhooks.sql @@ -0,0 +1,13 @@ +CREATE TABLE "WEBHOOKS" ( + "UUID" VARCHAR(40) NOT NULL, + "NAME" VARCHAR(100) NOT NULL, + "URL" VARCHAR(2000) NOT NULL, + "ORGANIZATION_UUID" VARCHAR(40), + "PROJECT_UUID" VARCHAR(40), + "CREATED_AT" BIGINT NOT NULL, + "UPDATED_AT" BIGINT NOT NULL, + + CONSTRAINT "PK_WEBHOOKS" PRIMARY KEY ("UUID") +); +CREATE INDEX "ORGANIZATION_WEBHOOK" ON "WEBHOOKS" ("ORGANIZATION_UUID"); +CREATE INDEX "PROJECT_WEBHOOK" ON "WEBHOOKS" ("PROJECT_UUID"); |