aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java8
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java7
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepIT.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java5
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepIT.java2
-rw-r--r--server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepIT.java4
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java3
-rw-r--r--server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java17
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java9
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java9
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml4
-rw-r--r--server/sonar-db-dao/src/schema/schema-sq.ddl2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java4
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java4
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponents.java52
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java6
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponents.java33
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponents.java79
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponents.java34
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponentsTest.java52
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponentsTest.java52
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java4
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest.java2
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponentsTest.java81
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponentsTest.java57
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponentsTest/schema.sql33
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponentsTest/schema.sql34
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponentsTest/schema.sql34
-rw-r--r--server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponentsTest/schema.sql33
-rw-r--r--server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java2
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java3
31 files changed, 622 insertions, 49 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java
index 7dd7d3449c9..d5b47e09c45 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepIT.java
@@ -75,14 +75,14 @@ public class ReportPersistComponentsStepIT extends BaseStepTest {
private final System2 system2 = mock(System2.class);
private final DbClient dbClient = db.getDbClient();
- private Date now;
+ private Long now;
private final MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS);
private PersistComponentsStep underTest;
@Before
public void setup() throws Exception {
- now = DATE_FORMAT.parse("2015-06-02");
- when(system2.now()).thenReturn(now.getTime());
+ now = DATE_FORMAT.parse("2015-06-02").getTime();
+ when(system2.now()).thenReturn(now);
BranchPersister branchPersister = mock(BranchPersister.class);
ProjectPersister projectPersister = mock(ProjectPersister.class);
@@ -365,7 +365,7 @@ public class ReportPersistComponentsStepIT extends BaseStepTest {
@Test
public void do_not_update_created_at_on_existing_component() {
Date oldDate = DateUtils.parseDate("2015-01-01");
- ComponentDto project = prepareProject(p -> p.setCreatedAt(oldDate));
+ ComponentDto project = prepareProject(p -> p.setCreatedAt(oldDate.getTime()));
db.getSession().commit();
treeRootHolder.setRoot(
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java
index 1972a83bb76..cadcb2bcd30 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepIT.java
@@ -20,7 +20,6 @@
package org.sonar.ce.task.projectanalysis.step;
import java.text.SimpleDateFormat;
-import java.util.Date;
import java.util.Random;
import java.util.stream.Stream;
import javax.annotation.Nullable;
@@ -88,14 +87,14 @@ public class ViewsPersistComponentsStepIT extends BaseStepTest {
private final System2 system2 = mock(System2.class);
private final DbClient dbClient = dbTester.getDbClient();
- private Date now;
+ private Long now;
private final MutableDisabledComponentsHolder disabledComponentsHolder = mock(MutableDisabledComponentsHolder.class, RETURNS_DEEP_STUBS);
private PersistComponentsStep underTest;
@Before
public void setup() throws Exception {
- now = DATE_FORMAT.parse("2015-06-02");
- when(system2.now()).thenReturn(now.getTime());
+ now = DATE_FORMAT.parse("2015-06-02").getTime();
+ when(system2.now()).thenReturn(now);
analysisMetadataHolder.setBranch(new DefaultBranchImpl(DEFAULT_MAIN_BRANCH_NAME));
BranchPersister branchPersister = mock(BranchPersister.class);
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepIT.java
index 9c82b10856b..bf3cee58ff1 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepIT.java
@@ -98,7 +98,7 @@ public class ExportBranchesStepIT {
ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
for (BranchDto branch : branches) {
createdAt = DateUtils.addMinutes(createdAt, 10);
- dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt);
+ dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt.getTime());
}
dbTester.commit();
when(projectHolder.projectDto()).thenReturn(projectData.getProjectDto());
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java
index 67a2285b2f5..23f48449e76 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/component/ExportComponentsStepIT.java
@@ -21,7 +21,6 @@ package org.sonar.ce.task.projectexport.component;
import com.google.common.collect.ImmutableSet;
import com.sonarsource.governance.projectdump.protobuf.ProjectDump;
-import java.util.Date;
import java.util.List;
import org.junit.After;
import org.junit.Before;
@@ -60,7 +59,7 @@ public class ExportComponentsStepIT {
.setEnabled(true)
.setUuid(PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
- .setCreatedAt(new Date(1596749115856L))
+ .setCreatedAt(1596749115856L)
.setBranchUuid(PROJECT_UUID);
private static final String FILE_UUID = "FILE_UUID";
@@ -74,7 +73,7 @@ public class ExportComponentsStepIT {
.setUuid(FILE_UUID)
.setUuidPath(FILE_UUID_PATH)
.setEnabled(true)
- .setCreatedAt(new Date(1596749148406L))
+ .setCreatedAt(1596749148406L)
.setBranchUuid(PROJECT_UUID);
@Rule
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepIT.java
index 0490a7dd965..664b31644bc 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/rule/ExportAdHocRulesStepIT.java
@@ -164,7 +164,7 @@ public class ExportAdHocRulesStepIT {
Date createdAt = new Date();
ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
mainBranch = projectData.getMainBranchComponent();
- BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt));
+ BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt.getTime()));
dbTester.commit();
return projectData.getProjectDto();
}
diff --git a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepIT.java b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepIT.java
index 02e7f87db13..7ab96648179 100644
--- a/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepIT.java
+++ b/server/sonar-ce-task-projectanalysis/src/it/java/org/sonar/ce/task/projectexport/steps/ExportNewCodePeriodsStepIT.java
@@ -86,10 +86,10 @@ public class ExportNewCodePeriodsStepIT {
logTester.setLevel(Level.DEBUG);
Date createdAt = new Date();
project = dbTester.components().insertPrivateProject(PROJECT_UUID).getProjectDto();
- PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(project, branch).setCreatedAt(createdAt));
+ PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(project, branch).setCreatedAt(createdAt.getTime()));
ComponentDto anotherProjectDto = dbTester.components().insertPublicProject(ANOTHER_PROJECT).getMainBranchComponent();
- ANOTHER_PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(anotherProjectDto, branch).setCreatedAt(createdAt));
+ ANOTHER_PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(anotherProjectDto, branch).setCreatedAt(createdAt.getTime()));
dbTester.commit();
projectHolder.setProjectDto(project);
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
index 21b4d1dfbf5..f9f1d6e30e7 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
@@ -20,7 +20,6 @@
package org.sonar.ce.task.projectanalysis.step;
import java.util.Collection;
-import java.util.Date;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -331,7 +330,7 @@ public class PersistComponentsStep implements ComputationStep {
componentDto.setUuid(componentUuid);
componentDto.setKey(componentKey);
componentDto.setEnabled(true);
- componentDto.setCreatedAt(new Date(system2.now()));
+ componentDto.setCreatedAt(system2.now());
return componentDto;
}
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
index 2299f88c60f..2131e1b0cef 100644
--- a/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
+++ b/server/sonar-db-dao/src/it/java/org/sonar/db/component/ComponentDaoIT.java
@@ -24,7 +24,6 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -987,9 +986,9 @@ public class ComponentDaoIT {
@Test
public void selectByQuery_verify_order() {
- Date firstDate = new Date(system2.now());
- Date secondDate = new Date(system2.now());
- Date thirdDate = new Date(system2.now());
+ Long firstDate = system2.now();
+ Long secondDate = system2.now();
+ Long thirdDate = system2.now();
ComponentDto project3 = db.components().insertPrivateProject(componentDto -> componentDto.setName("project3").setCreatedAt(thirdDate)).getMainBranchComponent();
ComponentDto project1 = db.components().insertPrivateProject(componentDto -> componentDto.setName("project1").setCreatedAt(firstDate)).getMainBranchComponent();
@@ -1364,15 +1363,15 @@ public class ComponentDaoIT {
@Test
public void selectByQuery_filter_created_at() {
- ComponentDto project1 = db.components().insertPrivateProject(p -> p.setCreatedAt(parseDate("2018-02-01"))).getMainBranchComponent();
- ComponentDto project2 = db.components().insertPrivateProject(p -> p.setCreatedAt(parseDate("2018-06-01"))).getMainBranchComponent();
+ ComponentDto project1 = db.components().insertPrivateProject(p -> p.setCreatedAt(parseDate("2018-02-01").getTime())).getMainBranchComponent();
+ ComponentDto project2 = db.components().insertPrivateProject(p -> p.setCreatedAt(parseDate("2018-06-01").getTime())).getMainBranchComponent();
- assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2017-12-01"))))
+ assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2017-12-01").getTime())))
.containsExactlyInAnyOrder(project1.uuid(), project2.uuid());
- assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2018-02-20"))))
+ assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2018-02-20").getTime())))
.containsExactlyInAnyOrder(project2.uuid());
- assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2019-01-01"))))
+ assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2019-01-01").getTime())))
.isEmpty();
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
index 2cf4f9dec67..9cc41cad9e3 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDto.java
@@ -21,7 +21,6 @@ package org.sonar.db.component;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
-import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckForNull;
@@ -98,7 +97,7 @@ public class ComponentDto {
private boolean enabled = true;
private boolean isPrivate = false;
- private Date createdAt;
+ private Long createdAt;
public static String formatUuidPathFromParent(ComponentDto parent) {
checkArgument(!Strings.isNullOrEmpty(parent.getUuidPath()));
@@ -245,12 +244,12 @@ public class ComponentDto {
return this;
}
- public Date getCreatedAt() {
+ public Long getCreatedAt() {
return createdAt;
}
- public ComponentDto setCreatedAt(Date datetime) {
- this.createdAt = datetime;
+ public ComponentDto setCreatedAt(Long createdAt) {
+ this.createdAt = createdAt;
return this;
}
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java
index 7baf5d3c409..c71729ace88 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentQuery.java
@@ -19,7 +19,6 @@
*/
package org.sonar.db.component;
-import java.util.Date;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Stream;
@@ -41,7 +40,7 @@ public class ComponentQuery {
private final Long anyBranchAnalyzedBefore;
private final Long anyBranchAnalyzedAfter;
private final Long allBranchesAnalyzedBefore;
- private final Date createdAfter;
+ private final Long createdAfter;
private final boolean onProvisionedOnly;
private ComponentQuery(Builder builder) {
@@ -119,7 +118,7 @@ public class ComponentQuery {
}
@CheckForNull
- public Date getCreatedAfter() {
+ public Long getCreatedAfter() {
return createdAfter;
}
@@ -147,7 +146,7 @@ public class ComponentQuery {
private Long anyBranchAnalyzedBefore;
private Long anyBranchAnalyzedAfter;
private Long allBranchesAnalyzedBefore;
- private Date createdAfter;
+ private Long createdAfter;
private boolean onProvisionedOnly = false;
public Builder setNameOrKeyQuery(@Nullable String nameOrKeyQuery) {
@@ -208,7 +207,7 @@ public class ComponentQuery {
return this;
}
- public Builder setCreatedAfter(@Nullable Date l) {
+ public Builder setCreatedAfter(@Nullable Long l) {
this.createdAfter = l;
return this;
}
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index e55f64f3fde..795916561fe 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -343,7 +343,7 @@
)
</if>
<if test="query.createdAfter != null">
- and p.created_at &gt;= #{query.createdAfter,jdbcType=TIMESTAMP}
+ and p.created_at &gt;= #{query.createdAfter,jdbcType=BIGINT}
</if>
</sql>
@@ -539,7 +539,7 @@
#{path,jdbcType=VARCHAR},
#{copyComponentUuid,jdbcType=VARCHAR},
#{enabled,jdbcType=BOOLEAN},
- #{createdAt,jdbcType=TIMESTAMP},
+ #{createdAt,jdbcType=BIGINT},
${_false},
null,
null,
diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl
index b043cd08d28..f09fbe6fb2d 100644
--- a/server/sonar-db-dao/src/schema/schema-sq.ddl
+++ b/server/sonar-db-dao/src/schema/schema-sq.ddl
@@ -226,7 +226,7 @@ CREATE TABLE "COMPONENTS"(
"B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
"B_PATH" CHARACTER VARYING(2000),
"B_UUID_PATH" CHARACTER VARYING(1500),
- "CREATED_AT" TIMESTAMP
+ "CREATED_AT" BIGINT
);
CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java
index ced666d7df6..a2a6d7ea364 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentQueryTest.java
@@ -38,7 +38,7 @@ public class ComponentQueryTest {
.setNameOrKeyQuery("key")
.setAnyBranchAnalyzedBefore(100L)
.setAnyBranchAnalyzedAfter(200L)
- .setCreatedAfter(new Date(300L))
+ .setCreatedAfter(new Date(300L).getTime())
.setQualifiers(PROJECT)
.build();
@@ -46,7 +46,7 @@ public class ComponentQueryTest {
assertThat(underTest.getQualifiers()).containsOnly(PROJECT);
assertThat(underTest.getAnyBranchAnalyzedBefore()).isEqualTo(100L);
assertThat(underTest.getAnyBranchAnalyzedAfter()).isEqualTo(200L);
- assertThat(underTest.getCreatedAfter().getTime()).isEqualTo(300L);
+ assertThat(underTest.getCreatedAfter()).isEqualTo(300L);
assertThat(underTest.isOnProvisionedOnly()).isFalse();
assertThat(underTest.isPartialMatchOnKey()).isFalse();
assertThat(underTest.hasEmptySetOfComponents()).isFalse();
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
index cf638ea7a4d..275d75ba575 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
@@ -68,7 +68,7 @@ public class ComponentTesting {
.setBranchUuid(branch.branchUuid())
.setQualifier(Qualifiers.FILE)
.setPath(path)
- .setCreatedAt(new Date())
+ .setCreatedAt(new Date().getTime())
.setLanguage("xoo");
}
@@ -214,7 +214,7 @@ public class ComponentTesting {
.setUuidPath(formatUuidPathFromParent(parent))
.setKey(uuid)
.setBranchUuid(branch.branchUuid())
- .setCreatedAt(new Date())
+ .setCreatedAt(new Date().getTime())
.setEnabled(true)
.setPrivate(branch.isPrivate());
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponents.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponents.java
new file mode 100644
index 00000000000..36299857a76
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponents.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef;
+import org.sonar.server.platform.db.migration.def.ColumnDef;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class AddCreatedAtTempInComponents extends DdlChange {
+
+ private static final String TABLE_NAME = "components";
+ private static final String COLUMN_NAME = "created_at_temp";
+
+ public AddCreatedAtTempInComponents(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ if (!DatabaseUtils.tableColumnExists(connection, TABLE_NAME, COLUMN_NAME)) {
+ ColumnDef columnDef = BigIntegerColumnDef.newBigIntegerColumnDefBuilder()
+ .setColumnName(COLUMN_NAME)
+ .setIsNullable(true)
+ .build();
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE_NAME).addColumn(columnDef).build());
+ }
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
index a8ba7cb1915..491e15e7e5c 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DbVersion102.java
@@ -75,7 +75,13 @@ public class DbVersion102 implements DbVersion {
.add(10_2_022, "Populate 'purged' column in 'snapshots' table", PopulatePurgedColumnInSnapshots.class)
.add(10_2_023, "Make 'purged' column not nullable in 'snapshots' table", MakePurgedColumnNotNullableInSnapshots.class)
.add(10_2_024, "Drop 'purge_status' column in 'snapshots' table", DropPurgeStatusColumnInSnapshots.class)
+
.add(10_2_025, "Rename 'build_date' in 'snapshots' table to 'analysis_date", RenameBuildDateInSnapshots.class)
+
+ .add(10_2_026, "Add column 'created_at_temp' in 'components' table", AddCreatedAtTempInComponents.class)
+ .add(10_2_027, "Populate column 'created_at_temp' in 'components' table", PopulateCreatedAtTempInComponents.class)
+ .add(10_2_028, "Drop column 'created_at' in 'components' table", DropCreatedAtInComponents.class)
+ .add(10_2_029, "Rename column 'created_at_temp' to 'created_at' in 'components' table", RenameCreatedAtTempInComponents.class)
;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponents.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponents.java
new file mode 100644
index 00000000000..9ed21688e12
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponents.java
@@ -0,0 +1,33 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DropColumnChange;
+
+class DropCreatedAtInComponents extends DropColumnChange {
+
+ static final String TABLE_NAME = "components";
+ static final String COLUMN_NAME = "created_at";
+
+ public DropCreatedAtInComponents(Database db) {
+ super(db, TABLE_NAME, COLUMN_NAME);
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponents.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponents.java
new file mode 100644
index 00000000000..6cf3fb8a41c
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponents.java
@@ -0,0 +1,79 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Types;
+import org.sonar.db.ColumnMetadata;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.db.dialect.Oracle;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PopulateCreatedAtTempInComponents extends DataChange {
+
+ private static final String SELECT_QUERY = """
+ SELECT uuid, created_at
+ FROM components
+ WHERE created_at_temp is null
+ """;
+
+ private static final String UPDATE_QUERY = """
+ UPDATE components
+ SET created_at_temp=?
+ WHERE uuid=?
+ """;
+
+ public PopulateCreatedAtTempInComponents(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ boolean columnAlreadyHasNewType = columnAlreadyHasNewType();
+
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select(SELECT_QUERY);
+ massUpdate.update(UPDATE_QUERY);
+
+ massUpdate.execute((row, update, index) -> {
+ String componentUuid = row.getString(1);
+ Long createdAt;
+ if (columnAlreadyHasNewType) {
+ createdAt = row.getNullableLong(2);
+ } else {
+ createdAt = row.getNullableDate(2) == null ? null : row.getNullableDate(2).getTime();
+ }
+ update.setLong(1, createdAt)
+ .setString(2, componentUuid);
+ return true;
+ });
+ }
+
+ private boolean columnAlreadyHasNewType() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ ColumnMetadata columnMetadata = DatabaseUtils.getColumnMetadata(connection, "components", "created_at");
+ int newType = getDialect().getId().equals(Oracle.ID) ? Types.NUMERIC : Types.BIGINT;
+ return columnMetadata != null && columnMetadata.sqlType() == newType;
+ }
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponents.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponents.java
new file mode 100644
index 00000000000..33f8b1ecf73
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponents.java
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.RenameVarcharColumnChange;
+
+public class RenameCreatedAtTempInComponents extends RenameVarcharColumnChange {
+
+ private static final String TABLE_NAME = "components";
+ private static final String OLD_COLUMN_NAME = "created_at_temp";
+ private static final String NEW_COLUMN_NAME = "created_at";
+
+ public RenameCreatedAtTempInComponents(Database db) {
+ super(db, TABLE_NAME, OLD_COLUMN_NAME, NEW_COLUMN_NAME);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponentsTest.java
new file mode 100644
index 00000000000..ad17bcc8940
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponentsTest.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class AddCreatedAtTempInComponentsTest {
+
+ private static final String TABLE_NAME = "components";
+ private static final String COLUMN_NAME = "created_at_temp";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(AddCreatedAtTempInComponentsTest.class, "schema.sql");
+
+ private final AddCreatedAtTempInComponents underTest = new AddCreatedAtTempInComponents(db.database());
+
+ @Test
+ public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException {
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ underTest.execute();
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BIGINT, null, null);
+ }
+
+ @Test
+ public void execute_whenExecutedTwice_shouldNotFail() throws SQLException {
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ underTest.execute();
+ underTest.execute();
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.BIGINT, null, null);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponentsTest.java
new file mode 100644
index 00000000000..46e8d8ed8d5
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponentsTest.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class DropCreatedAtInComponentsTest {
+
+ private static final String TABLE_NAME = "components";
+ private static final String COLUMN_NAME = "created_at";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropCreatedAtInComponentsTest.class, "schema.sql");
+
+ private final DropCreatedAtInComponents underTest = new DropCreatedAtInComponents(db.database());
+
+ @Test
+ public void execute_whenColumnExists_shouldDropColumn() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.TIMESTAMP, null, null);
+ underTest.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+
+ @Test
+ public void execute_whenExecutedTwice_shouldNotFail() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, COLUMN_NAME, Types.TIMESTAMP, null, null);
+ underTest.execute();
+ underTest.execute();
+ db.assertColumnDoesNotExist(TABLE_NAME, COLUMN_NAME);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java
index 69252ad8cbb..64441a5a19b 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInGroupRolesTest.java
@@ -31,9 +31,9 @@ public class DropIndexComponentUuidInGroupRolesTest {
private static final String INDEX_NAME = "group_roles_component_uuid";
@Rule
- public final CoreDbTester db = CoreDbTester.createForSchema(RenameComponentUuidInGroupRolesTest.class, "schema.sql");
+ public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexComponentUuidInGroupRolesTest.class, "schema.sql");
- private final RenameComponentUuidInGroupRoles underTest = new RenameComponentUuidInGroupRoles(db.database());
+ private final DropIndexComponentUuidInGroupRoles underTest = new DropIndexComponentUuidInGroupRoles(db.database());
@Test
public void index_is_dropped() throws SQLException {
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest.java
index 1ed7fa6e3c7..65fe916469a 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/DropIndexComponentUuidInUserRolesTest.java
@@ -33,7 +33,7 @@ public class DropIndexComponentUuidInUserRolesTest {
@Rule
public final CoreDbTester db = CoreDbTester.createForSchema(DropIndexComponentUuidInUserRolesTest.class, "schema.sql");
- private final RenameComponentUuidInUserRoles underTest = new RenameComponentUuidInUserRoles(db.database());
+ private final DropIndexComponentUuidInUserRoles underTest = new DropIndexComponentUuidInUserRoles(db.database());
@Test
public void index_is_dropped() throws SQLException {
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponentsTest.java
new file mode 100644
index 00000000000..41633a712f9
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponentsTest.java
@@ -0,0 +1,81 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class PopulateCreatedAtTempInComponentsTest {
+
+ private static final String TABLE_NAME = "components";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(PopulateCreatedAtTempInComponentsTest.class, "schema.sql");
+
+ private final PopulateCreatedAtTempInComponents underTest = new PopulateCreatedAtTempInComponents(db.database());
+
+ @Test
+ public void execute_whenComponentsDoNotExist_shouldNotFail() {
+ assertThatCode(underTest::execute).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void execute_whenComponentsExist_shouldPopulateColumn() throws SQLException, ParseException {
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+ format.setTimeZone(TimeZone.getTimeZone("UTC"));
+ Date date1 = format.parse("2023-01-01 10:22:38.222");
+ Date date2 = format.parse("2023-07-20 02:00:01.800");
+
+ insertComponent("uuid-1", null);
+ insertComponent("uuid-2", date1);
+ insertComponent("uuid-3", date2);
+
+ underTest.execute();
+
+ assertThat(db.select("select UUID, CREATED_AT_TEMP from components"))
+ .extracting(stringObjectMap -> stringObjectMap.get("UUID"), stringObjectMap -> stringObjectMap.get("CREATED_AT_TEMP"))
+ .containsExactlyInAnyOrder(
+ tuple("uuid-1", null),
+ tuple("uuid-2", 1672568558222L),
+ tuple("uuid-3", 1689818401800L));
+ }
+
+ private void insertComponent(String uuid, @Nullable Date createdAt) {
+ db.executeInsert(TABLE_NAME,
+ "UUID", uuid,
+ "UUID_PATH", "P",
+ "BRANCH_UUID", "B",
+ "ENABLED", true,
+ "PRIVATE", true,
+ "CREATED_AT", createdAt,
+ "CREATED_AT_TEMP", null);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponentsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponentsTest.java
new file mode 100644
index 00000000000..7fefd0dc7da
--- /dev/null
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponentsTest.java
@@ -0,0 +1,57 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class RenameCreatedAtTempInComponentsTest {
+
+ public static final String TABLE_NAME = "components";
+ public static final String OLD_COLUMN_NAME = "created_at_temp";
+ public static final String NEW_COLUMN_NAME = "created_at";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(RenameCreatedAtTempInComponentsTest.class, "schema.sql");
+
+ private final RenameCreatedAtTempInComponents underTest = new RenameCreatedAtTempInComponents(db.database());
+
+ @Test
+ public void execute_shouldRenameColumn() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, OLD_COLUMN_NAME, Types.BIGINT, null, null);
+ db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+ underTest.execute();
+ db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, Types.BIGINT, null, null);
+ db.assertColumnDoesNotExist(TABLE_NAME, OLD_COLUMN_NAME);
+ }
+
+ @Test
+ public void execute_whenExecutedTwice_shouldNotFail() throws SQLException {
+ db.assertColumnDefinition(TABLE_NAME, OLD_COLUMN_NAME, Types.BIGINT, null, null);
+ db.assertColumnDoesNotExist(TABLE_NAME, NEW_COLUMN_NAME);
+ underTest.execute();
+ underTest.execute();
+ db.assertColumnDefinition(TABLE_NAME, NEW_COLUMN_NAME, Types.BIGINT, null, null);
+ db.assertColumnDoesNotExist(TABLE_NAME, OLD_COLUMN_NAME);
+ }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponentsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponentsTest/schema.sql
new file mode 100644
index 00000000000..6b3d3b86b05
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/AddCreatedAtTempInComponentsTest/schema.sql
@@ -0,0 +1,33 @@
+CREATE TABLE "COMPONENTS"(
+ "UUID" CHARACTER VARYING(50) NOT NULL,
+ "KEE" CHARACTER VARYING(1000),
+ "DEPRECATED_KEE" CHARACTER VARYING(400),
+ "NAME" CHARACTER VARYING(2000),
+ "LONG_NAME" CHARACTER VARYING(2000),
+ "DESCRIPTION" CHARACTER VARYING(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" CHARACTER VARYING(3),
+ "QUALIFIER" CHARACTER VARYING(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "LANGUAGE" CHARACTER VARYING(20),
+ "COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "PATH" CHARACTER VARYING(2000),
+ "UUID_PATH" CHARACTER VARYING(1500) NOT NULL,
+ "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL,
+ "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" CHARACTER VARYING(500),
+ "B_LONG_NAME" CHARACTER VARYING(500),
+ "B_DESCRIPTION" CHARACTER VARYING(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" CHARACTER VARYING(10),
+ "B_LANGUAGE" CHARACTER VARYING(20),
+ "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "B_PATH" CHARACTER VARYING(2000),
+ "B_UUID_PATH" CHARACTER VARYING(1500),
+ "CREATED_AT" TIMESTAMP
+);
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST);
+CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponentsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponentsTest/schema.sql
new file mode 100644
index 00000000000..8224670a0df
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/DropCreatedAtInComponentsTest/schema.sql
@@ -0,0 +1,34 @@
+CREATE TABLE "COMPONENTS"(
+ "UUID" CHARACTER VARYING(50) NOT NULL,
+ "KEE" CHARACTER VARYING(1000),
+ "DEPRECATED_KEE" CHARACTER VARYING(400),
+ "NAME" CHARACTER VARYING(2000),
+ "LONG_NAME" CHARACTER VARYING(2000),
+ "DESCRIPTION" CHARACTER VARYING(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" CHARACTER VARYING(3),
+ "QUALIFIER" CHARACTER VARYING(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "LANGUAGE" CHARACTER VARYING(20),
+ "COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "PATH" CHARACTER VARYING(2000),
+ "UUID_PATH" CHARACTER VARYING(1500) NOT NULL,
+ "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL,
+ "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" CHARACTER VARYING(500),
+ "B_LONG_NAME" CHARACTER VARYING(500),
+ "B_DESCRIPTION" CHARACTER VARYING(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" CHARACTER VARYING(10),
+ "B_LANGUAGE" CHARACTER VARYING(20),
+ "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "B_PATH" CHARACTER VARYING(2000),
+ "B_UUID_PATH" CHARACTER VARYING(1500),
+ "CREATED_AT" TIMESTAMP,
+ "CREATED_AT_TEMP" BIGINT
+);
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST);
+CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponentsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponentsTest/schema.sql
new file mode 100644
index 00000000000..8224670a0df
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/PopulateCreatedAtTempInComponentsTest/schema.sql
@@ -0,0 +1,34 @@
+CREATE TABLE "COMPONENTS"(
+ "UUID" CHARACTER VARYING(50) NOT NULL,
+ "KEE" CHARACTER VARYING(1000),
+ "DEPRECATED_KEE" CHARACTER VARYING(400),
+ "NAME" CHARACTER VARYING(2000),
+ "LONG_NAME" CHARACTER VARYING(2000),
+ "DESCRIPTION" CHARACTER VARYING(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" CHARACTER VARYING(3),
+ "QUALIFIER" CHARACTER VARYING(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "LANGUAGE" CHARACTER VARYING(20),
+ "COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "PATH" CHARACTER VARYING(2000),
+ "UUID_PATH" CHARACTER VARYING(1500) NOT NULL,
+ "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL,
+ "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" CHARACTER VARYING(500),
+ "B_LONG_NAME" CHARACTER VARYING(500),
+ "B_DESCRIPTION" CHARACTER VARYING(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" CHARACTER VARYING(10),
+ "B_LANGUAGE" CHARACTER VARYING(20),
+ "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "B_PATH" CHARACTER VARYING(2000),
+ "B_UUID_PATH" CHARACTER VARYING(1500),
+ "CREATED_AT" TIMESTAMP,
+ "CREATED_AT_TEMP" BIGINT
+);
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST);
+CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST);
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponentsTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponentsTest/schema.sql
new file mode 100644
index 00000000000..ea8abd3a08b
--- /dev/null
+++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v102/RenameCreatedAtTempInComponentsTest/schema.sql
@@ -0,0 +1,33 @@
+CREATE TABLE "COMPONENTS"(
+ "UUID" CHARACTER VARYING(50) NOT NULL,
+ "KEE" CHARACTER VARYING(1000),
+ "DEPRECATED_KEE" CHARACTER VARYING(400),
+ "NAME" CHARACTER VARYING(2000),
+ "LONG_NAME" CHARACTER VARYING(2000),
+ "DESCRIPTION" CHARACTER VARYING(2000),
+ "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+ "SCOPE" CHARACTER VARYING(3),
+ "QUALIFIER" CHARACTER VARYING(10),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "LANGUAGE" CHARACTER VARYING(20),
+ "COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "PATH" CHARACTER VARYING(2000),
+ "UUID_PATH" CHARACTER VARYING(1500) NOT NULL,
+ "BRANCH_UUID" CHARACTER VARYING(50) NOT NULL,
+ "MAIN_BRANCH_PROJECT_UUID" CHARACTER VARYING(50),
+ "B_CHANGED" BOOLEAN,
+ "B_NAME" CHARACTER VARYING(500),
+ "B_LONG_NAME" CHARACTER VARYING(500),
+ "B_DESCRIPTION" CHARACTER VARYING(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_QUALIFIER" CHARACTER VARYING(10),
+ "B_LANGUAGE" CHARACTER VARYING(20),
+ "B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
+ "B_PATH" CHARACTER VARYING(2000),
+ "B_UUID_PATH" CHARACTER VARYING(1500),
+ "CREATED_AT_TEMP" BIGINT
+);
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST);
+CREATE INDEX "COMPONENTS_BRANCH_UUID" ON "COMPONENTS"("BRANCH_UUID" NULLS FIRST);
+CREATE UNIQUE INDEX "COMPONENTS_KEE_BRANCH_UUID" ON "COMPONENTS"("KEE" NULLS FIRST, "BRANCH_UUID" NULLS FIRST);
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java
index 8c1ff9c38c9..965ba688bfc 100644
--- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java
+++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/TreeActionIT.java
@@ -579,7 +579,7 @@ public class TreeActionIT {
.setQualifier(getJsonField(componentAsJsonObject, "qualifier"))
.setDescription(getJsonField(componentAsJsonObject, "description"))
.setEnabled(true)
- .setCreatedAt(now));
+ .setCreatedAt(now.getTime()));
}
db.commit();
return projectData;
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
index 75118c589f1..8e95de62c14 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
@@ -20,7 +20,6 @@
package org.sonar.server.component;
import com.google.common.annotations.VisibleForTesting;
-import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
@@ -186,7 +185,7 @@ public class ComponentUpdater {
.setScope(Scopes.PROJECT)
.setQualifier(newComponent.qualifier())
.setPrivate(newComponent.isPrivate())
- .setCreatedAt(new Date(now));
+ .setCreatedAt(now);
dbClient.componentDao().insert(session, component, true);
return component;