]> source.dussan.org Git - sonarqube.git/commitdiff
Table creation migrations should not be re-entrant
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 3 Jun 2020 12:34:45 +0000 (14:34 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 3 Jun 2020 20:04:43 +0000 (20:04 +0000)
* 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 tests

24 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/alm/pat/AlmPatMapper.java
server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/alm/setting/AlmSettingMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/alm/pat/AlmPatMapper.xml
server/sonar-db-dao/src/main/resources/org/sonar/db/alm/setting/AlmSettingMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/ALMPatDaoTest.java [deleted file]
server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/AlmPatDaoTest.java [new file with mode: 0644]
server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/AlmSettingDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/sql/CreateTableBuilder.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/CreateNewCodePeriodTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v80/CreateProjectQualityGatesTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/CreateAlmSettingsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v81/CreateProjectAlmSettingsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/CreateAlmPatsTable.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v82/CreateProjectsTable.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/CreateNewCodePeriodTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v80/CreateProjectQualityGatesTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/CreateAlmSettingsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v81/CreateProjectAlmSettingsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/CreateAlmPATsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/CreateProjectsTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/RenameProjectsTableToComponentsTest.java

index 7f0164253ae8970efad9ce9bb90d56b7e5bff155..899df1e53f8e9a389341cbf94870a2342939d429 100644 (file)
@@ -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());
   }
 
-
-
 }
index e4e5b6318b105fa423956e4769222dea36122b9b..a43cbf397e12bcc8b55842e786d331844f79440c 100644 (file)
@@ -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);
 
index a70ba2010878ee8312f251b55d9038656138bfc1..dc7217c00d2393e865f8c375d0a6afb3f7dd16b5 100644 (file)
@@ -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);
   }
 }
index 86fa20a12972928073b587387e9e5ebcfc92166c..49848605e24b2517c3c41785e02fc0f5adc4c040 100644 (file)
@@ -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);
 }
index 68f1fb44b893911bd4479a2c5a2f08aba98114a0..b2a36d237ea0bdb662c6e89e304bd738895d9a0f 100644 (file)
       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}
index f8c29ed4a3b827a529f350bd7085fc8155803ab7..5a2a43e3f31842a8c47ec5f94c155da34941f207 100644 (file)
       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}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/ALMPatDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/ALMPatDaoTest.java
