From be7d7c94ba8620dd326a3442082e68667efcc41e Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 20 Apr 2020 14:31:14 -0500 Subject: [PATCH] SONAR-13221 Group roles --- .../db/permission/GroupPermissionDao.java | 2 + .../db/permission/GroupPermissionDto.java | 11 ++- .../db/permission/GroupPermissionMapper.xml | 8 +- .../db/permission/GroupPermissionDaoTest.java | 6 +- ...imaryKeyOnUuidColumnOfGroupRolesTable.java | 38 +++++++++ .../AddUuidColumnToGroupRolesTable.java | 31 +++++++ .../DropIdColumnOfGroupRolesTable.java | 41 +++++++++ ...PrimaryKeyOnIdColumnOfGroupRolesTable.java | 32 +++++++ .../MakeGroupRolesUuidColumnNotNullable.java | 50 +++++++++++ .../grouproles/PopulateGroupRolesUuid.java | 50 +++++++++++ ...ddComponentUuidColumnToGroupRolesTest.java | 3 +- ...yKeyOnUuidColumnOfGroupRolesTableTest.java | 49 +++++++++++ .../AddUuidColumnToGroupRolesTableTest.java | 68 +++++++++++++++ .../DropIdColumnOfGroupRolesTableTest.java | 50 +++++++++++ ...aryKeyOnIdColumnOfGroupRolesTableTest.java | 55 ++++++++++++ ...DropResourceIdFromGroupRolesTableTest.java | 3 +- ...keGroupRolesUuidColumnNotNullableTest.java | 42 ++++++++++ ...grateResourceIdToUuidInGroupRolesTest.java | 3 +- .../PopulateGroupRolesUuidTest.java | 84 +++++++++++++++++++ .../schema.sql | 0 .../schema.sql | 11 +++ .../schema.sql | 10 +++ .../schema.sql | 11 +++ .../schema.sql | 11 +++ .../schema.sql | 0 .../schema.sql | 11 +++ .../schema.sql | 0 .../PopulateGroupRolesUuidTest/schema.sql | 11 +++ .../schema.sql | 0 .../schema.sql | 0 .../schema.sql | 0 .../schema.sql | 0 .../schema.sql | 0 .../schema.sql | 0 34 files changed, 678 insertions(+), 13 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuid.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuidTest.java rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => grouproles}/AddComponentUuidColumnToGroupRolesTest/schema.sql (100%) create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest/schema.sql rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => grouproles}/DropResourceIdFromGroupRolesTableTest/schema.sql (100%) create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullableTest/schema.sql rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => grouproles}/MigrateResourceIdToUuidInGroupRolesTest/schema.sql (100%) create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuidTest/schema.sql rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => properties}/AddComponentUuidColumnToPropertiesTest/schema.sql (100%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => properties}/DropResourceIdFromPropertiesTableTest/schema.sql (100%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => properties}/MigrateResourceIdToUuidInPropertiesTest/schema.sql (100%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => userroles}/AddComponentUuidColumnToUserRolesTest/schema.sql (100%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => userroles}/DropResourceIdFromUserRolesTableTest/schema.sql (100%) rename server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/{ => userroles}/MigrateResourceIdToUuidInUserRolesTest/schema.sql (100%) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java index 6d4ee373de6..4a342975896 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDao.java @@ -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); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java index 28d5b87e432..eb7bf2f8e7f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/permission/GroupPermissionDto.java @@ -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; } diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml index d46247961af..c74ed2c7133 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/permission/GroupPermissionMapper.xml @@ -55,7 +55,7 @@ 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 @@ -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 @@ -196,13 +196,15 @@ ) - + 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}, diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java index 181ce66e8cf..443b3b7374c 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java @@ -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 index 00000000000..ee024e616f4 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTable.java @@ -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 index 00000000000..9f4841e0d00 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTable.java @@ -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 index 00000000000..3e15cba01d7 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTable.java @@ -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 index 00000000000..9de6c1beae8 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTable.java @@ -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 index 00000000000..b4e54f50d06 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullable.java @@ -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 index 00000000000..7458ffd1e06 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuid.java @@ -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; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddComponentUuidColumnToGroupRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddComponentUuidColumnToGroupRolesTest.java index ecf218b2023..95cadb9588d 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddComponentUuidColumnToGroupRolesTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddComponentUuidColumnToGroupRolesTest.java @@ -17,14 +17,13 @@ * 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 index 00000000000..420d3401f03 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest.java @@ -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 index 00000000000..b0841a2ab15 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTableTest.java @@ -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 index 00000000000..5ad2078afc0 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTableTest.java @@ -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 index 00000000000..35333a4b651 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropResourceIdFromGroupRolesTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropResourceIdFromGroupRolesTableTest.java index b5699a17f04..9ef6c9d2a65 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropResourceIdFromGroupRolesTableTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/DropResourceIdFromGroupRolesTableTest.java @@ -17,14 +17,13 @@ * 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 index 00000000000..86f82e8470e --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullableTest.java @@ -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); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MigrateResourceIdToUuidInGroupRolesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MigrateResourceIdToUuidInGroupRolesTest.java index a9564852627..112bb4f0309 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MigrateResourceIdToUuidInGroupRolesTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/MigrateResourceIdToUuidInGroupRolesTest.java @@ -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 index 00000000000..de1b72765ba --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuidTest.java @@ -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/grouproles/AddComponentUuidColumnToGroupRolesTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToGroupRolesTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddComponentUuidColumnToGroupRolesTest/schema.sql 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 index 00000000000..3203c1421d1 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddPrimaryKeyOnUuidColumnOfGroupRolesTableTest/schema.sql @@ -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 index 00000000000..b91324d4572 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/AddUuidColumnToGroupRolesTableTest/schema.sql @@ -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 index 00000000000..7ecca2b6b71 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropIdColumnOfGroupRolesTableTest/schema.sql @@ -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 index 00000000000..d7d1320aebe --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropPrimaryKeyOnIdColumnOfGroupRolesTableTest/schema.sql @@ -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/DropResourceIdFromGroupRolesTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropResourceIdFromGroupRolesTableTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromGroupRolesTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/DropResourceIdFromGroupRolesTableTest/schema.sql 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 index 00000000000..7c73be272fd --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/MakeGroupRolesUuidColumnNotNullableTest/schema.sql @@ -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/MigrateResourceIdToUuidInGroupRolesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/MigrateResourceIdToUuidInGroupRolesTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInGroupRolesTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/MigrateResourceIdToUuidInGroupRolesTest/schema.sql 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 index 00000000000..7c73be272fd --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/grouproles/PopulateGroupRolesUuidTest/schema.sql @@ -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/AddComponentUuidColumnToPropertiesTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/AddComponentUuidColumnToPropertiesTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToPropertiesTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/AddComponentUuidColumnToPropertiesTest/schema.sql 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/properties/DropResourceIdFromPropertiesTableTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromPropertiesTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/DropResourceIdFromPropertiesTableTest/schema.sql 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/properties/MigrateResourceIdToUuidInPropertiesTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInPropertiesTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/properties/MigrateResourceIdToUuidInPropertiesTest/schema.sql 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/userroles/AddComponentUuidColumnToUserRolesTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/AddComponentUuidColumnToUserRolesTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/AddComponentUuidColumnToUserRolesTest/schema.sql 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/userroles/DropResourceIdFromUserRolesTableTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/DropResourceIdFromUserRolesTableTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/DropResourceIdFromUserRolesTableTest/schema.sql 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/userroles/MigrateResourceIdToUuidInUserRolesTest/schema.sql similarity index 100% rename from server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/MigrateResourceIdToUuidInUserRolesTest/schema.sql rename to server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v83/userroles/MigrateResourceIdToUuidInUserRolesTest/schema.sql -- 2.39.5