]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13221 Group roles
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 20 Apr 2020 19:31:14 +0000 (14:31 -0500)
committersonartech <sonartech@sonarsource.com>
Mon, 25 May 2020 20:05:19 +0000 (20:05 +0000)
43 files changed:
server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullable.java [new file with mode: 0644]
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuid.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddComponentUuidColumnToGroupRolesTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropResourceIdFromGroupRolesTableTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullableTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MigrateResourceIdToUuidInGroupRolesTest.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuidTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToPropertiesTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest/schema.sql [deleted file]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddComponentUuidColumnToGroupRolesTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropResourceIdFromGroupRolesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/MigrateResourceIdToUuidInGroupRolesTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuidTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/AddComponentUuidColumnToPropertiesTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/DropResourceIdFromPropertiesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/MigrateResourceIdToUuidInPropertiesTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/AddComponentUuidColumnToUserRolesTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/DropResourceIdFromUserRolesTableTest/schema.sql [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/MigrateResourceIdToUuidInUserRolesTest/schema.sql [new file with mode: 0644]

index 6d4ee373de6f60f252d08508e84c26c3a6285d3c..4a342975896fe60f278c6dc6764b321595be2924 100644 (file)
@@ -27,6 +27,7 @@ import javax.annotation.Nullable;
 import org.apache.ibatis.session.ResultHandler;
 import org.apache.ibatis.session.RowBounds;
 import org.sonar.api.security.DefaultGroups;
+import org.sonar.core.util.Uuids;
 import org.sonar.db.Dao;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentMapper;
@@ -114,6 +115,7 @@ public class GroupPermissionDao implements Dao {
   }
 
   public void insert(DbSession dbSession, GroupPermissionDto dto) {
+    dto.setUuid(Uuids.create());
     ensureComponentPermissionConsistency(dbSession, dto);
     ensureGroupPermissionConsistency(dbSession, dto);
     mapper(dbSession).insert(dto);
index 28d5b87e432d69bd22445536f0d52f08f7683a5f..eb7bf2f8e7ffa2664ed0f64fed1b80c75725ed97 100644 (file)
@@ -22,12 +22,21 @@ package org.sonar.db.permission;
 import javax.annotation.Nullable;
 
 public class GroupPermissionDto {
-
+  private String uuid;
   private String organizationUuid;
   private Integer groupId;
   private String componentUuid;
   private String role;
 
+  public String getUuid() {
+    return uuid;
+  }
+
+  public GroupPermissionDto setUuid(String uuid) {
+    this.uuid = uuid;
+    return this;
+  }
+
   public Integer getGroupId() {
     return groupId;
   }
index d46247961af2ec4bc43833488802b0004615e06d..c74ed2c7133a45705b182106d0388c4b2e8a893b 100644 (file)
@@ -55,7 +55,7 @@
 
   <sql id="groupsByQuery">
     from (
-      select g.id as groupId, g.name as name, gr.role as permission, gr.component_uuid as componentUuid, gr.id as id
+      select g.id as groupId, g.name as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
       from groups g
       left join group_roles gr on g.id = gr.group_id
       <if test="query.componentUuid == null">
@@ -69,7 +69,7 @@
 
     union all
 
-    select 0 as groupId, 'Anyone' as name, gr.role as permission, gr.component_uuid as componentUuid, gr.id as id
+    select 0 as groupId, 'Anyone' as name, gr.role as permission, gr.component_uuid as componentUuid, gr.uuid as uuid
     from group_roles gr
     <where>
       <if test="query.componentUuid == null">
       )
   </select>
 
-  <insert id="insert" parameterType="GroupPermission" keyColumn="id" useGeneratedKeys="false" keyProperty="id">
+  <insert id="insert" parameterType="GroupPermission">
     insert into group_roles (
+    uuid,
     organization_uuid,
     group_id,
     component_uuid,
     role
     ) values (
+    #{uuid,jdbcType=VARCHAR},
     #{organizationUuid,jdbcType=VARCHAR},
     #{groupId,jdbcType=INTEGER},
     #{componentUuid,jdbcType=BIGINT},
index 181ce66e8cfef05e74c3b57682d792ca5b614b4f..443b3b7374c0a4e5d2d71e6b839a21754c0cf0d4 100644 (file)
@@ -599,7 +599,7 @@ public class GroupPermissionDaoTest {
     underTest.deleteByRootComponentUuid(dbSession, project1.uuid());
     dbSession.commit();
 
-    assertThat(db.countSql("select count(id) from group_roles where component_uuid='" + project1.uuid() + "'")).isEqualTo(0);
+    assertThat(db.countSql("select count(uuid) from group_roles where component_uuid='" + project1.uuid() + "'")).isEqualTo(0);
     assertThat(db.countRowsOfTable("group_roles")).isEqualTo(2);
   }
 
@@ -619,7 +619,7 @@ public class GroupPermissionDaoTest {
     underTest.deleteByRootComponentUuid(dbSession, project1.uuid());
     dbSession.commit();
 
-    assertThat(db.countSql("select count(id) from group_roles where component_uuid='" + project1.uuid() + "'")).isEqualTo(0);
+    assertThat(db.countSql("select count(uuid) from group_roles where component_uuid='" + project1.uuid() + "'")).isEqualTo(0);
     assertThat(db.countRowsOfTable("group_roles")).isEqualTo(3);
   }
 
@@ -1055,7 +1055,7 @@ public class GroupPermissionDaoTest {
   }
 
   private void assertThatNoPermission(String permission) {
-    assertThat(db.countSql("select count(id) from group_roles where role='" + permission + "'")).isEqualTo(0);
+    assertThat(db.countSql("select count(uuid) from group_roles where role='" + permission + "'")).isEqualTo(0);
   }
 
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTable.java
new file mode 100644 (file)
index 0000000..ee024e6
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+import org.sonar.server.platform.db.migration.version.v83.util.AddPrimaryKeyBuilder;
+
+public class AddPrimaryKeyOnUuidColumnOfGroupRolesTable extends DdlChange {
+
+  public AddPrimaryKeyOnUuidColumnOfGroupRolesTable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AddPrimaryKeyBuilder("group_roles", "uuid").build());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTable.java
new file mode 100644 (file)
index 0000000..9f4841e
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.AddUuidColumnToTable;
+
+public class AddUuidColumnToGroupRolesTable extends AddUuidColumnToTable {
+  private static final String TABLE = "group_roles";
+
+  public AddUuidColumnToGroupRolesTable(Database db) {
+    super(db, TABLE);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTable.java
new file mode 100644 (file)
index 0000000..3e15cba
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.DropColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIdColumnOfGroupRolesTable extends DdlChange {
+
+  private Database db;
+
+  public DropIdColumnOfGroupRolesTable(Database db) {
+    super(db);
+    this.db = db;
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new DropColumnsBuilder(db.getDialect(), "group_roles", "id").build());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTable.java
new file mode 100644 (file)
index 0000000..9de6c1b
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.version.v83.common.DropPrimaryKeyOnIdColumn;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnIdColumnOfGroupRolesTable extends DropPrimaryKeyOnIdColumn {
+  private static final String TABLE_NAME = "group_roles";
+
+  public DropPrimaryKeyOnIdColumnOfGroupRolesTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+    super(db, dropPrimaryKeySqlGenerator, TABLE_NAME);
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullable.java
new file mode 100644 (file)
index 0000000..b4e54f5
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
+import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class MakeGroupRolesUuidColumnNotNullable extends DdlChange {
+  private static final String TABLE = "group_roles";
+
+  private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+    .setColumnName("uuid")
+    .setIsNullable(false)
+    .setDefaultValue(null)
+    .setLimit(VarcharColumnDef.UUID_SIZE)
+    .build();
+
+  public MakeGroupRolesUuidColumnNotNullable(Database db) {
+    super(db);
+  }
+
+  @Override
+  public void execute(Context context) throws SQLException {
+    context.execute(new AlterColumnsBuilder(getDialect(), TABLE)
+      .updateColumn(uuidColumnDefinition)
+      .build());
+  }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuid.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuid.java
new file mode 100644 (file)
index 0000000..7458ffd
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import java.sql.SQLException;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class PopulateGroupRolesUuid extends DataChange {
+
+  private final UuidFactory uuidFactory;
+
+  public PopulateGroupRolesUuid(Database db, UuidFactory uuidFactory) {
+    super(db);
+    this.uuidFactory = uuidFactory;
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    MassUpdate massUpdate = context.prepareMassUpdate();
+
+    massUpdate.select("select id from group_roles where uuid is null order by id asc");
+    massUpdate.update("update group_roles set uuid = ? where id = ?");
+
+    massUpdate.execute((row, update) -> {
+      update.setString(1, uuidFactory.create());
+      update.setLong(2, row.getLong(1));
+      return true;
+    });
+  }
+}
index ecf218b2023af42ca306cb3fdba752635aaa5587..95cadb9588d8f77fe46be1b810633ace1d3b64a5 100644 (file)
  * 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.v83;
+package org.sonar.server.platform.db.migration.version.v83.grouproles;
 
 import java.sql.SQLException;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v83.grouproles.AddComponentUuidColumnToGroupRoles;
 
 import static java.sql.Types.VARCHAR;
 
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest.java
new file mode 100644 (file)
index 0000000..420d340
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest.class, "schema.sql");
+
+  private AddPrimaryKeyOnUuidColumnOfGroupRolesTable underTest = new AddPrimaryKeyOnUuidColumnOfGroupRolesTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertPrimaryKey("group_roles", "pk_group_roles", "uuid");
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTableTest.java
new file mode 100644 (file)
index 0000000..b0841a2
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddUuidColumnToGroupRolesTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(AddUuidColumnToGroupRolesTableTest.class, "schema.sql");
+
+  private DdlChange underTest = new AddUuidColumnToGroupRolesTable(db.database());
+
+  private UuidFactoryFast uuidFactory = UuidFactoryFast.getInstance();
+
+  @Before
+  public void setup() {
+    insertGroupRoles(1L);
+    insertGroupRoles(2L);
+    insertGroupRoles(3L);
+  }
+
+  @Test
+  public void add_uuid_column() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("group_roles", "uuid", Types.VARCHAR, 40, true);
+
+    assertThat(db.countRowsOfTable("group_roles"))
+      .isEqualTo(3);
+  }
+
+  private void insertGroupRoles(Long id) {
+    db.executeInsert("group_roles",
+      "id", id,
+      "organization_uuid", uuidFactory.create(),
+      "group_id", id + 1,
+      "role", id + 2,
+      "component_uuid", uuidFactory.create());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTableTest.java
new file mode 100644 (file)
index 0000000..5ad2078
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropIdColumnOfGroupRolesTableTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropIdColumnOfGroupRolesTableTest.class, "schema.sql");
+
+  private DropIdColumnOfGroupRolesTable underTest = new DropIdColumnOfGroupRolesTable(db.database());
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDoesNotExist("group_roles", "id");
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.java
new file mode 100644 (file)
index 0000000..35333a4
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.version.v83.util.DropPrimaryKeySqlGenerator;
+import org.sonar.server.platform.db.migration.version.v83.util.SqlHelper;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropPrimaryKeyOnIdColumnOfGroupRolesTableTest {
+
+  private static final String TABLE_NAME = "group_roles";
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.class, "schema.sql");
+
+  private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+
+  private DropPrimaryKeyOnIdColumnOfGroupRolesTable underTest = new DropPrimaryKeyOnIdColumnOfGroupRolesTable(db.database(), dropPrimaryKeySqlGenerator);
+
+  @Test
+  public void execute() throws SQLException {
+    underTest.execute();
+
+    db.assertNoPrimaryKey(TABLE_NAME);
+  }
+
+  @Test
+  public void migration_is_not_re_entrant() throws SQLException {
+    underTest.execute();
+
+    assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+  }
+}
index b5699a17f043872bdb8f15aae9d30878e5102ee2..9ef6c9d2a651168f05d0c7bcd92ff14a0fcb1dfe 100644 (file)
  * 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.v83;
+package org.sonar.server.platform.db.migration.version.v83.grouproles;
 
 import java.sql.SQLException;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v83.grouproles.DropResourceIdFromGroupRolesTable;
 
 import static java.sql.Types.INTEGER;
 
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullableTest.java
new file mode 100644 (file)
index 0000000..86f82e8
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.MigrationStep;
+
+import static java.sql.Types.VARCHAR;
+
+public class MakeGroupRolesUuidColumnNotNullableTest {
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MakeGroupRolesUuidColumnNotNullableTest.class, "schema.sql");
+
+  private MigrationStep underTest = new MakeGroupRolesUuidColumnNotNullable(db.database());
+
+  @Test
+  public void uuid_column_is_not_nullable() throws SQLException {
+    underTest.execute();
+
+    db.assertColumnDefinition("group_roles", "uuid", VARCHAR, null, false);
+  }
+}
index a95648526278321ab23417701f2047ffe9ebf358..112bb4f0309219bc48582f9c30aae70e7bee37d1 100644 (file)
@@ -17,7 +17,7 @@
  * 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.v83;
+package org.sonar.server.platform.db.migration.version.v83.grouproles;
 
 import java.sql.SQLException;
 import java.util.Date;
@@ -28,7 +28,6 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.db.CoreDbTester;
-import org.sonar.server.platform.db.migration.version.v83.grouproles.MigrateResourceIdToUuidInGroupRoles;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuidTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuidTest.java
new file mode 100644 (file)
index 0000000..de1b727
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * 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.server.platform.db.migration.version.v83.grouproles;
+
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.UuidFactory;
+import org.sonar.core.util.UuidFactoryFast;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateGroupRolesUuidTest {
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(PopulateGroupRolesUuidTest.class, "schema.sql");
+
+  private UuidFactory uuidFactory = UuidFactoryFast.getInstance();
+  private DataChange underTest = new PopulateGroupRolesUuid(db.database(), uuidFactory);
+
+  @Test
+  public void populate_uuids() throws SQLException {
+    insertGroupRoles(1L);
+    insertGroupRoles(2L);
+    insertGroupRoles(3L);
+
+    underTest.execute();
+
+    verifyUuidsAreNotNull();
+  }
+
+  @Test
+  public void migration_is_reentrant() throws SQLException {
+    insertGroupRoles(1L);
+    insertGroupRoles(2L);
+    insertGroupRoles(3L);
+
+    underTest.execute();
+    // re-entrant
+    underTest.execute();
+
+    verifyUuidsAreNotNull();
+  }
+
+  private void verifyUuidsAreNotNull() {
+    assertThat(db.select("select uuid from group_roles")
+      .stream()
+      .map(row -> row.get("UUID"))
+      .filter(Objects::isNull)
+      .collect(Collectors.toList())).isEmpty();
+  }
+
+  private void insertGroupRoles(Long id) {
+    db.executeInsert("group_roles",
+      "id", id,
+      "uuid", uuidFactory.create(),
+      "organization_uuid", uuidFactory.create(),
+      "group_id", id + 1,
+      "role", id + 2,
+      "component_uuid", uuidFactory.create());
+  }
+
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest/schema.sql
deleted file mode 100644 (file)
index 9373e3f..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-CREATE TABLE "GROUP_ROLES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
-    "GROUP_ID" INTEGER,
-    "RESOURCE_ID" INTEGER,
-    "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
-CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToPropertiesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToPropertiesTest/schema.sql
deleted file mode 100644 (file)
index 2ac1601..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-CREATE TABLE "PROPERTIES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "PROP_KEY" VARCHAR(512) NOT NULL,
-    "RESOURCE_ID" BIGINT,
-    "USER_ID" BIGINT,
-    "IS_EMPTY" BOOLEAN NOT NULL,
-    "TEXT_VALUE" VARCHAR(4000),
-    "CLOB_VALUE" CLOB(2147483647),
-    "CREATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
-CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest/schema.sql
deleted file mode 100644 (file)
index b4879f3..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-CREATE TABLE "USER_ROLES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
-    "USER_ID" INTEGER,
-    "RESOURCE_ID" INTEGER,
-    "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
-CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
-CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest/schema.sql
deleted file mode 100644 (file)
index 36a3d90..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-CREATE TABLE "GROUP_ROLES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
-     "COMPONENT_UUID" VARCHAR(50),
-    "GROUP_ID" INTEGER,
-    "RESOURCE_ID" INTEGER,
-    "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
-CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
-CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest/schema.sql
deleted file mode 100644 (file)
index 529e0a0..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-CREATE TABLE "PROPERTIES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "COMPONENT_UUID" VARCHAR(50),
-    "PROP_KEY" VARCHAR(512) NOT NULL,
-    "RESOURCE_ID" BIGINT,
-    "USER_ID" BIGINT,
-    "IS_EMPTY" BOOLEAN NOT NULL,
-    "TEXT_VALUE" VARCHAR(4000),
-    "CLOB_VALUE" CLOB(2147483647),
-    "CREATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
-CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest/schema.sql
deleted file mode 100644 (file)
index 62e4238..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-CREATE TABLE "USER_ROLES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
-    "COMPONENT_UUID" VARCHAR(50),
-    "USER_ID" INTEGER,
-    "RESOURCE_ID" INTEGER,
-    "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
-CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
-CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
-CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest/schema.sql
deleted file mode 100644 (file)
index 04d3cb4..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-CREATE TABLE "GROUP_ROLES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
-     "COMPONENT_UUID" VARCHAR(50),
-    "GROUP_ID" INTEGER,
-    "RESOURCE_ID" INTEGER,
-    "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
-CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
-CREATE UNIQUE INDEX "GROUP_ROLES_UNIQ" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
-CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
-CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
-
-CREATE TABLE "COMPONENTS"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "UUID" VARCHAR(50) NOT NULL,
-    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
-    "KEE" VARCHAR(400),
-    "DEPRECATED_KEE" VARCHAR(400),
-    "NAME" VARCHAR(2000),
-    "LONG_NAME" VARCHAR(2000),
-    "DESCRIPTION" VARCHAR(2000),
-    "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
-    "SCOPE" VARCHAR(3),
-    "QUALIFIER" VARCHAR(10),
-    "PRIVATE" BOOLEAN NOT NULL,
-    "ROOT_UUID" VARCHAR(50) NOT NULL,
-    "LANGUAGE" VARCHAR(20),
-    "COPY_COMPONENT_UUID" VARCHAR(50),
-    "PATH" VARCHAR(2000),
-    "UUID_PATH" VARCHAR(1500) NOT NULL,
-    "PROJECT_UUID" VARCHAR(50) NOT NULL,
-    "MODULE_UUID" VARCHAR(50),
-    "MODULE_UUID_PATH" VARCHAR(1500),
-    "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
-    "B_CHANGED" BOOLEAN,
-    "B_NAME" VARCHAR(500),
-    "B_LONG_NAME" VARCHAR(500),
-    "B_DESCRIPTION" VARCHAR(2000),
-    "B_ENABLED" BOOLEAN,
-    "B_QUALIFIER" VARCHAR(10),
-    "B_LANGUAGE" VARCHAR(20),
-    "B_COPY_COMPONENT_UUID" VARCHAR(50),
-    "B_PATH" VARCHAR(2000),
-    "B_UUID_PATH" VARCHAR(1500),
-    "B_MODULE_UUID" VARCHAR(50),
-    "B_MODULE_UUID_PATH" VARCHAR(1500),
-    "CREATED_AT" TIMESTAMP
-);
-ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
-CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
-CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
-CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
-CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
-CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
-CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
-CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest/schema.sql
deleted file mode 100644 (file)
index aff8977..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-CREATE TABLE "PROPERTIES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "COMPONENT_UUID" VARCHAR(50),
-    "PROP_KEY" VARCHAR(512) NOT NULL,
-    "RESOURCE_ID" BIGINT,
-    "USER_ID" BIGINT,
-    "IS_EMPTY" BOOLEAN NOT NULL,
-    "TEXT_VALUE" VARCHAR(4000),
-    "CLOB_VALUE" CLOB(2147483647),
-    "CREATED_AT" BIGINT NOT NULL
-);
-ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
-CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
-
-CREATE TABLE "COMPONENTS"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "UUID" VARCHAR(50) NOT NULL,
-    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
-    "KEE" VARCHAR(400),
-    "DEPRECATED_KEE" VARCHAR(400),
-    "NAME" VARCHAR(2000),
-    "LONG_NAME" VARCHAR(2000),
-    "DESCRIPTION" VARCHAR(2000),
-    "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
-    "SCOPE" VARCHAR(3),
-    "QUALIFIER" VARCHAR(10),
-    "PRIVATE" BOOLEAN NOT NULL,
-    "ROOT_UUID" VARCHAR(50) NOT NULL,
-    "LANGUAGE" VARCHAR(20),
-    "COPY_COMPONENT_UUID" VARCHAR(50),
-    "PATH" VARCHAR(2000),
-    "UUID_PATH" VARCHAR(1500) NOT NULL,
-    "PROJECT_UUID" VARCHAR(50) NOT NULL,
-    "MODULE_UUID" VARCHAR(50),
-    "MODULE_UUID_PATH" VARCHAR(1500),
-    "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
-    "B_CHANGED" BOOLEAN,
-    "B_NAME" VARCHAR(500),
-    "B_LONG_NAME" VARCHAR(500),
-    "B_DESCRIPTION" VARCHAR(2000),
-    "B_ENABLED" BOOLEAN,
-    "B_QUALIFIER" VARCHAR(10),
-    "B_LANGUAGE" VARCHAR(20),
-    "B_COPY_COMPONENT_UUID" VARCHAR(50),
-    "B_PATH" VARCHAR(2000),
-    "B_UUID_PATH" VARCHAR(1500),
-    "B_MODULE_UUID" VARCHAR(50),
-    "B_MODULE_UUID_PATH" VARCHAR(1500),
-    "CREATED_AT" TIMESTAMP
-);
-ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
-CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
-CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
-CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
-CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
-CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
-CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
-CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest/schema.sql
deleted file mode 100644 (file)
index fb91fd3..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-CREATE TABLE "USER_ROLES"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
-    "COMPONENT_UUID" VARCHAR(50),
-    "USER_ID" INTEGER,
-    "RESOURCE_ID" INTEGER,
-    "ROLE" VARCHAR(64) NOT NULL
-);
-ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
-CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
-CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
-CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID");
-
-CREATE TABLE "COMPONENTS"(
-    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
-    "UUID" VARCHAR(50) NOT NULL,
-    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
-    "KEE" VARCHAR(400),
-    "DEPRECATED_KEE" VARCHAR(400),
-    "NAME" VARCHAR(2000),
-    "LONG_NAME" VARCHAR(2000),
-    "DESCRIPTION" VARCHAR(2000),
-    "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
-    "SCOPE" VARCHAR(3),
-    "QUALIFIER" VARCHAR(10),
-    "PRIVATE" BOOLEAN NOT NULL,
-    "ROOT_UUID" VARCHAR(50) NOT NULL,
-    "LANGUAGE" VARCHAR(20),
-    "COPY_COMPONENT_UUID" VARCHAR(50),
-    "PATH" VARCHAR(2000),
-    "UUID_PATH" VARCHAR(1500) NOT NULL,
-    "PROJECT_UUID" VARCHAR(50) NOT NULL,
-    "MODULE_UUID" VARCHAR(50),
-    "MODULE_UUID_PATH" VARCHAR(1500),
-    "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
-    "B_CHANGED" BOOLEAN,
-    "B_NAME" VARCHAR(500),
-    "B_LONG_NAME" VARCHAR(500),
-    "B_DESCRIPTION" VARCHAR(2000),
-    "B_ENABLED" BOOLEAN,
-    "B_QUALIFIER" VARCHAR(10),
-    "B_LANGUAGE" VARCHAR(20),
-    "B_COPY_COMPONENT_UUID" VARCHAR(50),
-    "B_PATH" VARCHAR(2000),
-    "B_UUID_PATH" VARCHAR(1500),
-    "B_MODULE_UUID" VARCHAR(50),
-    "B_MODULE_UUID_PATH" VARCHAR(1500),
-    "CREATED_AT" TIMESTAMP
-);
-ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
-CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
-CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
-CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
-CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
-CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
-CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
-CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddComponentUuidColumnToGroupRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddComponentUuidColumnToGroupRolesTest/schema.sql
new file mode 100644 (file)
index 0000000..9373e3f
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "GROUP_ROLES"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "GROUP_ID" INTEGER,
+    "RESOURCE_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
+CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..3203c14
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "GROUP_ROLES"(
+    "ID" INTEGER NOT NULL,
+    "UUID" VARCHAR(40) NOT NULL,
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "GROUP_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(40)
+);
+
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..b91324d
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "GROUP_ROLES"(
+    "ID" INTEGER NOT NULL,
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "GROUP_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..7ecca2b
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "GROUP_ROLES"(
+    "ID" INTEGER NOT NULL,
+    "UUID" VARCHAR(40) NOT NULL,
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "GROUP_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("UUID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..d7d1320
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "GROUP_ROLES"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(40) NOT NULL,
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "GROUP_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropResourceIdFromGroupRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropResourceIdFromGroupRolesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..36a3d90
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "GROUP_ROLES"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+     "COMPONENT_UUID" VARCHAR(50),
+    "GROUP_ID" INTEGER,
+    "RESOURCE_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
+CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullableTest/schema.sql
new file mode 100644 (file)
index 0000000..7c73be2
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "GROUP_ROLES"(
+    "ID" INTEGER NOT NULL,
+    "UUID" VARCHAR(40),
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "GROUP_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/MigrateResourceIdToUuidInGroupRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/MigrateResourceIdToUuidInGroupRolesTest/schema.sql
new file mode 100644 (file)
index 0000000..04d3cb4
--- /dev/null
@@ -0,0 +1,58 @@
+CREATE TABLE "GROUP_ROLES"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+     "COMPONENT_UUID" VARCHAR(50),
+    "GROUP_ID" INTEGER,
+    "RESOURCE_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "RESOURCE_ID", "ROLE");
+CREATE UNIQUE INDEX "GROUP_ROLES_UNIQ" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
+CREATE INDEX "GROUP_ROLES_RESOURCE" ON "GROUP_ROLES"("RESOURCE_ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+
+CREATE TABLE "COMPONENTS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(50) NOT NULL,
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(400),
+    "DEPRECATED_KEE" VARCHAR(400),
+    "NAME" VARCHAR(2000),
+    "LONG_NAME" VARCHAR(2000),
+    "DESCRIPTION" VARCHAR(2000),
+    "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+    "SCOPE" VARCHAR(3),
+    "QUALIFIER" VARCHAR(10),
+    "PRIVATE" BOOLEAN NOT NULL,
+    "ROOT_UUID" VARCHAR(50) NOT NULL,
+    "LANGUAGE" VARCHAR(20),
+    "COPY_COMPONENT_UUID" VARCHAR(50),
+    "PATH" VARCHAR(2000),
+    "UUID_PATH" VARCHAR(1500) NOT NULL,
+    "PROJECT_UUID" VARCHAR(50) NOT NULL,
+    "MODULE_UUID" VARCHAR(50),
+    "MODULE_UUID_PATH" VARCHAR(1500),
+    "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
+    "B_CHANGED" BOOLEAN,
+    "B_NAME" VARCHAR(500),
+    "B_LONG_NAME" VARCHAR(500),
+    "B_DESCRIPTION" VARCHAR(2000),
+    "B_ENABLED" BOOLEAN,
+    "B_QUALIFIER" VARCHAR(10),
+    "B_LANGUAGE" VARCHAR(20),
+    "B_COPY_COMPONENT_UUID" VARCHAR(50),
+    "B_PATH" VARCHAR(2000),
+    "B_UUID_PATH" VARCHAR(1500),
+    "B_MODULE_UUID" VARCHAR(50),
+    "B_MODULE_UUID_PATH" VARCHAR(1500),
+    "CREATED_AT" TIMESTAMP
+);
+ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
+CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuidTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuidTest/schema.sql
new file mode 100644 (file)
index 0000000..7c73be2
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "GROUP_ROLES"(
+    "ID" INTEGER NOT NULL,
+    "UUID" VARCHAR(40),
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "GROUP_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(40)
+);
+ALTER TABLE "GROUP_ROLES" ADD CONSTRAINT "PK_GROUP_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "GROUP_ROLES_COMPONENT_UUID" ON "GROUP_ROLES"("COMPONENT_UUID");
+CREATE UNIQUE INDEX "UNIQ_GROUP_ROLES" ON "GROUP_ROLES"("ORGANIZATION_UUID", "GROUP_ID", "COMPONENT_UUID", "ROLE");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/AddComponentUuidColumnToPropertiesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/AddComponentUuidColumnToPropertiesTest/schema.sql
new file mode 100644 (file)
index 0000000..2ac1601
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "PROPERTIES"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "PROP_KEY" VARCHAR(512) NOT NULL,
+    "RESOURCE_ID" BIGINT,
+    "USER_ID" BIGINT,
+    "IS_EMPTY" BOOLEAN NOT NULL,
+    "TEXT_VALUE" VARCHAR(4000),
+    "CLOB_VALUE" CLOB(2147483647),
+    "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/DropResourceIdFromPropertiesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/DropResourceIdFromPropertiesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..529e0a0
--- /dev/null
@@ -0,0 +1,13 @@
+CREATE TABLE "PROPERTIES"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "COMPONENT_UUID" VARCHAR(50),
+    "PROP_KEY" VARCHAR(512) NOT NULL,
+    "RESOURCE_ID" BIGINT,
+    "USER_ID" BIGINT,
+    "IS_EMPTY" BOOLEAN NOT NULL,
+    "TEXT_VALUE" VARCHAR(4000),
+    "CLOB_VALUE" CLOB(2147483647),
+    "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/MigrateResourceIdToUuidInPropertiesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/MigrateResourceIdToUuidInPropertiesTest/schema.sql
new file mode 100644 (file)
index 0000000..aff8977
--- /dev/null
@@ -0,0 +1,58 @@
+CREATE TABLE "PROPERTIES"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "COMPONENT_UUID" VARCHAR(50),
+    "PROP_KEY" VARCHAR(512) NOT NULL,
+    "RESOURCE_ID" BIGINT,
+    "USER_ID" BIGINT,
+    "IS_EMPTY" BOOLEAN NOT NULL,
+    "TEXT_VALUE" VARCHAR(4000),
+    "CLOB_VALUE" CLOB(2147483647),
+    "CREATED_AT" BIGINT NOT NULL
+);
+ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PK_PROPERTIES" PRIMARY KEY("ID");
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES"("PROP_KEY");
+
+CREATE TABLE "COMPONENTS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(50) NOT NULL,
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(400),
+    "DEPRECATED_KEE" VARCHAR(400),
+    "NAME" VARCHAR(2000),
+    "LONG_NAME" VARCHAR(2000),
+    "DESCRIPTION" VARCHAR(2000),
+    "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+    "SCOPE" VARCHAR(3),
+    "QUALIFIER" VARCHAR(10),
+    "PRIVATE" BOOLEAN NOT NULL,
+    "ROOT_UUID" VARCHAR(50) NOT NULL,
+    "LANGUAGE" VARCHAR(20),
+    "COPY_COMPONENT_UUID" VARCHAR(50),
+    "PATH" VARCHAR(2000),
+    "UUID_PATH" VARCHAR(1500) NOT NULL,
+    "PROJECT_UUID" VARCHAR(50) NOT NULL,
+    "MODULE_UUID" VARCHAR(50),
+    "MODULE_UUID_PATH" VARCHAR(1500),
+    "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
+    "B_CHANGED" BOOLEAN,
+    "B_NAME" VARCHAR(500),
+    "B_LONG_NAME" VARCHAR(500),
+    "B_DESCRIPTION" VARCHAR(2000),
+    "B_ENABLED" BOOLEAN,
+    "B_QUALIFIER" VARCHAR(10),
+    "B_LANGUAGE" VARCHAR(20),
+    "B_COPY_COMPONENT_UUID" VARCHAR(50),
+    "B_PATH" VARCHAR(2000),
+    "B_UUID_PATH" VARCHAR(1500),
+    "B_MODULE_UUID" VARCHAR(50),
+    "B_MODULE_UUID_PATH" VARCHAR(1500),
+    "CREATED_AT" TIMESTAMP
+);
+ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
+CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/AddComponentUuidColumnToUserRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/AddComponentUuidColumnToUserRolesTest/schema.sql
new file mode 100644 (file)
index 0000000..b4879f3
--- /dev/null
@@ -0,0 +1,10 @@
+CREATE TABLE "USER_ROLES"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "USER_ID" INTEGER,
+    "RESOURCE_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/DropResourceIdFromUserRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/DropResourceIdFromUserRolesTableTest/schema.sql
new file mode 100644 (file)
index 0000000..62e4238
--- /dev/null
@@ -0,0 +1,12 @@
+CREATE TABLE "USER_ROLES"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50),
+    "USER_ID" INTEGER,
+    "RESOURCE_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
+CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID");
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/MigrateResourceIdToUuidInUserRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/MigrateResourceIdToUuidInUserRolesTest/schema.sql
new file mode 100644 (file)
index 0000000..fb91fd3
--- /dev/null
@@ -0,0 +1,57 @@
+CREATE TABLE "USER_ROLES"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "COMPONENT_UUID" VARCHAR(50),
+    "USER_ID" INTEGER,
+    "RESOURCE_ID" INTEGER,
+    "ROLE" VARCHAR(64) NOT NULL
+);
+ALTER TABLE "USER_ROLES" ADD CONSTRAINT "PK_USER_ROLES" PRIMARY KEY("ID");
+CREATE INDEX "USER_ROLES_RESOURCE" ON "USER_ROLES"("RESOURCE_ID");
+CREATE INDEX "USER_ROLES_USER" ON "USER_ROLES"("USER_ID");
+CREATE INDEX "USER_ROLES_COMPONENT_UUID" ON "USER_ROLES"("COMPONENT_UUID");
+
+CREATE TABLE "COMPONENTS"(
+    "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+    "UUID" VARCHAR(50) NOT NULL,
+    "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+    "KEE" VARCHAR(400),
+    "DEPRECATED_KEE" VARCHAR(400),
+    "NAME" VARCHAR(2000),
+    "LONG_NAME" VARCHAR(2000),
+    "DESCRIPTION" VARCHAR(2000),
+    "ENABLED" BOOLEAN DEFAULT TRUE NOT NULL,
+    "SCOPE" VARCHAR(3),
+    "QUALIFIER" VARCHAR(10),
+    "PRIVATE" BOOLEAN NOT NULL,
+    "ROOT_UUID" VARCHAR(50) NOT NULL,
+    "LANGUAGE" VARCHAR(20),
+    "COPY_COMPONENT_UUID" VARCHAR(50),
+    "PATH" VARCHAR(2000),
+    "UUID_PATH" VARCHAR(1500) NOT NULL,
+    "PROJECT_UUID" VARCHAR(50) NOT NULL,
+    "MODULE_UUID" VARCHAR(50),
+    "MODULE_UUID_PATH" VARCHAR(1500),
+    "MAIN_BRANCH_PROJECT_UUID" VARCHAR(50),
+    "B_CHANGED" BOOLEAN,
+    "B_NAME" VARCHAR(500),
+    "B_LONG_NAME" VARCHAR(500),
+    "B_DESCRIPTION" VARCHAR(2000),
+    "B_ENABLED" BOOLEAN,
+    "B_QUALIFIER" VARCHAR(10),
+    "B_LANGUAGE" VARCHAR(20),
+    "B_COPY_COMPONENT_UUID" VARCHAR(50),
+    "B_PATH" VARCHAR(2000),
+    "B_UUID_PATH" VARCHAR(1500),
+    "B_MODULE_UUID" VARCHAR(50),
+    "B_MODULE_UUID_PATH" VARCHAR(1500),
+    "CREATED_AT" TIMESTAMP
+);
+ALTER TABLE "COMPONENTS" ADD CONSTRAINT "PK_PROJECTS" PRIMARY KEY("ID");
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "COMPONENTS"("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "COMPONENTS"("KEE");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "COMPONENTS"("MODULE_UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "COMPONENTS"("PROJECT_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "COMPONENTS"("QUALIFIER");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "COMPONENTS"("ROOT_UUID");
+CREATE INDEX "PROJECTS_UUID" ON "COMPONENTS"("UUID");