@@ -90,6 +90,8 @@ public class BranchDto { | |||
private boolean excludeFromPurge; | |||
private boolean needIssueSync = false; | |||
public String getUuid() { | |||
return uuid; | |||
} | |||
@@ -200,6 +202,14 @@ public class BranchDto { | |||
} | |||
} | |||
public boolean isNeedIssueSync() { | |||
return needIssueSync; | |||
} | |||
public void setNeedIssueSync(boolean needIssueSync) { | |||
this.needIssueSync = needIssueSync; | |||
} | |||
@Override | |||
public boolean equals(Object o) { | |||
if (this == o) { | |||
@@ -213,12 +223,13 @@ public class BranchDto { | |||
Objects.equals(projectUuid, branchDto.projectUuid) && | |||
Objects.equals(kee, branchDto.kee) && | |||
branchType == branchDto.branchType && | |||
Objects.equals(mergeBranchUuid, branchDto.mergeBranchUuid); | |||
Objects.equals(mergeBranchUuid, branchDto.mergeBranchUuid) && | |||
needIssueSync == branchDto.needIssueSync; | |||
} | |||
@Override | |||
public int hashCode() { | |||
return Objects.hash(uuid, projectUuid, kee, branchType, mergeBranchUuid); | |||
return Objects.hash(uuid, projectUuid, kee, branchType, mergeBranchUuid, needIssueSync); | |||
} | |||
@Override | |||
@@ -231,6 +242,7 @@ public class BranchDto { | |||
", branchType=" + branchType + | |||
", mergeBranchUuid='" + mergeBranchUuid + '\'' + | |||
", excludeFromPurge=" + excludeFromPurge + | |||
", needIssueSync=" + needIssueSync + | |||
'}'; | |||
} | |||
} |
@@ -10,32 +10,35 @@ | |||
pb.branch_type as branchType, | |||
pb.merge_branch_uuid as mergeBranchUuid, | |||
pb.pull_request_binary as pullRequestBinary, | |||
pb.exclude_from_purge as excludeFromPurge | |||
pb.exclude_from_purge as excludeFromPurge, | |||
pb.need_issue_sync as needIssueSync | |||
</sql> | |||
<insert id="insert" parameterType="map" useGeneratedKeys="false"> | |||
insert into project_branches ( | |||
uuid, | |||
project_uuid, | |||
kee, | |||
key_type, | |||
branch_type, | |||
merge_branch_uuid, | |||
pull_request_binary, | |||
created_at, | |||
updated_at, | |||
exclude_from_purge | |||
uuid, | |||
project_uuid, | |||
kee, | |||
key_type, | |||
branch_type, | |||
merge_branch_uuid, | |||
pull_request_binary, | |||
created_at, | |||
updated_at, | |||
exclude_from_purge, | |||
need_issue_sync | |||
) values ( | |||
#{dto.uuid, jdbcType=VARCHAR}, | |||
#{dto.projectUuid, jdbcType=VARCHAR}, | |||
#{dto.kee, jdbcType=VARCHAR}, | |||
#{dto.keyType, jdbcType=VARCHAR}, | |||
#{dto.branchType, jdbcType=VARCHAR}, | |||
#{dto.mergeBranchUuid, jdbcType=VARCHAR}, | |||
#{dto.pullRequestBinary, jdbcType=BINARY}, | |||
#{now, jdbcType=BIGINT}, | |||
#{now, jdbcType=BIGINT}, | |||
#{dto.excludeFromPurge, jdbcType=BOOLEAN} | |||
#{dto.uuid, jdbcType=VARCHAR}, | |||
#{dto.projectUuid, jdbcType=VARCHAR}, | |||
#{dto.kee, jdbcType=VARCHAR}, | |||
#{dto.keyType, jdbcType=VARCHAR}, | |||
#{dto.branchType, jdbcType=VARCHAR}, | |||
#{dto.mergeBranchUuid, jdbcType=VARCHAR}, | |||
#{dto.pullRequestBinary, jdbcType=BINARY}, | |||
#{now, jdbcType=BIGINT}, | |||
#{now, jdbcType=BIGINT}, | |||
#{dto.excludeFromPurge, jdbcType=BOOLEAN}, | |||
#{dto.needIssueSync, jdbcType=BOOLEAN} | |||
) | |||
</insert> | |||
@@ -643,7 +643,8 @@ CREATE TABLE "PROJECT_BRANCHES"( | |||
"MANUAL_BASELINE_ANALYSIS_UUID" VARCHAR(40), | |||
"CREATED_AT" BIGINT NOT NULL, | |||
"UPDATED_AT" BIGINT NOT NULL, | |||
"EXCLUDE_FROM_PURGE" BOOLEAN DEFAULT FALSE NOT NULL | |||
"EXCLUDE_FROM_PURGE" BOOLEAN DEFAULT FALSE NOT NULL, | |||
"NEED_ISSUE_SYNC" BOOLEAN NOT NULL | |||
); | |||
ALTER TABLE "PROJECT_BRANCHES" ADD CONSTRAINT "PK_PROJECT_BRANCHES" PRIMARY KEY("UUID"); | |||
CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE_KEY_TYPE" ON "PROJECT_BRANCHES"("PROJECT_UUID", "KEE", "KEY_TYPE"); |
@@ -59,7 +59,7 @@ public class BranchDtoTest { | |||
underTest.setExcludeFromPurge(true); | |||
assertThat(underTest.toString()).isEqualTo("BranchDto{uuid='U1', " + | |||
"projectUuid='U2', kee='K1', keyType=null, branchType=BRANCH, mergeBranchUuid='U3', excludeFromPurge=true}"); | |||
"projectUuid='U2', kee='K1', keyType=null, branchType=BRANCH, mergeBranchUuid='U3', excludeFromPurge=true, needIssueSync=false}"); | |||
} | |||
@Test |
@@ -0,0 +1,43 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v84; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.def.BooleanColumnDef; | |||
import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
public class AddProjectBranchesNeedIssueSync extends DdlChange { | |||
public AddProjectBranchesNeedIssueSync(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
context.execute(new AddColumnsBuilder(getDialect(), "project_branches") | |||
.addColumn(BooleanColumnDef.newBooleanColumnDefBuilder() | |||
.setColumnName("need_issue_sync") | |||
.setIsNullable(true) | |||
.setDefaultValue(null) | |||
.build()) | |||
.build()); | |||
} | |||
} |
@@ -776,6 +776,10 @@ public class DbVersion84 implements DbVersion { | |||
.add(3800, "Remove favourites for components with qualifiers 'DIR', 'FIL', 'UTS'", RemoveFilesFavouritesFromProperties.class) | |||
.add(3801, "Create 'SESSION_TOKENS' table", CreateSessionTokensTable.class) | |||
.add(3802, "Create 'SAML_MESSAGE_IDS' table", CreateSamlMessageIdsTable.class) | |||
.add(3803, "Add 'need_issue_sync' column to 'project_branches' table", AddProjectBranchesNeedIssueSync.class) | |||
.add(3804, "Populate 'need_issue_sync' of 'project_branches'", PopulateProjectBranchesNeedIssueSync.class) | |||
.add(3805, "Make 'need_issue_sync' of 'project_branches' not null", MakeProjectBranchesNeedIssueSyncNonNull.class) | |||
; | |||
} | |||
} |
@@ -0,0 +1,43 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v84; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.def.BooleanColumnDef; | |||
import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
public class MakeProjectBranchesNeedIssueSyncNonNull extends DdlChange { | |||
public MakeProjectBranchesNeedIssueSyncNonNull(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
context.execute(new AlterColumnsBuilder(getDialect(), "project_branches") | |||
.updateColumn(BooleanColumnDef.newBooleanColumnDefBuilder() | |||
.setColumnName("need_issue_sync") | |||
.setIsNullable(false) | |||
.setDefaultValue(null) | |||
.build()) | |||
.build()); | |||
} | |||
} |
@@ -0,0 +1,44 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v84; | |||
import java.sql.SQLException; | |||
import org.sonar.db.Database; | |||
import org.sonar.server.platform.db.migration.step.DataChange; | |||
import org.sonar.server.platform.db.migration.step.MassUpdate; | |||
public class PopulateProjectBranchesNeedIssueSync extends DataChange { | |||
public PopulateProjectBranchesNeedIssueSync(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
protected void execute(Context context) throws SQLException { | |||
MassUpdate massUpdate = context.prepareMassUpdate(); | |||
massUpdate.select("select uuid from project_branches where need_issue_sync is null"); | |||
massUpdate.update("update project_branches set need_issue_sync = ? where uuid = ?"); | |||
massUpdate.execute((row, update) -> { | |||
String uuid = row.getString(1); | |||
update.setBoolean(1, false); | |||
update.setString(2, uuid); | |||
return true; | |||
}); | |||
} | |||
} |
@@ -21,7 +21,6 @@ package org.sonar.server.platform.db.migration.version.v83; | |||
import org.junit.Test; | |||
import org.sonar.server.platform.db.migration.version.DbVersion; | |||
import org.sonar.server.platform.db.migration.version.v84.DbVersion84; | |||
import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationNotEmpty; | |||
import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber; |
@@ -0,0 +1,66 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v84; | |||
import java.sql.SQLException; | |||
import java.sql.Types; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.db.CoreDbTester; | |||
import org.sonar.server.platform.db.migration.step.DdlChange; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class AddProjectBranchesNeedIssueSyncTest { | |||
@Rule | |||
public CoreDbTester db = CoreDbTester.createForSchema(AddProjectBranchesNeedIssueSyncTest.class, "schema.sql"); | |||
private DdlChange underTest = new AddProjectBranchesNeedIssueSync(db.database()); | |||
@Before | |||
public void setup() { | |||
insertProjectBranches("uuid-1"); | |||
insertProjectBranches("uuid-2"); | |||
insertProjectBranches("uuid-3"); | |||
} | |||
@Test | |||
public void add_need_issue_sync_column_to_project_branches() throws SQLException { | |||
underTest.execute(); | |||
db.assertColumnDefinition("project_branches", "need_issue_sync", Types.BOOLEAN, null, true); | |||
assertThat(db.countSql("select count(uuid) from project_branches")) | |||
.isEqualTo(3); | |||
} | |||
private void insertProjectBranches(String uuid) { | |||
db.executeInsert("project_branches", | |||
"uuid", uuid, | |||
"project_uuid", "name", | |||
"kee", uuid, | |||
"key_type", "KEY_TYPE", | |||
"created_at", System.currentTimeMillis(), | |||
"updated_at", System.currentTimeMillis(), | |||
"exclude_from_purge", false); | |||
} | |||
} |
@@ -0,0 +1,43 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v84; | |||
import java.sql.SQLException; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.db.CoreDbTester; | |||
import org.sonar.server.platform.db.migration.step.MigrationStep; | |||
import static java.sql.Types.BOOLEAN; | |||
public class MakeProjectBranchesNeedIssueSyncNonNullTest { | |||
@Rule | |||
public CoreDbTester db = CoreDbTester.createForSchema(MakeProjectBranchesNeedIssueSyncNonNullTest.class, "schema.sql"); | |||
private MigrationStep underTest = new MakeProjectBranchesNeedIssueSyncNonNull(db.database()); | |||
@Test | |||
public void uuid_column_is_not_null() throws SQLException { | |||
underTest.execute(); | |||
db.assertColumnDefinition("project_branches", "need_issue_sync", BOOLEAN, null, false); | |||
} | |||
} |
@@ -0,0 +1,75 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2020 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.v84; | |||
import java.sql.SQLException; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.db.CoreDbTester; | |||
import org.sonar.server.platform.db.migration.step.DataChange; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class PopulateProjectBranchesNeedIssueSyncTest { | |||
@Rule | |||
public CoreDbTester db = CoreDbTester.createForSchema(PopulateProjectBranchesNeedIssueSyncTest.class, "schema.sql"); | |||
private DataChange underTest = new PopulateProjectBranchesNeedIssueSync(db.database()); | |||
@Test | |||
public void populate_need_issue_sync() throws SQLException { | |||
insertProjectBranches("uuid-1"); | |||
insertProjectBranches("uuid-2"); | |||
insertProjectBranches("uuid-3"); | |||
underTest.execute(); | |||
verifyNeedIssueSyncIsNotNull(); | |||
} | |||
@Test | |||
public void migration_is_reentrant() throws SQLException { | |||
insertProjectBranches("uuid-1"); | |||
insertProjectBranches("uuid-2"); | |||
insertProjectBranches("uuid-3"); | |||
underTest.execute(); | |||
// re-entrant | |||
underTest.execute(); | |||
verifyNeedIssueSyncIsNotNull(); | |||
} | |||
private void verifyNeedIssueSyncIsNotNull() { | |||
assertThat(db.select("select need_issue_sync from project_branches where need_issue_sync is null")).isEmpty(); | |||
} | |||
private void insertProjectBranches(String uuid) { | |||
db.executeInsert("project_branches", | |||
"uuid", uuid, | |||
"project_uuid", "name", | |||
"kee", uuid, | |||
"key_type", "KEY_TYPE", | |||
"created_at", System.currentTimeMillis(), | |||
"updated_at", System.currentTimeMillis(), | |||
"exclude_from_purge", false); | |||
} | |||
} |
@@ -0,0 +1,15 @@ | |||
CREATE TABLE "PROJECT_BRANCHES"( | |||
"UUID" VARCHAR(50) NOT NULL, | |||
"PROJECT_UUID" VARCHAR(50) NOT NULL, | |||
"KEE" VARCHAR(255) NOT NULL, | |||
"BRANCH_TYPE" VARCHAR(12), | |||
"MERGE_BRANCH_UUID" VARCHAR(50), | |||
"KEY_TYPE" VARCHAR(12) NOT NULL, | |||
"PULL_REQUEST_BINARY" BLOB, | |||
"MANUAL_BASELINE_ANALYSIS_UUID" VARCHAR(40), | |||
"CREATED_AT" BIGINT NOT NULL, | |||
"UPDATED_AT" BIGINT NOT NULL, | |||
"EXCLUDE_FROM_PURGE" BOOLEAN DEFAULT FALSE NOT NULL | |||
); | |||
ALTER TABLE "PROJECT_BRANCHES" ADD CONSTRAINT "PK_PROJECT_BRANCHES" PRIMARY KEY("UUID"); | |||
CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE_KEY_TYPE" ON "PROJECT_BRANCHES"("PROJECT_UUID", "KEE", "KEY_TYPE"); |
@@ -0,0 +1,16 @@ | |||
CREATE TABLE "PROJECT_BRANCHES"( | |||
"UUID" VARCHAR(50) NOT NULL, | |||
"PROJECT_UUID" VARCHAR(50) NOT NULL, | |||
"KEE" VARCHAR(255) NOT NULL, | |||
"BRANCH_TYPE" VARCHAR(12), | |||
"MERGE_BRANCH_UUID" VARCHAR(50), | |||
"KEY_TYPE" VARCHAR(12) NOT NULL, | |||
"PULL_REQUEST_BINARY" BLOB, | |||
"MANUAL_BASELINE_ANALYSIS_UUID" VARCHAR(40), | |||
"CREATED_AT" BIGINT NOT NULL, | |||
"UPDATED_AT" BIGINT NOT NULL, | |||
"EXCLUDE_FROM_PURGE" BOOLEAN DEFAULT FALSE NOT NULL, | |||
"NEED_ISSUE_SYNC" BOOLEAN | |||
); | |||
ALTER TABLE "PROJECT_BRANCHES" ADD CONSTRAINT "PK_PROJECT_BRANCHES" PRIMARY KEY("UUID"); | |||
CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE_KEY_TYPE" ON "PROJECT_BRANCHES"("PROJECT_UUID", "KEE", "KEY_TYPE"); |
@@ -0,0 +1,16 @@ | |||
CREATE TABLE "PROJECT_BRANCHES"( | |||
"UUID" VARCHAR(50) NOT NULL, | |||
"PROJECT_UUID" VARCHAR(50) NOT NULL, | |||
"KEE" VARCHAR(255) NOT NULL, | |||
"BRANCH_TYPE" VARCHAR(12), | |||
"MERGE_BRANCH_UUID" VARCHAR(50), | |||
"KEY_TYPE" VARCHAR(12) NOT NULL, | |||
"PULL_REQUEST_BINARY" BLOB, | |||
"MANUAL_BASELINE_ANALYSIS_UUID" VARCHAR(40), | |||
"CREATED_AT" BIGINT NOT NULL, | |||
"UPDATED_AT" BIGINT NOT NULL, | |||
"EXCLUDE_FROM_PURGE" BOOLEAN DEFAULT FALSE NOT NULL, | |||
"NEED_ISSUE_SYNC" BOOLEAN | |||
); | |||
ALTER TABLE "PROJECT_BRANCHES" ADD CONSTRAINT "PK_PROJECT_BRANCHES" PRIMARY KEY("UUID"); | |||
CREATE UNIQUE INDEX "PROJECT_BRANCHES_KEE_KEY_TYPE" ON "PROJECT_BRANCHES"("PROJECT_UUID", "KEE", "KEY_TYPE"); |