* Table creation should not be re-entrant The creation of a table should not be re-entrant. Indeed, if the creation of the table is in success but not the creation of the index(es), then next execution of the migration will ignore creation of indexes. * Simplify some mappers insert usage and some dao teststags/8.4.0.35506
@@ -52,16 +52,16 @@ public class AlmPatDao implements Dao { | |||
public void insert(DbSession dbSession, AlmPatDto almPatDto) { | |||
String uuid = uuidFactory.create(); | |||
long now = system2.now(); | |||
getMapper(dbSession).insert(almPatDto, uuid, now); | |||
almPatDto.setUuid(uuid); | |||
almPatDto.setCreatedAt(now); | |||
almPatDto.setUpdatedAt(now); | |||
getMapper(dbSession).insert(almPatDto); | |||
} | |||
public void update(DbSession dbSession, AlmPatDto almPatDto) { | |||
long now = system2.now(); | |||
getMapper(dbSession).update(almPatDto, now); | |||
almPatDto.setUpdatedAt(now); | |||
getMapper(dbSession).update(almPatDto); | |||
} | |||
public void delete(DbSession dbSession, AlmPatDto almPatDto) { | |||
@@ -76,6 +76,4 @@ public class AlmPatDao implements Dao { | |||
getMapper(dbSession).deleteByAlmSetting(almSetting.getUuid()); | |||
} | |||
} |
@@ -30,9 +30,9 @@ public interface AlmPatMapper { | |||
@CheckForNull | |||
AlmPatDto selectByUserAndAlmSetting(@Param("userUuid") String userUuid, @Param("almSettingUuid") String almSettingUuid); | |||
void insert(@Param("dto") AlmPatDto almPatDto, @Param("uuid") String uuid, @Param("now") long now); | |||
void insert(@Param("dto") AlmPatDto almPatDto); | |||
void update(@Param("dto") AlmPatDto almPatDto, @Param("now") long now); | |||
void update(@Param("dto") AlmPatDto almPatDto); | |||
void deleteByUuid(@Param("uuid") String uuid); | |||
@@ -43,10 +43,10 @@ public class AlmSettingDao implements Dao { | |||
public void insert(DbSession dbSession, AlmSettingDto almSettingDto) { | |||
String uuid = uuidFactory.create(); | |||
long now = system2.now(); | |||
getMapper(dbSession).insert(almSettingDto, uuid, now); | |||
almSettingDto.setUuid(uuid); | |||
almSettingDto.setCreatedAt(now); | |||
almSettingDto.setUpdatedAt(now); | |||
getMapper(dbSession).insert(almSettingDto); | |||
} | |||
public Optional<AlmSettingDto> selectByUuid(DbSession dbSession, String uuid) { | |||
@@ -61,18 +61,17 @@ public class AlmSettingDao implements Dao { | |||
return getMapper(dbSession).selectByAlm(alm.getId()); | |||
} | |||
public List<AlmSettingDto> selectAll(DbSession dbSession) { | |||
return getMapper(dbSession).selectAll(); | |||
} | |||
public void delete(DbSession dbSession, AlmSettingDto almSettingDto){ | |||
public void delete(DbSession dbSession, AlmSettingDto almSettingDto) { | |||
getMapper(dbSession).deleteByKey(almSettingDto.getKey()); | |||
} | |||
public void update(DbSession dbSession, AlmSettingDto almSettingDto) { | |||
long now = system2.now(); | |||
getMapper(dbSession).update(almSettingDto, now); | |||
almSettingDto.setUpdatedAt(now); | |||
getMapper(dbSession).update(almSettingDto); | |||
} | |||
} |
@@ -35,9 +35,9 @@ public interface AlmSettingMapper { | |||
List<AlmSettingDto> selectAll(); | |||
void insert(@Param("dto") AlmSettingDto almSettingDto, @Param("uuid") String uuid, @Param("now") long now); | |||
void insert(@Param("dto") AlmSettingDto almSettingDto); | |||
void update(@Param("dto") AlmSettingDto almSettingDto, @Param("now") long now); | |||
void update(@Param("dto") AlmSettingDto almSettingDto); | |||
void deleteByKey(@Param("key") String key); | |||
} |
@@ -41,12 +41,12 @@ | |||
updated_at | |||
) | |||
VALUES ( | |||
#{uuid, jdbcType=VARCHAR}, | |||
#{dto.uuid, jdbcType=VARCHAR}, | |||
#{dto.personalAccessToken, jdbcType=VARCHAR}, | |||
#{dto.userUuid, jdbcType=VARCHAR}, | |||
#{dto.almSettingUuid, jdbcType=VARCHAR}, | |||
#{now, jdbcType=BIGINT}, | |||
#{now, jdbcType=BIGINT} | |||
#{dto.createdAt, jdbcType=BIGINT}, | |||
#{dto.updatedAt, jdbcType=BIGINT} | |||
) | |||
</insert> | |||
@@ -54,7 +54,7 @@ | |||
UPDATE alm_pats | |||
<set> | |||
pat = #{dto.personalAccessToken, jdbcType=VARCHAR}, | |||
updated_at = #{now, jdbcType=BIGINT} | |||
updated_at = #{dto.updatedAt, jdbcType=BIGINT} | |||
</set> | |||
<where> | |||
uuid = #{dto.uuid, jdbcType=VARCHAR} |
@@ -59,15 +59,15 @@ | |||
updated_at | |||
) | |||
VALUES ( | |||
#{uuid, jdbcType=VARCHAR}, | |||
#{dto.uuid, jdbcType=VARCHAR}, | |||
#{dto.key, jdbcType=VARCHAR}, | |||
#{dto.rawAlm, jdbcType=VARCHAR}, | |||
#{dto.url, jdbcType=VARCHAR}, | |||
#{dto.appId, jdbcType=VARCHAR}, | |||
#{dto.privateKey, jdbcType=VARCHAR}, | |||
#{dto.personalAccessToken, jdbcType=VARCHAR}, | |||
#{now, jdbcType=BIGINT}, | |||
#{now, jdbcType=BIGINT} | |||
#{dto.createdAt, jdbcType=BIGINT}, | |||
#{dto.updatedAt, jdbcType=BIGINT} | |||
) | |||
</insert> | |||
@@ -79,7 +79,7 @@ | |||
app_id = #{dto.appId, jdbcType=VARCHAR}, | |||
private_key = #{dto.privateKey, jdbcType=VARCHAR}, | |||
pat = #{dto.personalAccessToken, jdbcType=VARCHAR}, | |||
updated_at = #{now, jdbcType=BIGINT} | |||
updated_at = #{dto.updatedAt, jdbcType=BIGINT} | |||
</set> | |||
<where> | |||
uuid = #{dto.uuid, jdbcType=VARCHAR} |
@@ -21,8 +21,7 @@ package org.sonar.db.alm.pat; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.api.impl.utils.TestSystem2; | |||
import org.sonar.core.util.UuidFactory; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
@@ -37,25 +36,23 @@ import static org.mockito.Mockito.when; | |||
import static org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto; | |||
import static org.sonar.db.almsettings.AlmSettingsTesting.newGithubAlmSettingDto; | |||
public class ALMPatDaoTest { | |||
public class AlmPatDaoTest { | |||
private static final long NOW = 1000000L; | |||
private static final String A_UUID = "SOME_UUID"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private System2 system2 = mock(System2.class); | |||
private TestSystem2 system2 = new TestSystem2().setNow(NOW); | |||
@Rule | |||
public DbTester db = DbTester.create(system2); | |||
private DbSession dbSession = db.getSession(); | |||
private UuidFactory uuidFactory = mock(UuidFactory.class); | |||
private AlmPatDao underTest = new AlmPatDao(system2, uuidFactory); | |||
private AlmSettingDao almSettingDao = new AlmSettingDao(system2, uuidFactory); | |||
private AlmPatDao underTest = new AlmPatDao(system2, uuidFactory); | |||
@Test | |||
public void selectByUuid() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
AlmPatDto almPatDto = newAlmPatDto(); | |||
underTest.insert(dbSession, almPatDto); | |||
@@ -74,7 +71,6 @@ public class ALMPatDaoTest { | |||
@Test | |||
public void selectByAlmSetting() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
AlmSettingDto almSetting = newGithubAlmSettingDto(); | |||
almSettingDao.insert(dbSession, almSetting); | |||
@@ -98,14 +94,13 @@ public class ALMPatDaoTest { | |||
@Test | |||
public void update() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
AlmPatDto almPatDto = newAlmPatDto(); | |||
underTest.insert(dbSession, almPatDto); | |||
String updated_pat = "updated pat"; | |||
almPatDto.setPersonalAccessToken(updated_pat); | |||
when(system2.now()).thenReturn(NOW + 1); | |||
system2.setNow(NOW + 1); | |||
underTest.update(dbSession, almPatDto); | |||
AlmPatDto result = underTest.selectByUuid(dbSession, A_UUID).get(); | |||
@@ -116,13 +111,11 @@ public class ALMPatDaoTest { | |||
.containsExactly(A_UUID, updated_pat, almPatDto.getUserUuid(), | |||
almPatDto.getAlmSettingUuid(), | |||
NOW, NOW + 1); | |||
} | |||
@Test | |||
public void delete() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
AlmPatDto almPat = newAlmPatDto(); | |||
underTest.insert(dbSession, almPat); | |||
@@ -134,7 +127,6 @@ public class ALMPatDaoTest { | |||
@Test | |||
public void deleteByUser() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
UserDto userDto = db.users().insertUser(); | |||
AlmPatDto almPat = newAlmPatDto(); | |||
almPat.setUserUuid(userDto.getUuid()); | |||
@@ -148,7 +140,6 @@ public class ALMPatDaoTest { | |||
@Test | |||
public void deleteByAlmSetting() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting(); | |||
AlmPatDto almPat = newAlmPatDto(); | |||
almPat.setAlmSettingUuid(almSettingDto.getUuid()); |
@@ -22,8 +22,7 @@ package org.sonar.db.alm.setting; | |||
import java.util.List; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.api.impl.utils.TestSystem2; | |||
import org.sonar.core.util.UuidFactory; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
@@ -38,20 +37,18 @@ public class AlmSettingDaoTest { | |||
private static final long NOW = 1000000L; | |||
private static final String A_UUID = "SOME_UUID"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private System2 system2 = mock(System2.class); | |||
private TestSystem2 system2 = new TestSystem2().setNow(NOW); | |||
@Rule | |||
public DbTester db = DbTester.create(system2); | |||
private DbSession dbSession = db.getSession(); | |||
private UuidFactory uuidFactory = mock(UuidFactory.class); | |||
private AlmSettingDao underTest = new AlmSettingDao(system2, uuidFactory); | |||
@Test | |||
public void selectByUuid() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
AlmSettingDto almSettingDto = newGithubAlmSettingDto(); | |||
underTest.insert(dbSession, almSettingDto); | |||
@@ -70,7 +67,6 @@ public class AlmSettingDaoTest { | |||
@Test | |||
public void selectByKey() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
AlmSettingDto almSettingDto = AlmSettingsTesting.newGithubAlmSettingDto(); | |||
underTest.insert(dbSession, almSettingDto); | |||
@@ -89,7 +85,6 @@ public class AlmSettingDaoTest { | |||
@Test | |||
public void selectByAlm() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
AlmSettingDto gitHubAlmSetting1 = db.almSettings().insertGitHubAlmSetting(); | |||
AlmSettingDto gitHubAlmSetting2 = db.almSettings().insertGitHubAlmSetting(); | |||
AlmSettingDto azureAlmSetting2 = db.almSettings().insertAzureAlmSetting(); | |||
@@ -104,7 +99,6 @@ public class AlmSettingDaoTest { | |||
@Test | |||
public void selectAll() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
underTest.insert(dbSession, newGithubAlmSettingDto()); | |||
when(uuidFactory.create()).thenReturn(A_UUID + "bis"); | |||
underTest.insert(dbSession, newGithubAlmSettingDto()); | |||
@@ -117,7 +111,6 @@ public class AlmSettingDaoTest { | |||
@Test | |||
public void update() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
AlmSettingDto almSettingDto = newGithubAlmSettingDto(); | |||
underTest.insert(dbSession, almSettingDto); | |||
@@ -127,7 +120,7 @@ public class AlmSettingDaoTest { | |||
almSettingDto.setPersonalAccessToken("updated pat"); | |||
almSettingDto.setKey("updated key"); | |||
when(system2.now()).thenReturn(NOW + 1); | |||
system2.setNow(NOW + 1); | |||
underTest.update(dbSession, almSettingDto); | |||
AlmSettingDto result = underTest.selectByUuid(dbSession, A_UUID).get(); | |||
@@ -143,7 +136,6 @@ public class AlmSettingDaoTest { | |||
@Test | |||
public void delete() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(NOW); | |||
AlmSettingDto almSettingDto = newGithubAlmSettingDto(); | |||
underTest.insert(dbSession, almSettingDto); | |||
@@ -23,8 +23,7 @@ import java.util.HashSet; | |||
import java.util.Set; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.api.impl.utils.TestSystem2; | |||
import org.sonar.core.util.UuidFactory; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
@@ -43,9 +42,7 @@ public class ProjectAlmSettingDaoTest { | |||
private static final long A_DATE_LATER = 1_700_000_000_000L; | |||
private static final String A_UUID = "SOME_UUID"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private System2 system2 = mock(System2.class); | |||
private TestSystem2 system2 = new TestSystem2().setNow(A_DATE); | |||
@Rule | |||
public DbTester db = DbTester.create(system2); | |||
@@ -56,7 +53,6 @@ public class ProjectAlmSettingDaoTest { | |||
@Test | |||
public void select_by_project() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(A_DATE); | |||
AlmSettingDto githubAlmSettingDto = db.almSettings().insertGitHubAlmSetting(); | |||
ProjectDto project = db.components().insertPrivateProjectDto(); | |||
ProjectDto anotherProject = db.components().insertPrivateProjectDto(); | |||
@@ -78,7 +74,6 @@ public class ProjectAlmSettingDaoTest { | |||
@Test | |||
public void select_by_alm_setting_and_slugs() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(A_DATE); | |||
AlmSettingDto almSettingsDto = db.almSettings().insertBitbucketAlmSetting(); | |||
ProjectDto project = db.components().insertPrivateProjectDto(); | |||
ProjectAlmSettingDto bitbucketProjectAlmSettingDto = newBitbucketProjectAlmSettingDto(almSettingsDto, project); | |||
@@ -99,7 +94,6 @@ public class ProjectAlmSettingDaoTest { | |||
@Test | |||
public void select_with_no_slugs_return_empty() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(A_DATE); | |||
AlmSettingDto almSettingsDto = db.almSettings().insertBitbucketAlmSetting(); | |||
assertThat(underTest.selectByAlmSettingAndSlugs(dbSession, almSettingsDto, new HashSet<>())).isEmpty(); | |||
@@ -108,13 +102,12 @@ public class ProjectAlmSettingDaoTest { | |||
@Test | |||
public void update_existing_binding() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(A_DATE); | |||
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting(); | |||
ProjectDto project = db.components().insertPrivateProjectDto(); | |||
ProjectAlmSettingDto projectAlmSettingDto = db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project); | |||
AlmSettingDto anotherGithubAlmSetting = db.almSettings().insertGitHubAlmSetting(); | |||
when(system2.now()).thenReturn(A_DATE_LATER); | |||
system2.setNow(A_DATE_LATER); | |||
ProjectAlmSettingDto newProjectAlmSettingDto = newGithubProjectAlmSettingDto(anotherGithubAlmSetting, project) | |||
.setSummaryCommentEnabled(false); | |||
underTest.insertOrUpdate(dbSession, newProjectAlmSettingDto); | |||
@@ -132,7 +125,6 @@ public class ProjectAlmSettingDaoTest { | |||
@Test | |||
public void deleteByProject() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(A_DATE); | |||
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting(); | |||
ProjectDto project = db.components().insertPrivateProjectDto(); | |||
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project); | |||
@@ -148,7 +140,6 @@ public class ProjectAlmSettingDaoTest { | |||
@Test | |||
public void deleteByAlmSetting() { | |||
when(uuidFactory.create()).thenReturn(A_UUID); | |||
when(system2.now()).thenReturn(A_DATE); | |||
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting(); | |||
ProjectDto project1 = db.components().insertPrivateProjectDto(); | |||
ProjectDto project2 = db.components().insertPrivateProjectDto(); |
@@ -21,8 +21,6 @@ package org.sonar.server.platform.db.migration.sql; | |||
import com.google.common.collect.HashMultimap; | |||
import com.google.common.collect.Multimap; | |||
import java.sql.Connection; | |||
import java.sql.SQLException; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Collection; | |||
@@ -32,8 +30,6 @@ import java.util.Locale; | |||
import java.util.stream.Stream; | |||
import javax.annotation.CheckForNull; | |||
import org.sonar.core.util.stream.MoreCollectors; | |||
import org.sonar.db.Database; | |||
import org.sonar.db.DatabaseUtils; | |||
import org.sonar.db.dialect.Dialect; | |||
import org.sonar.db.dialect.H2; | |||
import org.sonar.db.dialect.MsSql; | |||
@@ -68,12 +64,6 @@ public class CreateTableBuilder { | |||
this.tableName = validateTableName(tableName); | |||
} | |||
public boolean tableExists(Database database) throws SQLException { | |||
try (Connection connection = database.getDataSource().getConnection()) { | |||
return DatabaseUtils.tableExists(tableName, connection); | |||
} | |||
} | |||
public List<String> build() { | |||
checkState(!columnDefs.isEmpty() || !pkColumnDefs.isEmpty(), "at least one column must be specified"); | |||
@@ -19,10 +19,8 @@ | |||
*/ | |||
package org.sonar.server.platform.db.migration.version.v80; | |||
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.VarcharColumnDef; | |||
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; | |||
@@ -33,7 +31,6 @@ import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.new | |||
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE; | |||
import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; | |||
public class CreateNewCodePeriodTable extends DdlChange { | |||
private static final String TABLE_NAME = "new_code_periods"; | |||
@@ -84,16 +81,12 @@ public class CreateNewCodePeriodTable extends DdlChange { | |||
.setIsNullable(false) | |||
.build(); | |||
public CreateNewCodePeriodTable(Database db) { | |||
super(db); | |||
} | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
if (tableExists()) { | |||
return; | |||
} | |||
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME) | |||
.addPkColumn(UUID_COLUMN) | |||
.addColumn(PROJECT_UUID_COLUMN) | |||
@@ -113,9 +106,4 @@ public class CreateNewCodePeriodTable extends DdlChange { | |||
.build()); | |||
} | |||
private boolean tableExists() throws SQLException { | |||
try (Connection connection = getDatabase().getDataSource().getConnection()) { | |||
return DatabaseUtils.tableExists(TABLE_NAME, connection); | |||
} | |||
} | |||
} |
@@ -19,10 +19,8 @@ | |||
*/ | |||
package org.sonar.server.platform.db.migration.version.v80; | |||
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.SupportsBlueGreen; | |||
import org.sonar.server.platform.db.migration.def.VarcharColumnDef; | |||
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; | |||
@@ -54,9 +52,6 @@ public class CreateProjectQualityGatesTable extends DdlChange { | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
if (tableExists()) { | |||
return; | |||
} | |||
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME) | |||
.addPkColumn(PROJECT_UUID_COLUMN) | |||
.addColumn(QUALITY_GATE_UUID_COLUMN) | |||
@@ -70,10 +65,4 @@ public class CreateProjectQualityGatesTable extends DdlChange { | |||
.addColumn(QUALITY_GATE_UUID_COLUMN) | |||
.build()); | |||
} | |||
private boolean tableExists() throws SQLException { | |||
try (Connection connection = getDatabase().getDataSource().getConnection()) { | |||
return DatabaseUtils.tableExists(TABLE_NAME, connection); | |||
} | |||
} | |||
} |
@@ -19,10 +19,8 @@ | |||
*/ | |||
package org.sonar.server.platform.db.migration.version.v81; | |||
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.VarcharColumnDef; | |||
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; | |||
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder; | |||
@@ -48,9 +46,6 @@ public class CreateAlmSettingsTable extends DdlChange { | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
if (tableExists()) { | |||
return; | |||
} | |||
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME) | |||
.addPkColumn(newVarcharColumnDefBuilder() | |||
.setColumnName("uuid") | |||
@@ -100,10 +95,4 @@ public class CreateAlmSettingsTable extends DdlChange { | |||
.setUnique(true) | |||
.build()); | |||
} | |||
private boolean tableExists() throws SQLException { | |||
try (Connection connection = getDatabase().getDataSource().getConnection()) { | |||
return DatabaseUtils.tableExists(TABLE_NAME, connection); | |||
} | |||
} | |||
} |
@@ -19,10 +19,8 @@ | |||
*/ | |||
package org.sonar.server.platform.db.migration.version.v81; | |||
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.VarcharColumnDef; | |||
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; | |||
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder; | |||
@@ -55,9 +53,6 @@ public class CreateProjectAlmSettingsTable extends DdlChange { | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
if (tableExists()) { | |||
return; | |||
} | |||
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME) | |||
.addPkColumn(newVarcharColumnDefBuilder() | |||
.setColumnName("uuid") | |||
@@ -99,10 +94,4 @@ public class CreateProjectAlmSettingsTable extends DdlChange { | |||
.setName("project_alm_settings_alm") | |||
.build()); | |||
} | |||
private boolean tableExists() throws SQLException { | |||
try (Connection connection = getDatabase().getDataSource().getConnection()) { | |||
return DatabaseUtils.tableExists(TABLE_NAME, connection); | |||
} | |||
} | |||
} |
@@ -19,10 +19,8 @@ | |||
*/ | |||
package org.sonar.server.platform.db.migration.version.v82; | |||
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.VarcharColumnDef; | |||
import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder; | |||
import org.sonar.server.platform.db.migration.sql.CreateTableBuilder; | |||
@@ -54,10 +52,6 @@ public class CreateAlmPatsTable extends DdlChange { | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
if (tableExists()) { | |||
return; | |||
} | |||
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME) | |||
.addPkColumn(newVarcharColumnDefBuilder() | |||
.setColumnName("uuid") | |||
@@ -89,10 +83,4 @@ public class CreateAlmPatsTable extends DdlChange { | |||
.setUnique(true) | |||
.build()); | |||
} | |||
private boolean tableExists() throws SQLException { | |||
try (Connection connection = getDatabase().getDataSource().getConnection()) { | |||
return DatabaseUtils.tableExists(TABLE_NAME, connection); | |||
} | |||
} | |||
} |
@@ -19,10 +19,8 @@ | |||
*/ | |||
package org.sonar.server.platform.db.migration.version.v82; | |||
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.BooleanColumnDef; | |||
import org.sonar.server.platform.db.migration.def.VarcharColumnDef; | |||
@@ -90,9 +88,6 @@ public class CreateProjectsTable extends DdlChange { | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
if (tableExists()) { | |||
return; | |||
} | |||
context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME) | |||
.withPkConstraintName("pk_new_projects") | |||
.addPkColumn(UUID_COLUMN) | |||
@@ -120,10 +115,4 @@ public class CreateProjectsTable extends DdlChange { | |||
.addColumn(QUALIFIER_COLUMN) | |||
.build()); | |||
} | |||
private boolean tableExists() throws SQLException { | |||
try (Connection connection = getDatabase().getDataSource().getConnection()) { | |||
return DatabaseUtils.tableExists(TABLE_NAME, connection); | |||
} | |||
} | |||
} |
@@ -54,9 +54,6 @@ public class CreateNewCodePeriodTableTest { | |||
dbTester.assertColumnDefinition(TABLE_NAME, "value", VARCHAR, 40, true); | |||
dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, 20, false); | |||
dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, 20, false); | |||
//script should not fail if executed twice | |||
underTest.execute(); | |||
} | |||
} |
@@ -48,8 +48,5 @@ public class CreateProjectQualityGatesTableTest { | |||
dbTester.assertColumnDefinition(TABLE_NAME, "project_uuid", VARCHAR, 40, false); | |||
dbTester.assertColumnDefinition(TABLE_NAME, "quality_gate_uuid", VARCHAR, 40, false); | |||
//script should not fail if executed twice | |||
underTest.execute(); | |||
} | |||
} |
@@ -57,9 +57,6 @@ public class CreateAlmSettingsTableTest { | |||
dbTester.assertColumnDefinition(TABLE_NAME, "pat", VARCHAR, 2000, true); | |||
dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, 20, false); | |||
dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, 20, false); | |||
// script should not fail if executed twice | |||
underTest.execute(); | |||
} | |||
} |
@@ -55,8 +55,5 @@ public class CreateProjectAlmSettingsTableTest { | |||
dbTester.assertColumnDefinition(TABLE_NAME, "alm_slug", VARCHAR, 256, true); | |||
dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, 20, false); | |||
dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, 20, false); | |||
// script should not fail if executed twice | |||
underTest.execute(); | |||
} | |||
} |
@@ -54,9 +54,6 @@ public class CreateAlmPATsTableTest { | |||
dbTester.assertColumnDefinition(TABLE_NAME, "alm_setting_uuid", VARCHAR, 40, false); | |||
dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, 20, false); | |||
dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, 20, false); | |||
// script should not fail if executed twice | |||
underTest.execute(); | |||
} | |||
} |
@@ -58,8 +58,5 @@ public class CreateProjectsTableTest { | |||
dbTester.assertColumnDefinition(TABLE_NAME, "tags", VARCHAR, 500, true); | |||
dbTester.assertColumnDefinition(TABLE_NAME, "created_at", BIGINT, null, true); | |||
dbTester.assertColumnDefinition(TABLE_NAME, "updated_at", BIGINT, null, false); | |||
// script should not fail if executed twice | |||
underTest.execute(); | |||
} | |||
} |
@@ -26,7 +26,7 @@ import org.junit.rules.ExpectedException; | |||
import org.sonar.db.CoreDbTester; | |||
public class RenameProjectsTableToComponentsTest { | |||
private static final String TABLE_NAME = "projects"; | |||
private static final String OLD_TABLE_NAME = "projects"; | |||
private static final String NEW_TABLE_NAME = "components"; | |||
@Rule | |||
@@ -35,27 +35,24 @@ public class RenameProjectsTableToComponentsTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private CreateProjectsTable underTest = new CreateProjectsTable(dbTester.database()); | |||
private RenameProjectsTableToComponents underTest = new RenameProjectsTableToComponents(dbTester.database()); | |||
@Test | |||
public void table_has_been_renamed() throws SQLException { | |||
underTest.execute(); | |||
dbTester.assertTableExists(TABLE_NAME); | |||
dbTester.assertPrimaryKey(TABLE_NAME, "pk_projects", "id"); | |||
dbTester.assertIndex(TABLE_NAME, "PROJECTS_ORGANIZATION", "organization_uuid"); | |||
dbTester.assertUniqueIndex(TABLE_NAME, "PROJECTS_KEE", "kee"); | |||
dbTester.assertIndex(TABLE_NAME, "PROJECTS_ROOT_UUID", "root_uuid"); | |||
dbTester.assertUniqueIndex(TABLE_NAME, "PROJECTS_UUID", "uuid"); | |||
dbTester.assertIndex(TABLE_NAME, "PROJECTS_PROJECT_UUID", "project_uuid"); | |||
dbTester.assertIndex(TABLE_NAME, "PROJECTS_MODULE_UUID", "module_uuid"); | |||
dbTester.assertIndex(TABLE_NAME, "PROJECTS_QUALIFIER", "qualifier"); | |||
dbTester.assertTableDoesNotExist(OLD_TABLE_NAME); | |||
underTest.execute(); | |||
dbTester.assertTableExists(NEW_TABLE_NAME); | |||
dbTester.assertPrimaryKey(NEW_TABLE_NAME, "pk_projects", "id"); | |||
dbTester.assertTableExists(TABLE_NAME); | |||
dbTester.assertIndex(NEW_TABLE_NAME, "PROJECTS_ORGANIZATION", "organization_uuid"); | |||
dbTester.assertUniqueIndex(NEW_TABLE_NAME, "PROJECTS_KEE", "kee"); | |||
dbTester.assertIndex(NEW_TABLE_NAME, "PROJECTS_ROOT_UUID", "root_uuid"); | |||
dbTester.assertUniqueIndex(NEW_TABLE_NAME, "PROJECTS_UUID", "uuid"); | |||
dbTester.assertIndex(NEW_TABLE_NAME, "PROJECTS_PROJECT_UUID", "project_uuid"); | |||
dbTester.assertIndex(NEW_TABLE_NAME, "PROJECTS_MODULE_UUID", "module_uuid"); | |||
dbTester.assertIndex(NEW_TABLE_NAME, "PROJECTS_QUALIFIER", "qualifier"); | |||
} | |||
} |