deleted file mode 100644 (file)
index ee08704..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.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.core.util.UuidFactory;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.alm.setting.AlmSettingDao;
-import org.sonar.db.alm.setting.AlmSettingDto;
-import org.sonar.db.user.UserDto;
-
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-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 {
-
-  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);
-  @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);
-
-  @Test
-  public void selectByUuid() {
-    when(uuidFactory.create()).thenReturn(A_UUID);
-    when(system2.now()).thenReturn(NOW);
-
-    AlmPatDto almPatDto = newAlmPatDto();
-    underTest.insert(dbSession, almPatDto);
-
-    assertThat(underTest.selectByUuid(dbSession, A_UUID).get())
-      .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
-        AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
-        AlmPatDto::getUpdatedAt, AlmPatDto::getCreatedAt)
-      .containsExactly(A_UUID, almPatDto.getPersonalAccessToken(),
-        almPatDto.getUserUuid(), almPatDto.getAlmSettingUuid(),
-        NOW, NOW);
-
-    assertThat(underTest.selectByUuid(dbSession, "foo")).isNotPresent();
-  }
-
-  @Test
-  public void selectByAlmSetting() {
-    when(uuidFactory.create()).thenReturn(A_UUID);
-    when(system2.now()).thenReturn(NOW);
-
-    AlmSettingDto almSetting = newGithubAlmSettingDto();
-    almSettingDao.insert(dbSession, almSetting);
-    AlmPatDto almPatDto = newAlmPatDto();
-    almPatDto.setAlmSettingUuid(almSetting.getUuid());
-
-    String userUuid = randomAlphanumeric(40);
-    almPatDto.setUserUuid(userUuid);
-    underTest.insert(dbSession, almPatDto);
-
-    assertThat(underTest.selectByUserAndAlmSetting(dbSession, userUuid, almSetting).get())
-      .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
-        AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
-        AlmPatDto::getCreatedAt, AlmPatDto::getUpdatedAt)
-      .containsExactly(A_UUID, almPatDto.getPersonalAccessToken(),
-        userUuid, almSetting.getUuid(), NOW, NOW);
-
-    assertThat(underTest.selectByUserAndAlmSetting(dbSession, randomAlphanumeric(40), newGithubAlmSettingDto())).isNotPresent();
-  }
-
-  @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);
-    underTest.update(dbSession, almPatDto);
-
-    AlmPatDto result = underTest.selectByUuid(dbSession, A_UUID).get();
-    assertThat(result)
-      .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
-        AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
-        AlmPatDto::getCreatedAt, AlmPatDto::getUpdatedAt)
-      .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);
-
-    underTest.delete(dbSession, almPat);
-
-    assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
-  }
-
-  @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());
-    underTest.insert(dbSession, almPat);
-
-    underTest.deleteByUser(dbSession, userDto);
-
-    assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
-  }
-
-  @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());
-    underTest.insert(dbSession, almPat);
-
-    underTest.deleteByAlmSetting(dbSession, almSettingDto);
-
-    assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
-  }
-
-}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/AlmPatDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/AlmPatDaoTest.java
new file mode 100644 (file)
index 0000000..a215bca
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.db.alm.pat;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.impl.utils.TestSystem2;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.DbSession;
+import org.sonar.db.DbTester;
+import org.sonar.db.alm.setting.AlmSettingDao;
+import org.sonar.db.alm.setting.AlmSettingDto;
+import org.sonar.db.user.UserDto;
+
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+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 {
+
+  private static final long NOW = 1000000L;
+  private static final String A_UUID = "SOME_UUID";
+  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 almSettingDao = new AlmSettingDao(system2, uuidFactory);
+
+  private AlmPatDao underTest = new AlmPatDao(system2, uuidFactory);
+
+  @Test
+  public void selectByUuid() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+
+    AlmPatDto almPatDto = newAlmPatDto();
+    underTest.insert(dbSession, almPatDto);
+
+    assertThat(underTest.selectByUuid(dbSession, A_UUID).get())
+      .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
+        AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
+        AlmPatDto::getUpdatedAt, AlmPatDto::getCreatedAt)
+      .containsExactly(A_UUID, almPatDto.getPersonalAccessToken(),
+        almPatDto.getUserUuid(), almPatDto.getAlmSettingUuid(),
+        NOW, NOW);
+
+    assertThat(underTest.selectByUuid(dbSession, "foo")).isNotPresent();
+  }
+
+  @Test
+  public void selectByAlmSetting() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+
+    AlmSettingDto almSetting = newGithubAlmSettingDto();
+    almSettingDao.insert(dbSession, almSetting);
+    AlmPatDto almPatDto = newAlmPatDto();
+    almPatDto.setAlmSettingUuid(almSetting.getUuid());
+
+    String userUuid = randomAlphanumeric(40);
+    almPatDto.setUserUuid(userUuid);
+    underTest.insert(dbSession, almPatDto);
+
+    assertThat(underTest.selectByUserAndAlmSetting(dbSession, userUuid, almSetting).get())
+      .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
+        AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
+        AlmPatDto::getCreatedAt, AlmPatDto::getUpdatedAt)
+      .containsExactly(A_UUID, almPatDto.getPersonalAccessToken(),
+        userUuid, almSetting.getUuid(), NOW, NOW);
+
+    assertThat(underTest.selectByUserAndAlmSetting(dbSession, randomAlphanumeric(40), newGithubAlmSettingDto())).isNotPresent();
+  }
+
+  @Test
+  public void update() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+    AlmPatDto almPatDto = newAlmPatDto();
+    underTest.insert(dbSession, almPatDto);
+
+    String updated_pat = "updated pat";
+    almPatDto.setPersonalAccessToken(updated_pat);
+
+    system2.setNow(NOW + 1);
+    underTest.update(dbSession, almPatDto);
+
+    AlmPatDto result = underTest.selectByUuid(dbSession, A_UUID).get();
+    assertThat(result)
+      .extracting(AlmPatDto::getUuid, AlmPatDto::getPersonalAccessToken,
+        AlmPatDto::getUserUuid, AlmPatDto::getAlmSettingUuid,
+        AlmPatDto::getCreatedAt, AlmPatDto::getUpdatedAt)
+      .containsExactly(A_UUID, updated_pat, almPatDto.getUserUuid(),
+        almPatDto.getAlmSettingUuid(),
+        NOW, NOW + 1);
+  }
+
+  @Test
+  public void delete() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+    AlmPatDto almPat = newAlmPatDto();
+    underTest.insert(dbSession, almPat);
+
+    underTest.delete(dbSession, almPat);
+
+    assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
+  }
+
+  @Test
+  public void deleteByUser() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+    UserDto userDto = db.users().insertUser();
+    AlmPatDto almPat = newAlmPatDto();
+    almPat.setUserUuid(userDto.getUuid());
+    underTest.insert(dbSession, almPat);
+
+    underTest.deleteByUser(dbSession, userDto);
+
+    assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
+  }
+
+  @Test
+  public void deleteByAlmSetting() {
+    when(uuidFactory.create()).thenReturn(A_UUID);
+    AlmSettingDto almSettingDto = db.almSettings().insertBitbucketAlmSetting();
+    AlmPatDto almPat = newAlmPatDto();
+    almPat.setAlmSettingUuid(almSettingDto.getUuid());
+    underTest.insert(dbSession, almPat);
+
+    underTest.deleteByAlmSetting(dbSession, almSettingDto);
+
+    assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse();
+  }
+
+}
index aa68cbef03f7aedbc227620d538819b183ee73d0..c5571d66943a6f7e30306a1ae4f5c6c32704a8b5 100644 (file)
@@ -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);
 
