updated_at=#{updatedAt, jdbcType=TIMESTAMP}
WHERE
uuid=#{uuid, jdbcType=VARCHAR}
+ OR
+ (project_uuid=#{projectUuid, jdbcType=VARCHAR}
+ AND
+ branch_uuid=#{branchUuid, jdbcType=VARCHAR})
</update>
<select id="selectByProject" parameterType="map" resultType="org.sonar.db.newcodeperiod.NewCodePeriodDto">
import org.sonar.db.DatabaseUtils;
import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef;
import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
import org.sonar.server.platform.db.migration.step.DdlChange;
.addColumn(UPDATED_AT)
.addColumn(CREATED_AT)
.build());
+
+ context.execute(new CreateIndexBuilder()
+ .setTable(TABLE_NAME)
+ .setName("uniq_new_code_periods")
+ .setUnique(true)
+ .addColumn(PROJECT_UUID_COLUMN)
+ .addColumn(BRANCH_UUID_COLUMN)
+ .build());
}
private boolean tableExists() throws SQLException {
dbTester.assertTableExists(TABLE_NAME);
dbTester.assertPrimaryKey(TABLE_NAME, "pk_new_code_periods", "uuid");
+ dbTester.assertUniqueIndex(TABLE_NAME, "uniq_new_code_periods", "project_uuid", "branch_uuid");
dbTester.assertColumnDefinition(TABLE_NAME, "uuid", VARCHAR, 40, false);
dbTester.assertColumnDefinition(TABLE_NAME, "project_uuid", VARCHAR, 40, true);
CONSTRAINT "PK_NEW_CODE_PERIOD" PRIMARY KEY ("UUID")
);
+CREATE UNIQUE INDEX "UNIQ_NEW_CODE_PERIODS" ON "NEW_CODE_PERIODS" ("PROJECT_UUID", "BRANCH_UUID");
+
CREATE TABLE "WEBHOOKS" (
"UUID" VARCHAR(40) NOT NULL,
"NAME" VARCHAR(100) NOT NULL,
dbClient.newCodePeriodDao().upsert(dbSession, new NewCodePeriodDto()
.setProjectUuid(projectBranch.getMainBranchProjectUuid() != null ? projectBranch.getMainBranchProjectUuid() : projectBranch.uuid())
- .setBranchUuid(branchKey != null ? projectBranch.uuid() : null)
+ .setBranchUuid(projectBranch.uuid())
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS)
.setValue(analysisUuid)
);
@Test
@UseDataProvider("nullOrEmpty")
- public void set_baseline_on_project(@Nullable String branchName) {
+ public void set_baseline_on_main_branch(@Nullable String branchName) {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.organizations().insert());
BranchDto branch = new BranchDto()
.setBranchType(BranchType.LONG)
call(project.getKey(), branchName, analysis.getUuid());
- NewCodePeriodDto loaded = dbClient.newCodePeriodDao().selectByProject(dbSession, project.uuid()).get();
+ NewCodePeriodDto loaded = dbClient.newCodePeriodDao().selectByBranch(dbSession, project.uuid(), branch.getUuid()).get();
assertThat(loaded.getValue()).isEqualTo(analysis.getUuid());
assertThat(loaded.getType()).isEqualTo(SPECIFIC_ANALYSIS);
}