forked from SonarSource/sonarqube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
to application and portfolios columns
- Loading branch information
Showing
5 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
.../server/platform/db/migration/version/v74/PopulateDefaultPermTemplateOnOrganizations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.v74; | ||
|
||
import java.sql.SQLException; | ||
import org.sonar.api.utils.System2; | ||
import org.sonar.db.Database; | ||
import org.sonar.server.platform.db.migration.SupportsBlueGreen; | ||
import org.sonar.server.platform.db.migration.step.DataChange; | ||
import org.sonar.server.platform.db.migration.step.MassUpdate; | ||
|
||
@SupportsBlueGreen | ||
public class PopulateDefaultPermTemplateOnOrganizations extends DataChange { | ||
|
||
private final System2 system2; | ||
|
||
public PopulateDefaultPermTemplateOnOrganizations(Database db, System2 system2) { | ||
super(db); | ||
this.system2 = system2; | ||
} | ||
|
||
@Override | ||
protected void execute(Context context) throws SQLException { | ||
long now = system2.now(); | ||
MassUpdate massUpdate = context.prepareMassUpdate().rowPluralName("organizations"); | ||
massUpdate.select("SELECT uuid, default_perm_template_view FROM organizations WHERE default_perm_template_view IS NOT NULL"); | ||
massUpdate.update("UPDATE organizations " + | ||
"SET default_perm_template_app=?, default_perm_template_port=?, updated_at=? " + | ||
"WHERE uuid=?"); | ||
massUpdate.execute((row, update) -> { | ||
String uuid = row.getString(1); | ||
String defaultPermTemplateView = row.getString(2); | ||
update.setString(1, defaultPermTemplateView); | ||
update.setString(2, defaultPermTemplateView); | ||
update.setLong(3, now); | ||
update.setString(4, uuid); | ||
return true; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...ver/platform/db/migration/version/v74/PopulateDefaultPermTemplateOnOrganizationsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* 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.v74; | ||
|
||
import java.sql.SQLException; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nullable; | ||
import org.assertj.core.groups.Tuple; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.sonar.api.utils.System2; | ||
import org.sonar.api.utils.internal.TestSystem2; | ||
import org.sonar.db.CoreDbTester; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.tuple; | ||
|
||
public class PopulateDefaultPermTemplateOnOrganizationsTest { | ||
|
||
private final static long PAST = 10_000_000_000L; | ||
private final static long NOW = 50_000_000_000L; | ||
|
||
@Rule | ||
public ExpectedException expectedException = ExpectedException.none(); | ||
@Rule | ||
public CoreDbTester db = CoreDbTester.createForSchema(PopulateDefaultPermTemplateOnOrganizationsTest.class, "organizations.sql"); | ||
private System2 system2 = new TestSystem2().setNow(NOW); | ||
|
||
private PopulateDefaultPermTemplateOnOrganizations underTest = new PopulateDefaultPermTemplateOnOrganizations(db.database(), system2); | ||
|
||
@Test | ||
public void test_is_reentrant() throws SQLException { | ||
insertOrganization("aa", "aa-1"); | ||
insertOrganization("bb", null); | ||
underTest.execute(); | ||
underTest.execute(); | ||
|
||
assertOrganizations( | ||
tuple("aa", "aa-1", "aa-1", "aa-1", NOW), | ||
tuple("bb", null, null, null, PAST) | ||
); | ||
} | ||
|
||
@Test | ||
public void test_with_organizations() throws SQLException { | ||
insertOrganization("aa", "aa-1"); | ||
insertOrganization("bb", "bb-1"); | ||
insertOrganization("cc", null); | ||
|
||
underTest.execute(); | ||
|
||
assertOrganizations( | ||
tuple("aa", "aa-1", "aa-1", "aa-1", NOW), | ||
tuple("bb", "bb-1", "bb-1", "bb-1", NOW), | ||
tuple("cc", null, null, null, PAST) | ||
); | ||
} | ||
|
||
@Test | ||
public void without_governance_no_modifications() throws SQLException { | ||
insertOrganization("default-organization", null); | ||
|
||
underTest.execute(); | ||
|
||
assertOrganizations( | ||
tuple("default-organization", null, null, null, PAST) | ||
); | ||
} | ||
|
||
private void assertOrganizations(Tuple... expectedTuples) { | ||
assertThat(db.select("SELECT uuid, default_perm_template_view, default_perm_template_app, default_perm_template_port, updated_at FROM organizations") | ||
.stream() | ||
.map(row -> new Tuple(row.get("UUID"), row.get("DEFAULT_PERM_TEMPLATE_VIEW"), row.get("DEFAULT_PERM_TEMPLATE_APP"), row.get("DEFAULT_PERM_TEMPLATE_PORT"), row.get("UPDATED_AT"))) | ||
.collect(Collectors.toList())) | ||
.containsExactlyInAnyOrder(expectedTuples); | ||
} | ||
|
||
private void insertOrganization(String uuid, @Nullable String defaultPermTemplateView) { | ||
db.executeInsert("ORGANIZATIONS", | ||
"UUID", uuid, | ||
"KEE", uuid, | ||
"NAME", uuid, | ||
"GUARDED", false, | ||
"DEFAULT_PERM_TEMPLATE_VIEW", defaultPermTemplateView, | ||
"DEFAULT_QUALITY_GATE_UUID", "111", | ||
"NEW_PROJECT_PRIVATE", false, | ||
"SUBSCRIPTION", "sonarqube", | ||
"CREATED_AT", PAST, | ||
"UPDATED_AT", PAST); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...db/migration/version/v74/PopulateDefaultPermTemplateOnOrganizationsTest/organizations.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CREATE TABLE "ORGANIZATIONS" ( | ||
"UUID" VARCHAR(40) NOT NULL, | ||
"KEE" VARCHAR(32) NOT NULL, | ||
"NAME" VARCHAR(64) NOT NULL, | ||
"DESCRIPTION" VARCHAR(256), | ||
"URL" VARCHAR(256), | ||
"AVATAR_URL" VARCHAR(256), | ||
"GUARDED" BOOLEAN NOT NULL, | ||
"DEFAULT_PERM_TEMPLATE_PROJECT" VARCHAR(40), | ||
"DEFAULT_PERM_TEMPLATE_VIEW" VARCHAR(40), | ||
"DEFAULT_PERM_TEMPLATE_APP" VARCHAR(40), | ||
"DEFAULT_PERM_TEMPLATE_PORT" VARCHAR(40), | ||
"DEFAULT_GROUP_ID" INTEGER, | ||
"DEFAULT_QUALITY_GATE_UUID" VARCHAR(40) NOT NULL, | ||
"NEW_PROJECT_PRIVATE" BOOLEAN NOT NULL, | ||
"SUBSCRIPTION" VARCHAR(40) NOT NULL, | ||
"CREATED_AT" BIGINT NOT NULL, | ||
"UPDATED_AT" BIGINT NOT NULL, | ||
|
||
CONSTRAINT "PK_ORGANIZATIONS" PRIMARY KEY ("UUID") | ||
); | ||
CREATE UNIQUE INDEX "ORGANIZATION_KEY" ON "ORGANIZATIONS" ("KEE"); |