private final System2 system2 = mock(System2.class);
private final DbClient dbClient = db.getDbClient();
- private Long now;
+ private Date 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").getTime();
- when(system2.now()).thenReturn(now);
+ now = DATE_FORMAT.parse("2015-06-02");
+ when(system2.now()).thenReturn(now.getTime());
BranchPersister branchPersister = mock(BranchPersister.class);
ProjectPersister projectPersister = mock(ProjectPersister.class);
@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.getTime()));
+ ComponentDto project = prepareProject(p -> p.setCreatedAt(oldDate));
db.getSession().commit();
treeRootHolder.setRoot(
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;
private final System2 system2 = mock(System2.class);
private final DbClient dbClient = dbTester.getDbClient();
- private Long now;
+ private Date 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").getTime();
- when(system2.now()).thenReturn(now);
+ now = DATE_FORMAT.parse("2015-06-02");
+ when(system2.now()).thenReturn(now.getTime());
analysisMetadataHolder.setBranch(new DefaultBranchImpl(DEFAULT_MAIN_BRANCH_NAME));
BranchPersister branchPersister = mock(BranchPersister.class);
ProjectData projectData = dbTester.components().insertPublicProject(PROJECT_UUID);
for (BranchDto branch : branches) {
createdAt = DateUtils.addMinutes(createdAt, 10);
- dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt.getTime());
+ dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt);
}
dbTester.commit();
when(projectHolder.projectDto()).thenReturn(projectData.getProjectDto());
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;
.setEnabled(true)
.setUuid(PROJECT_UUID)
.setUuidPath(UUID_PATH_OF_ROOT)
- .setCreatedAt(1596749115856L)
+ .setCreatedAt(new Date(1596749115856L))
.setBranchUuid(PROJECT_UUID);
private static final String FILE_UUID = "FILE_UUID";
.setUuid(FILE_UUID)
.setUuidPath(FILE_UUID_PATH)
.setEnabled(true)
- .setCreatedAt(1596749148406L)
+ .setCreatedAt(new Date(1596749148406L))
.setBranchUuid(PROJECT_UUID);
@Rule
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.getTime()));
+ BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(projectData.getProjectDto(), branch).setCreatedAt(createdAt));
dbTester.commit();
return projectData.getProjectDto();
}
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.getTime()));
+ PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(project, branch).setCreatedAt(createdAt));
ComponentDto anotherProjectDto = dbTester.components().insertPublicProject(ANOTHER_PROJECT).getMainBranchComponent();
- ANOTHER_PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(anotherProjectDto, branch).setCreatedAt(createdAt.getTime()));
+ ANOTHER_PROJECT_BRANCHES.forEach(branch -> dbTester.components().insertProjectBranch(anotherProjectDto, branch).setCreatedAt(createdAt));
dbTester.commit();
projectHolder.setProjectDto(project);
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;
componentDto.setUuid(componentUuid);
componentDto.setKey(componentKey);
componentDto.setEnabled(true);
- componentDto.setCreatedAt(system2.now());
+ componentDto.setCreatedAt(new Date(system2.now()));
return componentDto;
}
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;
@Test
public void selectByQuery_verify_order() {
- Long firstDate = system2.now();
- Long secondDate = system2.now();
- Long thirdDate = system2.now();
+ Date firstDate = new Date(system2.now());
+ Date secondDate = new Date(system2.now());
+ Date thirdDate = new Date(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();
@Test
public void selectByQuery_filter_created_at() {
- 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();
+ 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();
- assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2017-12-01").getTime())))
+ assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2017-12-01"))))
.containsExactlyInAnyOrder(project1.uuid(), project2.uuid());
- assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2018-02-20").getTime())))
+ assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2018-02-20"))))
.containsExactlyInAnyOrder(project2.uuid());
- assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2019-01-01").getTime())))
+ assertThat(selectProjectUuidsByQuery(q -> q.setCreatedAfter(parseDate("2019-01-01"))))
.isEmpty();
}
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;
private boolean enabled = true;
private boolean isPrivate = false;
- private Long createdAt;
+ private Date createdAt;
public static String formatUuidPathFromParent(ComponentDto parent) {
checkArgument(!Strings.isNullOrEmpty(parent.getUuidPath()));
return this;
}
- public Long getCreatedAt() {
+ public Date getCreatedAt() {
return createdAt;
}
- public ComponentDto setCreatedAt(Long createdAt) {
- this.createdAt = createdAt;
+ public ComponentDto setCreatedAt(Date datetime) {
+ this.createdAt = datetime;
return this;
}
*/
package org.sonar.db.component;
+import java.util.Date;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Stream;
private final Long anyBranchAnalyzedBefore;
private final Long anyBranchAnalyzedAfter;
private final Long allBranchesAnalyzedBefore;
- private final Long createdAfter;
+ private final Date createdAfter;
private final boolean onProvisionedOnly;
private ComponentQuery(Builder builder) {
}
@CheckForNull
- public Long getCreatedAfter() {
+ public Date getCreatedAfter() {
return createdAfter;
}
private Long anyBranchAnalyzedBefore;
private Long anyBranchAnalyzedAfter;
private Long allBranchesAnalyzedBefore;
- private Long createdAfter;
+ private Date createdAfter;
private boolean onProvisionedOnly = false;
public Builder setNameOrKeyQuery(@Nullable String nameOrKeyQuery) {
return this;
}
- public Builder setCreatedAfter(@Nullable Long l) {
+ public Builder setCreatedAfter(@Nullable Date l) {
this.createdAfter = l;
return this;
}
)
</if>
<if test="query.createdAfter != null">
- and p.created_at >= #{query.createdAfter,jdbcType=BIGINT}
+ and p.created_at >= #{query.createdAfter,jdbcType=TIMESTAMP}
</if>
</sql>
#{path,jdbcType=VARCHAR},
#{copyComponentUuid,jdbcType=VARCHAR},
#{enabled,jdbcType=BOOLEAN},
- #{createdAt,jdbcType=BIGINT},
+ #{createdAt,jdbcType=TIMESTAMP},
${_false},
null,
null,
"B_COPY_COMPONENT_UUID" CHARACTER VARYING(50),
"B_PATH" CHARACTER VARYING(2000),
"B_UUID_PATH" CHARACTER VARYING(1500),
- "CREATED_AT" BIGINT
+ "CREATED_AT" TIMESTAMP
);
CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER" NULLS FIRST);
CREATE UNIQUE INDEX "COMPONENTS_UUID" ON "COMPONENTS"("UUID" NULLS FIRST);
.setNameOrKeyQuery("key")
.setAnyBranchAnalyzedBefore(100L)
.setAnyBranchAnalyzedAfter(200L)
- .setCreatedAfter(new Date(300L).getTime())
+ .setCreatedAfter(new Date(300L))
.setQualifiers(PROJECT)
.build();
assertThat(underTest.getQualifiers()).containsOnly(PROJECT);
assertThat(underTest.getAnyBranchAnalyzedBefore()).isEqualTo(100L);
assertThat(underTest.getAnyBranchAnalyzedAfter()).isEqualTo(200L);
- assertThat(underTest.getCreatedAfter()).isEqualTo(300L);
+ assertThat(underTest.getCreatedAfter().getTime()).isEqualTo(300L);
assertThat(underTest.isOnProvisionedOnly()).isFalse();
assertThat(underTest.isPartialMatchOnKey()).isFalse();
assertThat(underTest.hasEmptySetOfComponents()).isFalse();
.setBranchUuid(branch.branchUuid())
.setQualifier(Qualifiers.FILE)
.setPath(path)
- .setCreatedAt(new Date().getTime())
+ .setCreatedAt(new Date())
.setLanguage("xoo");
}
.setUuidPath(formatUuidPathFromParent(parent))
.setKey(uuid)
.setBranchUuid(branch.branchUuid())
- .setCreatedAt(new Date().getTime())
+ .setCreatedAt(new Date())
.setEnabled(true)
.setPrivate(branch.isPrivate());
}
+++ /dev/null
-/*
- * 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());
- }
- }
- }
-}
// ignoring bad number formatting, as it's indented that we align the migration numbers to SQ versions
@SuppressWarnings("java:S3937")
public class DbVersion102 implements DbVersion {
+
/**
* We use the start of the 10.X cycle as an opportunity to align migration numbers with the SQ version number.
* Please follow this pattern:
.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)
+ // Versions 10_2_026 to 10_2_029 were used by a migration that has been rolled back. See SONAR-7704
.add(10_2_030, "Create table 'anticipated_transitions'", CreateAnticipatedTransitionsTable.class)
+++ /dev/null
-/*
- * 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);
- }
-}
+++ /dev/null
-/*
- * 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;
- }
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-}
+++ /dev/null
-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);
+++ /dev/null
-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);
+++ /dev/null
-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);
+++ /dev/null
-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);
.setQualifier(getJsonField(componentAsJsonObject, "qualifier"))
.setDescription(getJsonField(componentAsJsonObject, "description"))
.setEnabled(true)
- .setCreatedAt(now.getTime()));
+ .setCreatedAt(now));
}
db.commit();
return projectData;
*/
package org.sonar.server.component;
+import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
.setScope(Scopes.PROJECT)
.setQualifier(newComponent.qualifier())
.setPrivate(newComponent.isPrivate())
- .setCreatedAt(now);
+ .setCreatedAt(new Date(now));
dbClient.componentDao().insert(session, component, true);
return component;