index 9a81c0d9b56bedfa253848432852aaa3eff01ad5..e38d84145ad20d090a7470dc33442b894e8b7eb0 100644 (file)
@@ -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();
index 4eb83f1e442581cc53f23a5259950795d57bee74..2590ee446f889de0a73b7b44d250c4ea7d77687b 100644 (file)
@@ -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");
 
index a9089a055948b721f880cf620c17ec759a00b419..58f57596afb96ef77bfe72f88da62f4205aa2aff 100644 (file)
  */
 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);
-    }
-  }
 }
index d71419e6f8c338f5ec54e4e10b0088e556682677..b7e5d6227de2ca1cdfffb98f093f9d379f154752 100644 (file)
  */
 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);
-    }
-  }
 }
index 5a52f1fe8e0a7ed71f2fba35d6cf04664af96eee..97a249cf1ef015414a96000d1fb059c47a80dd3d 100644 (file)
  */
 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);
-    }
-  }
 }
index 40e23dc1b2b3b8ce2ed58b88b9d8c7216862f636..4eb499d5a1e291d777051fe395e94ceff952dad0 100644 (file)
  */
 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);
-    }
-  }
 }
index cc62e43372e933f01a2769feea504ca027c5ded4..a7851e1a69d026dbee04bafdc26f6e7426468ac8 100644 (file)
  */
 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);
-    }
-  }
 }
index 4af23a6dcfaef4f91f2dd36c5029045224441392..c01a40e3c458d34af679241458262203b63e7be6 100644 (file)
  */
 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);
-    }
-  }
 }
index 99d924cd38b33e6877e49604b83103288541a5e8..eb2c74bc27621ad98ace0cc02716798c21d2f92c 100644 (file)
@@ -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();
   }
 
 }
index e03de5ee0f2334a62e524408a96711b05e897351..18a59ab29b08c7a4f31d039a8e6bd4985f4edc5e 100644 (file)
@@ -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();
   }
 }
index 345d87619b64445408663f1e779e4140af9b3b1f..02ce0f1caec8d7ec2f91e5c92061655fe53c8d38 100644 (file)
@@ -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();
   }
 
 }
index 1d3c9d5e17d410a201161030246e5ff21aff4556..91e82b6c9a094647c50394734a51873bec40e75e 100644 (file)
@@ -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();
   }
 }
index cbc1001a1fa7dc0649445090e0d9d9db68233097..0b87f0b1a5059514266bba023b1aa940d94f9830 100644 (file)
@@ -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();
   }
 
 }
index 23819e69063a8ae3c63f0f2113abb512cd3d7a88..ed3a8b313cac97bb229acaad39dfae59d6c7f220 100644 (file)
@@ -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();
   }
 }
index 4f48be5381774f00397a06d51efc3fa19d874a50..30b12b3dcc3c2441dbe8b1c023b3769735ffc119 100644 (file)
@@ -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");
   }
 
 }