}
private boolean isUserMemberOfOrganization(DbSession dbSession, UserDto user) {
- return dbClient.organizationMemberDao().select(dbSession, analysisMetadataHolder.getOrganization().getUuid(), user.getId()).isPresent();
+ return dbClient.organizationMemberDao().select(dbSession, analysisMetadataHolder.getOrganization().getUuid(), user.getUuid()).isPresent();
}
}
return dbSession.getMapper(OrganizationMemberMapper.class);
}
- public Optional<OrganizationMemberDto> select(DbSession dbSession, String organizationUuid, int userId) {
- return Optional.ofNullable(mapper(dbSession).select(organizationUuid, userId));
+ public Optional<OrganizationMemberDto> select(DbSession dbSession, String organizationUuid, String userUuid) {
+ return Optional.ofNullable(mapper(dbSession).select(organizationUuid, userUuid));
}
public List<String> selectUserUuidsByOrganizationUuid(DbSession dbSession, String organizationUuid) {
return mapper(dbSession).selectUserUuids(organizationUuid);
}
- public List<Integer> selectUserIdsByOrganizationUuid(DbSession dbSession, String organizationUuid) {
- return mapper(dbSession).selectUserIds(organizationUuid);
- }
-
public void insert(DbSession dbSession, OrganizationMemberDto organizationMemberDto) {
mapper(dbSession).insert(organizationMemberDto);
}
- public void delete(DbSession dbSession, String organizationMemberUuid, Integer userId) {
- mapper(dbSession).delete(organizationMemberUuid, userId);
+ public void delete(DbSession dbSession, String organizationMemberUuid, String userUuid) {
+ mapper(dbSession).delete(organizationMemberUuid, userUuid);
}
public void deleteByOrganizationUuid(DbSession dbSession, String organizationMemberUuid) {
mapper(dbSession).deleteByOrganization(organizationMemberUuid);
}
- public void deleteByUserId(DbSession dbSession, int userId) {
- mapper(dbSession).deleteByUserId(userId);
+ public void deleteByUserUuid(DbSession dbSession, String userUuid) {
+ mapper(dbSession).deleteByUserUuid(userUuid);
}
- public Set<String> selectOrganizationUuidsByUser(DbSession dbSession, int userId) {
- return mapper(dbSession).selectOrganizationUuidsByUser(userId);
+ public Set<String> selectOrganizationUuidsByUser(DbSession dbSession, String userUuid) {
+ return mapper(dbSession).selectOrganizationUuidsByUser(userUuid);
}
/**
public class OrganizationMemberDto {
private String organizationUuid;
- private Integer userId;
+ private String userUuid;
public String getOrganizationUuid() {
return organizationUuid;
return this;
}
- public Integer getUserId() {
- return userId;
+ public String getUserUuid() {
+ return userUuid;
}
- public OrganizationMemberDto setUserId(Integer userId) {
- this.userId = userId;
+ public OrganizationMemberDto setUserUuid(String userUuid) {
+ this.userUuid = userUuid;
return this;
}
}
import org.apache.ibatis.annotations.Param;
public interface OrganizationMemberMapper {
- OrganizationMemberDto select(@Param("organizationUuid") String organizationUuid, @Param("userId") int userId);
+ OrganizationMemberDto select(@Param("organizationUuid") String organizationUuid, @Param("userUuid") String userUuid);
- Set<String> selectOrganizationUuidsByUser(@Param("userId") int userId);
+ Set<String> selectOrganizationUuidsByUser(@Param("userUuid") String userUuid);
List<String> selectUserUuids(String organizationUuid);
- List<Integer> selectUserIds(String organizationUuid);
-
List<Map<String, String>> selectForIndexing(@Param("uuids") List<String> uuids);
List<Map<String, String>> selectAllForIndexing();
void insert(OrganizationMemberDto organizationMember);
- void delete(@Param("organizationUuid") String organizationUuid, @Param("userId") Integer userId);
+ void delete(@Param("organizationUuid") String organizationUuid, @Param("userUuid") String userUuid);
void deleteByOrganization(@Param("organizationUuid") String organizationUuid);
- void deleteByUserId(@Param("userId") int userId);
+ void deleteByUserUuid(@Param("userUuid") String userUuid);
}
private static final OrganizationQuery NO_FILTER = newOrganizationQueryBuilder().build();
private final Set<String> keys;
@Nullable
- private final Integer userId;
+ private final String userUuid;
private final boolean withAnalyses;
@Nullable
private final Long analyzedAfter;
private OrganizationQuery(Builder builder) {
this.keys = builder.keys;
- this.userId = builder.member;
+ this.userUuid = builder.member;
this.withAnalyses = builder.withAnalyses;
this.analyzedAfter = builder.analyzedAfter;
}
}
@CheckForNull
- public Integer getMember() {
- return userId;
+ public String getMember() {
+ return userUuid;
}
public boolean isWithAnalyses() {
public static class Builder {
private Set<String> keys;
@Nullable
- private Integer member;
+ private String member;
private boolean withAnalyses = false;
@Nullable
private Long analyzedAfter;
return this;
}
- public Builder setMember(@Nullable Integer userId) {
- this.member = userId;
+ public Builder setMember(@Nullable String userUuid) {
+ this.member = userUuid;
return this;
}
from organizations org
<if test="query.member != null">
inner join organization_members om on org.uuid=om.organization_uuid
- and om.user_id=#{query.member,jdbcType=INTEGER}
+ and om.user_uuid=#{query.member,jdbcType=VARCHAR}
</if>
<where>
<if test="query.keys != null">
<mapper namespace="org.sonar.db.organization.OrganizationMemberMapper">
<sql id="selectColumns">
om.organization_uuid as "organizationUuid",
- om.user_id as "userId"
+ om.user_uuid as "userUuid"
</sql>
<select id="select" resultType="OrganizationMember">
from organization_members om
where
om.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- and om.user_id = #{userId, jdbcType=INTEGER}
+ and om.user_uuid = #{userUuid, jdbcType=VARCHAR}
</select>
- <select id="selectUserUuids" resultType="string">
- select u.uuid
- from organization_members om
- inner join users u on om.user_id = u.id
- where om.organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
- </select>
-
- <select id="selectUserIds" resultType="Integer">
- select om.user_id
+ <select id="selectUserUuids" resultType="String">
+ select om.user_uuid
from organization_members om
where om.organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
</select>
<select id="selectOrganizationUuidsByUser" resultType="String">
select om.organization_uuid as "organizationUuid"
from organization_members om
- where om.user_id = #{userId, jdbcType=INTEGER}
+ where om.user_uuid = #{userUuid, jdbcType=VARCHAR}
</select>
<select id="selectForIndexing" resultType="hashmap">
- select u.uuid as "uuid", om.organization_uuid as "organizationUuid"
+ select om.user_uuid as "uuid", om.organization_uuid as "organizationUuid"
from organization_members om
- inner join users u on om.user_id=u.id
- where u.uuid in
+ where om.user_uuid in
<foreach collection="uuids" open="(" close=")" item="uuid" separator=",">
#{uuid, jdbcType=VARCHAR}
</foreach>
</select>
<select id="selectAllForIndexing" resultType="hashmap">
- select u.uuid as "uuid", om.organization_uuid as "organizationUuid"
+ select om.user_uuid as "uuid", om.organization_uuid as "organizationUuid"
from organization_members om
- inner join users u on om.user_id=u.id
</select>
<insert id="insert" parameterType="OrganizationMember" useGeneratedKeys="false">
insert into organization_members
(
organization_uuid,
- user_id
+ user_uuid
)
values
(
#{organizationUuid, jdbcType=VARCHAR},
- #{userId, jdbcType=INTEGER}
+ #{userUuid, jdbcType=VARCHAR}
)
</insert>
delete from organization_members
where
organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
- and user_id = #{userId, jdbcType=INTEGER}
+ and user_uuid = #{userUuid, jdbcType=VARCHAR}
</delete>
<delete id="deleteByOrganization" parameterType="map">
organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
</delete>
- <delete id="deleteByUserId" parameterType="int">
- DELETE FROM organization_members WHERE user_id=#{userId,jdbcType=BIGINT}
+ <delete id="deleteByUserUuid" parameterType="String">
+ DELETE FROM organization_members WHERE user_uuid=#{userUuid,jdbcType=VARCHAR}
</delete>
</mapper>
</otherwise>
</choose>
left join components p on ur.component_uuid = p.uuid
- inner join organization_members om on u.id=om.user_id and om.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR}
+ inner join organization_members om on u.uuid=om.user_uuid and om.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR}
<where>
<include refid="sqlQueryFilters" />
</where>
from users u
left join user_roles ur on ur.user_id = u.id
left join components p on ur.component_uuid = p.uuid
- inner join organization_members om on u.id=om.user_id and om.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR}
+ inner join organization_members om on u.uuid=om.user_uuid and om.organization_uuid=#{query.organizationUuid,jdbcType=VARCHAR}
</sql>
<sql id="sqlQueryFilters">
FROM users u
LEFT JOIN perm_templates_users ptu ON ptu.user_id=u.id
AND ptu.template_uuid=#{templateUuid}
- INNER JOIN organization_members om ON u.id=om.user_id
+ INNER JOIN organization_members om ON u.uuid=om.user_uuid
AND om.organization_uuid=#{query.organizationUuid}
<where>
u.active = ${_true}
<sql id="sqlSelectByQuery">
FROM users u
LEFT JOIN qprofile_edit_users qeu ON qeu.user_id=u.id AND qeu.qprofile_uuid=#{query.qProfileUuid, jdbcType=VARCHAR}
- INNER JOIN organization_members om ON u.id=om.user_id AND om.organization_uuid=#{query.organizationUuid, jdbcType=VARCHAR}
+ INNER JOIN organization_members om ON u.uuid=om.user_uuid AND om.organization_uuid=#{query.organizationUuid, jdbcType=VARCHAR}
<where>
<choose>
<when test="query.getMembership() == 'IN'">
<sql id="userCommonClauses">
FROM users u
LEFT JOIN groups_users gu ON gu.user_uuid=u.uuid AND gu.group_uuid=#{groupUuid}
- INNER JOIN organization_members om ON u.id=om.user_id AND om.organization_uuid=#{organizationUuid}
+ INNER JOIN organization_members om ON u.uuid=om.user_uuid AND om.organization_uuid=#{organizationUuid}
<where>
<choose>
<when test="query.membership() == 'IN'">
CREATE TABLE "ORGANIZATION_MEMBERS"(
"ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
- "USER_ID" INTEGER NOT NULL
+ "USER_UUID" VARCHAR(40) NOT NULL
);
-ALTER TABLE "ORGANIZATION_MEMBERS" ADD CONSTRAINT "PK_ORGANIZATION_MEMBERS" PRIMARY KEY("ORGANIZATION_UUID", "USER_ID");
-CREATE INDEX "IX_ORG_MEMBERS_ON_USER_ID" ON "ORGANIZATION_MEMBERS"("USER_ID");
+ALTER TABLE "ORGANIZATION_MEMBERS" ADD CONSTRAINT "PK_ORGANIZATION_MEMBERS" PRIMARY KEY("USER_UUID", "ORGANIZATION_UUID");
+CREATE INDEX "ORG_MEMBERS_USER_UUID" ON "ORGANIZATION_MEMBERS"("USER_UUID");
CREATE TABLE "ORGANIZATIONS"(
"UUID" VARCHAR(40) NOT NULL,
db.organizations().addMember(organization, user);
db.organizations().addMember(anotherOrganization, user);
- List<OrganizationDto> result = underTest.selectByQuery(dbSession, newOrganizationQueryBuilder().setMember(user.getId()).build(), forPage(1).andSize(100));
+ List<OrganizationDto> result = underTest.selectByQuery(dbSession, newOrganizationQueryBuilder().setMember(user.getUuid()).build(), forPage(1).andSize(100));
assertThat(result).extracting(OrganizationDto::getUuid)
.containsExactlyInAnyOrder(organization.getUuid(), anotherOrganization.getUuid())
List<OrganizationDto> result = underTest.selectByQuery(dbSession, newOrganizationQueryBuilder()
.setKeys(Arrays.asList(organization.getKey(), anotherOrganization.getKey(), organizationWithoutMember.getKey()))
- .setMember(user.getId()).build(), forPage(1).andSize(100));
+ .setMember(user.getUuid()).build(), forPage(1).andSize(100));
assertThat(result).extracting(OrganizationDto::getUuid)
.containsExactlyInAnyOrder(organization.getUuid(), anotherOrganization.getUuid())
@Test
public void select() {
- underTest.insert(dbSession, create("O1", 512));
+ underTest.insert(dbSession, create("O1", "512"));
- Optional<OrganizationMemberDto> result = underTest.select(dbSession, "O1", 512);
+ Optional<OrganizationMemberDto> result = underTest.select(dbSession, "O1", "512");
assertThat(result).isPresent();
- assertThat(result.get()).extracting(OrganizationMemberDto::getOrganizationUuid, OrganizationMemberDto::getUserId).containsExactly("O1", 512);
- assertThat(underTest.select(dbSession, "O1", 256)).isNotPresent();
- assertThat(underTest.select(dbSession, "O2", 512)).isNotPresent();
+ assertThat(result.get()).extracting(OrganizationMemberDto::getOrganizationUuid, OrganizationMemberDto::getUserUuid).containsExactly("O1", "512");
+ assertThat(underTest.select(dbSession, "O1", "256")).isNotPresent();
+ assertThat(underTest.select(dbSession, "O2", "512")).isNotPresent();
}
@Test
}
@Test
- public void select_user_ids() {
- OrganizationDto organization = db.organizations().insert();
- OrganizationDto anotherOrganization = db.organizations().insert();
- UserDto user = db.users().insertUser();
- UserDto anotherUser = db.users().insertUser();
- UserDto userInAnotherOrganization = db.users().insertUser();
- db.organizations().addMember(organization, user);
- db.organizations().addMember(organization, anotherUser);
- db.organizations().addMember(anotherOrganization, userInAnotherOrganization);
-
- List<Integer> result = underTest.selectUserIdsByOrganizationUuid(dbSession, organization.getUuid());
-
- assertThat(result).containsOnly(user.getId(), anotherUser.getId());
- }
-
- @Test
- public void select_organization_uuids_by_user_id() {
+ public void select_organization_uuids_by_user_uuid() {
OrganizationDto organizationDto1 = db.organizations().insert();
OrganizationDto organizationDto2 = db.organizations().insert();
OrganizationDto organizationDto3 = db.organizations().insert();
- underTest.insert(dbSession, create(organizationDto1.getUuid(), 512));
- underTest.insert(dbSession, create(organizationDto2.getUuid(), 512));
+ underTest.insert(dbSession, create(organizationDto1.getUuid(), "512"));
+ underTest.insert(dbSession, create(organizationDto2.getUuid(), "512"));
- assertThat(underTest.selectOrganizationUuidsByUser(dbSession, 512)).containsOnly(organizationDto1.getUuid(), organizationDto2.getUuid())
+ assertThat(underTest.selectOrganizationUuidsByUser(dbSession, "512")).containsOnly(organizationDto1.getUuid(), organizationDto2.getUuid())
.doesNotContain(organizationDto3.getUuid());
- assertThat(underTest.selectOrganizationUuidsByUser(dbSession, 123)).isEmpty();
+ assertThat(underTest.selectOrganizationUuidsByUser(dbSession, "123")).isEmpty();
}
@Test
@Test
public void insert() {
- underTest.insert(dbSession, create("O_1", 256));
+ underTest.insert(dbSession, create("O_1", "256"));
- Map<String, Object> result = db.selectFirst(dbSession, "select organization_uuid as \"organizationUuid\", user_id as \"userId\" from organization_members");
+ Map<String, Object> result = db.selectFirst(dbSession, "select organization_uuid as \"organizationUuid\", user_uuid as \"userUuid\" from organization_members");
- assertThat(result).containsOnly(entry("organizationUuid", "O_1"), entry("userId", 256L));
+ assertThat(result).containsOnly(entry("organizationUuid", "O_1"), entry("userUuid", "256"));
}
@Test
public void fail_insert_if_no_organization_uuid() {
expectedException.expect(PersistenceException.class);
- underTest.insert(dbSession, create(null, 256));
+ underTest.insert(dbSession, create(null, "256"));
}
@Test
- public void fail_insert_if_no_user_id() {
+ public void fail_insert_if_no_user_uuid() {
expectedException.expect(PersistenceException.class);
underTest.insert(dbSession, create("O_1", null));
@Test
public void fail_if_organization_member_already_exist() {
- underTest.insert(dbSession, create("O_1", 256));
+ underTest.insert(dbSession, create("O_1", "256"));
expectedException.expect(PersistenceException.class);
- underTest.insert(dbSession, create("O_1", 256));
+ underTest.insert(dbSession, create("O_1", "256"));
}
@Test
public void delete_by_organization() {
- underTest.insert(dbSession, create("O1", 512));
- underTest.insert(dbSession, create("O1", 513));
- underTest.insert(dbSession, create("O2", 512));
+ underTest.insert(dbSession, create("O1", "512"));
+ underTest.insert(dbSession, create("O1", "513"));
+ underTest.insert(dbSession, create("O2", "512"));
underTest.deleteByOrganizationUuid(dbSession, "O1");
- assertThat(underTest.select(dbSession, "O1", 512)).isNotPresent();
- assertThat(underTest.select(dbSession, "O1", 513)).isNotPresent();
- assertThat(underTest.select(dbSession, "O2", 512)).isPresent();
+ assertThat(underTest.select(dbSession, "O1", "512")).isNotPresent();
+ assertThat(underTest.select(dbSession, "O1", "513")).isNotPresent();
+ assertThat(underTest.select(dbSession, "O2", "512")).isPresent();
}
@Test
- public void delete_by_user_id() {
- underTest.insert(dbSession, create("O1", 512));
- underTest.insert(dbSession, create("O1", 513));
- underTest.insert(dbSession, create("O2", 512));
+ public void delete_by_user_uuid() {
+ underTest.insert(dbSession, create("O1", "512"));
+ underTest.insert(dbSession, create("O1", "513"));
+ underTest.insert(dbSession, create("O2", "512"));
- underTest.deleteByUserId(dbSession, 512);
+ underTest.deleteByUserUuid(dbSession, "512");
db.commit();
- assertThat(db.select("select organization_uuid as \"organizationUuid\", user_id as \"userId\" from organization_members"))
- .extracting((row) -> row.get("organizationUuid"), (row) -> row.get("userId"))
- .containsOnly(tuple("O1", 513L));
+ assertThat(db.select("select organization_uuid as \"organizationUuid\", user_uuid as \"userUuid\" from organization_members"))
+ .extracting((row) -> row.get("organizationUuid"), (row) -> row.get("userUuid"))
+ .containsOnly(tuple("O1", "513"));
}
- private OrganizationMemberDto create(String organizationUuid, Integer userId) {
+ private OrganizationMemberDto create(String organizationUuid, String userUuid) {
return new OrganizationMemberDto()
.setOrganizationUuid(organizationUuid)
- .setUserId(userId);
+ .setUserUuid(userUuid);
}
}
public void addMember(OrganizationDto organization, UserDto... users) {
Arrays.stream(users)
- .forEach(u -> db.getDbClient().organizationMemberDao().insert(db.getSession(), new OrganizationMemberDto().setOrganizationUuid(organization.getUuid()).setUserId(u.getId())));
+ .forEach(
+ u -> db.getDbClient().organizationMemberDao().insert(db.getSession(), new OrganizationMemberDto().setOrganizationUuid(organization.getUuid()).setUserUuid(u.getUuid())));
db.commit();
}
}
public void assertUserIsMemberOfOrganization(OrganizationDto organization, UserDto user) {
- assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), organization.getUuid(), user.getId())).as("User is not member of the organization").isPresent();
+ assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), organization.getUuid(), user.getUuid())).as("User is not member of the organization").isPresent();
String defaultGroupUuid = db.getDbClient().organizationDao().getDefaultGroupUuid(db.getSession(), organization.getUuid()).get();
assertThat(db.getDbClient().groupMembershipDao().selectGroups(
db.getSession(),
}
public void assertUserIsNotMemberOfOrganization(OrganizationDto organization, UserDto user) {
- assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), organization.getUuid(), user.getId())).as("User is still member of the organization")
+ assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), organization.getUuid(), user.getUuid())).as("User is still member of the organization")
.isNotPresent();
assertThat(db.getDbClient().groupMembershipDao().countGroups(db.getSession(),
GroupMembershipQuery.builder().membership(IN).organizationUuid(organization.getUuid()).build(),
import org.sonar.server.platform.db.migration.version.v83.users.fk.groupsusers.DropUserIdColumnOfGroupsUsersTable;
import org.sonar.server.platform.db.migration.version.v83.users.fk.groupsusers.MakeGroupsUsersUserUuidColumnNotNullable;
import org.sonar.server.platform.db.migration.version.v83.users.fk.groupsusers.PopulateGroupsUsersUserUuid;
+import org.sonar.server.platform.db.migration.version.v83.users.fk.organizationmembers.AddIndexOnUserUuidOfOrganizationMembersTable;
+import org.sonar.server.platform.db.migration.version.v83.users.fk.organizationmembers.AddPrimaryKeyOnUserUuidAndOrganizationUuidColumnsOfUserRolesTable;
+import org.sonar.server.platform.db.migration.version.v83.users.fk.organizationmembers.AddUserUuidColumnToOrganizationMembers;
+import org.sonar.server.platform.db.migration.version.v83.users.fk.organizationmembers.DropIndexOnUserIdOfOrganizationMembersTable;
+import org.sonar.server.platform.db.migration.version.v83.users.fk.organizationmembers.DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable;
+import org.sonar.server.platform.db.migration.version.v83.users.fk.organizationmembers.DropUserIdColumnOfOrganizationMembersTable;
+import org.sonar.server.platform.db.migration.version.v83.users.fk.organizationmembers.MakeOrganizationMembersUserUuidColumnNotNullable;
+import org.sonar.server.platform.db.migration.version.v83.users.fk.organizationmembers.PopulateOrganizationMembersUserUuid;
import org.sonar.server.platform.db.migration.version.v83.usertokens.AddPrimaryKeyOnUuidColumnOfUserTokensTable;
import org.sonar.server.platform.db.migration.version.v83.usertokens.AddUuidColumnToUserTokens;
import org.sonar.server.platform.db.migration.version.v83.usertokens.DropIdColumnOfUserTokensTable;
.add(3641, "Add unique index on 'user_uuid', 'group_id' columns of 'GROUPS_USERS' table", AddUniqueIndexOnUserUuidAndGroupIdOfGroupsUsersTable.class)
.add(3642, "Drop column on 'user_id' column of 'GROUPS_USERS' table", DropUserIdColumnOfGroupsUsersTable.class)
-
- ;
+ // Migration of FK in ORGANIZATION_MEMBERS to USERS
+ .add(3643, "Add 'user_uuid' column on 'ORGANIZATION_MEMBERS' table", AddUserUuidColumnToOrganizationMembers.class)
+ .add(3644, "Populate 'user_uuid' for 'ORGANIZATION_MEMBERS'", PopulateOrganizationMembersUserUuid.class)
+ .add(3645, "Make 'user_uuid' not-null for 'ORGANIZATION_MEMBERS'", MakeOrganizationMembersUserUuidColumnNotNullable.class)
+ .add(3646, "Drop index on 'user_id' column of 'ORGANIZATION_MEMBERS' table", DropIndexOnUserIdOfOrganizationMembersTable.class)
+ .add(3647, "Add index on 'user_uuid' column of 'ORGANIZATION_MEMBERS' table", AddIndexOnUserUuidOfOrganizationMembersTable.class)
+ .add(3648, "Drop index on 'user_id', 'group_id' columns of 'ORGANIZATION_MEMBERS' table", DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable.class)
+ .add(3649, "Add PK on 'user_uuid', 'organization_uuid' columns of 'ORGANIZATION_MEMBERS' table", AddPrimaryKeyOnUserUuidAndOrganizationUuidColumnsOfUserRolesTable.class)
+ .add(3650, "Drop column on 'user_id' column of 'ORGANIZATION_MEMBERS' table", DropUserIdColumnOfOrganizationMembersTable.class);
}
}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddIndexOnUserUuidOfOrganizationMembersTable extends DdlChange {
+ private static final String TABLE_NAME = "organization_members";
+ private static final String INDEX_NAME = "org_members_user_uuid";
+
+ public AddIndexOnUserUuidOfOrganizationMembersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (!indexExists()) {
+ context.execute(new CreateIndexBuilder()
+ .setUnique(false)
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .addColumn(newVarcharColumnDefBuilder()
+ .setColumnName("user_uuid")
+ .setLimit(UUID_SIZE)
+ .build())
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+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 AddPrimaryKeyOnUserUuidAndOrganizationUuidColumnsOfUserRolesTable extends DdlChange {
+
+ public AddPrimaryKeyOnUserUuidAndOrganizationUuidColumnsOfUserRolesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddPrimaryKeyBuilder("organization_members", "user_uuid", "organization_uuid").build());
+ }
+
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+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.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddUserUuidColumnToOrganizationMembers extends DdlChange {
+ private static final String TABLE = "organization_members";
+
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("user_uuid")
+ .setIsNullable(true)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public AddUserUuidColumnToOrganizationMembers(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), TABLE)
+ .addColumn(uuidColumnDefinition)
+ .build());
+ }
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class DropIndexOnUserIdOfOrganizationMembersTable extends DdlChange {
+ private static final String TABLE_NAME = "organization_members";
+ private static final String INDEX_NAME = "ix_org_members_on_user_id";
+
+ public DropIndexOnUserIdOfOrganizationMembersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ if (indexExists()) {
+ context.execute(new DropIndexBuilder(getDialect())
+ .setTable(TABLE_NAME)
+ .setName(INDEX_NAME)
+ .build());
+ }
+ }
+
+ private boolean indexExists() throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ return DatabaseUtils.indexExists(TABLE_NAME, INDEX_NAME, connection);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+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.DropPrimaryKeySqlGenerator;
+
+public class DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable extends DdlChange {
+ private static final String TABLE_NAME = "organization_members";
+
+ private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator;
+
+ public DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator) {
+ super(db);
+ this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator;
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(dropPrimaryKeySqlGenerator.generate(TABLE_NAME, "user_id", false));
+ }
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+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 DropUserIdColumnOfOrganizationMembersTable extends DdlChange {
+ public DropUserIdColumnOfOrganizationMembersTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new DropColumnsBuilder(getDialect(), "organization_members", "user_id").build());
+ }
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+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 MakeOrganizationMembersUserUuidColumnNotNullable extends DdlChange {
+ private static final String TABLE_NAME = "organization_members";
+ private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder()
+ .setColumnName("user_uuid")
+ .setIsNullable(false)
+ .setDefaultValue(null)
+ .setLimit(VarcharColumnDef.UUID_SIZE)
+ .build();
+
+ public MakeOrganizationMembersUserUuidColumnNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AlterColumnsBuilder(getDialect(), TABLE_NAME)
+ .updateColumn(uuidColumnDefinition)
+ .build());
+ }
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+import java.sql.SQLException;
+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 PopulateOrganizationMembersUserUuid extends DataChange {
+
+ public PopulateOrganizationMembersUserUuid(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select om.user_id, om.organization_uuid, u.uuid " +
+ "from organization_members om " +
+ "join users u on om.user_id = u.id where om.user_uuid is null");
+
+ massUpdate.update("update organization_members set user_uuid = ? where organization_uuid = ? and user_id = ?");
+
+ massUpdate.execute((row, update, index) -> {
+ long userId = row.getLong(1);
+ String organizationUuid = row.getString(2);
+ String userUuid = row.getString(3);
+
+ update.setString(1, userUuid);
+ update.setString(2, organizationUuid);
+ update.setLong(3, userId);
+ return true;
+ });
+ }
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+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.DdlChange;
+
+public class AddIndexOnUserUuidOfOrganizationMembersTableTest {
+
+ private static final String TABLE_NAME = "organization_members";
+ private static final String INDEX_NAME = "org_members_user_uuid";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(AddIndexOnUserUuidOfOrganizationMembersTableTest.class, "schema.sql");
+
+ DdlChange underTest = new AddIndexOnUserUuidOfOrganizationMembersTable(dbTester.database());
+
+ @Test
+ public void add_index() throws SQLException {
+ underTest.execute();
+ dbTester.assertIndex(TABLE_NAME, INDEX_NAME, "user_uuid");
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ underTest.execute();
+ dbTester.assertIndex(TABLE_NAME, INDEX_NAME, "user_uuid");
+ }
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+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.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class AddPrimaryKeyOnUserUuidAndOrganizationUuidColumnsOfUserRolesTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddPrimaryKeyOnUserUuidAndOrganizationUuidColumnsOfUserRolesTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddPrimaryKeyOnUserUuidAndOrganizationUuidColumnsOfUserRolesTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertPrimaryKey("organization_members", "pk_organization_members", "user_uuid", "organization_uuid");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AddUserUuidColumnToOrganizationMembersTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(AddUserUuidColumnToOrganizationMembersTest.class, "schema.sql");
+
+ private DdlChange underTest = new AddUserUuidColumnToOrganizationMembers(db.database());
+
+ @Before
+ public void setup() {
+ insertGroupUser(1L);
+ insertGroupUser(2L);
+ insertGroupUser(3L);
+ }
+
+ @Test
+ public void add_uuid_column() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("organization_members", "user_uuid", Types.VARCHAR, 40, true);
+
+ assertThat(db.countSql("select count(*) from organization_members"))
+ .isEqualTo(3);
+ }
+
+ private void insertGroupUser(Long id) {
+ db.executeInsert("organization_members",
+ "user_id", id,
+ "organization_uuid", "uuid-" + id);
+ }
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+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.DdlChange;
+
+public class DropIndexOnUserIdOfOrganizationMembersTableTest {
+
+ private static final String TABLE_NAME = "organization_members";
+ private static final String INDEX_NAME = "ix_org_members_on_user_id";
+
+ @Rule
+ public CoreDbTester dbTester = CoreDbTester.createForSchema(DropIndexOnUserIdOfOrganizationMembersTableTest.class, "schema.sql");
+
+ DdlChange underTest = new DropIndexOnUserIdOfOrganizationMembersTable(dbTester.database());
+
+ @Test
+ public void add_index() throws SQLException {
+ underTest.execute();
+ dbTester.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ underTest.execute();
+ dbTester.assertIndexDoesNotExist(TABLE_NAME, INDEX_NAME);
+ }
+
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+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.DdlChange;
+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 DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTableTest {
+ private static final String TABLE_NAME = "organization_members";
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTableTest.class, "schema.sql");
+
+ private DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator = new DropPrimaryKeySqlGenerator(db.database(), new SqlHelper(db.database()));
+
+ private DdlChange underTest = new DropPrimaryKeyOnUserIdAndOrganizationUuidOfOrganizationMembersTable(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);
+ }
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+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.DdlChange;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class DropUserIdColumnOfOrganizationMembersTableTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DropUserIdColumnOfOrganizationMembersTableTest.class, "schema.sql");
+
+ private DdlChange underTest = new DropUserIdColumnOfOrganizationMembersTable(db.database());
+
+ @Test
+ public void execute() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDoesNotExist("organization_members", "user_id");
+ }
+
+ @Test
+ public void migration_is_not_re_entrant() throws SQLException {
+ underTest.execute();
+
+ assertThatThrownBy(() -> underTest.execute()).isInstanceOf(IllegalStateException.class);
+ }
+
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+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;
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
+
+public class MakeOrganizationMembersUserUuidColumnNotNullableTest {
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(MakeOrganizationMembersUserUuidColumnNotNullableTest.class, "schema.sql");
+
+ private MigrationStep underTest = new MakeOrganizationMembersUserUuidColumnNotNullable(db.database());
+
+ @Test
+ public void uuid_column_is_not_null() throws SQLException {
+ underTest.execute();
+
+ db.assertColumnDefinition("organization_members", "user_uuid", VARCHAR, UUID_SIZE, false);
+ }
+}
--- /dev/null
+/*
+ * 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.users.fk.organizationmembers;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.core.util.Uuids;
+import org.sonar.db.CoreDbTester;
+import org.sonar.server.platform.db.migration.step.DataChange;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PopulateOrganizationMembersUserUuidTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(PopulateOrganizationMembersUserUuidTest.class, "schema.sql");
+
+ private DataChange underTest = new PopulateOrganizationMembersUserUuid(db.database());
+
+ @Test
+ public void populate_uuids() throws SQLException {
+ long userId_1 = 1L;
+ String userUuid_1 = "uuid-1";
+ insertUser(userId_1, userUuid_1);
+
+ long userId_2 = 2L;
+ String userUuid_2 = "uuid-2";
+ insertUser(userId_2, userUuid_2);
+
+ long userId_3 = 3L;
+ String userUuid_3 = "uuid-3";
+ insertUser(userId_3, userUuid_3);
+
+ long userId_4 = 4L;
+ String userUuid_4 = "uuid-4";
+ insertUser(userId_4, userUuid_4);
+
+ String organizationUuid_1 = Uuids.createFast();
+ insertOrganizationMember(userId_1, organizationUuid_1);
+ String organizationUuid_2 = Uuids.createFast();
+ insertOrganizationMember(userId_2, organizationUuid_2);
+ String organizationUuid_3 = Uuids.createFast();
+ insertOrganizationMember(userId_3, organizationUuid_3);
+ String organizationUuid_4 = Uuids.createFast();
+ insertOrganizationMember(userId_4, organizationUuid_4);
+ String organizationUuid_5 = Uuids.createFast();
+ insertOrganizationMember(userId_1, organizationUuid_5);
+
+ underTest.execute();
+
+ assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_1, organizationUuid_1, userUuid_1);
+ assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_2, organizationUuid_2, userUuid_2);
+ assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_3, organizationUuid_3, userUuid_3);
+ assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_4, organizationUuid_4, userUuid_4);
+ assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_1, organizationUuid_5, userUuid_1);
+ }
+
+ @Test
+ public void migration_is_reentrant() throws SQLException {
+ long userId_1 = 1L;
+ String userUuid_1 = "uuid-1";
+ insertUser(userId_1, userUuid_1);
+
+ long userId_2 = 2L;
+ String userUuid_2 = "uuid-2";
+ insertUser(userId_2, userUuid_2);
+
+ long userId_3 = 3L;
+ String userUuid_3 = "uuid-3";
+ insertUser(userId_3, userUuid_3);
+
+ long userId_4 = 4L;
+ String userUuid_4 = "uuid-4";
+ insertUser(userId_4, userUuid_4);
+
+ String organizationUuid_1 = Uuids.createFast();
+ insertOrganizationMember(userId_1, organizationUuid_1);
+ String organizationUuid_2 = Uuids.createFast();
+ insertOrganizationMember(userId_2, organizationUuid_2);
+ String organizationUuid_3 = Uuids.createFast();
+ insertOrganizationMember(userId_3, organizationUuid_3);
+
+ underTest.execute();
+
+ String organizationUuid_4 = Uuids.createFast();
+ insertOrganizationMember(userId_3, organizationUuid_4);
+
+ // re-entrant
+ underTest.execute();
+
+ assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_1, organizationUuid_1, userUuid_1);
+ assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_2, organizationUuid_2, userUuid_2);
+ assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_3, organizationUuid_3, userUuid_3);
+ assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_3, organizationUuid_4, userUuid_3);
+ }
+
+ private void assertThatQProfileChangeRulesProfileUuidIsEqualTo(Long userId, String organizationUuid, String expectedUuid) {
+ assertThat(db.select(String.format("select user_uuid from organization_members where user_id = %d and organization_uuid = '%s'", userId, organizationUuid))
+ .stream()
+ .map(row -> row.get("USER_UUID"))
+ .findFirst())
+ .hasValue(expectedUuid);
+ }
+
+ private void insertOrganizationMember(Long userId, String organizationUuid) {
+ db.executeInsert("organization_members",
+ "user_id", userId,
+ "organization_uuid", organizationUuid);
+ }
+
+ private void insertUser(Long id, String uuid) {
+ db.executeInsert("users",
+ "id", id,
+ "uuid", uuid,
+ "login", "login" + id,
+ "external_login", "ex-login" + id,
+ "external_identity_provider", "ex-provider" + id,
+ "external_id", id + 1,
+ "is_root", false,
+ "onboarded", false);
+ }
+}
--- /dev/null
+CREATE TABLE "ORGANIZATION_MEMBERS"(
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "USER_ID" INTEGER NOT NULL,
+ "USER_UUID" VARCHAR(40) NOT NULL,
+);
+ALTER TABLE "ORGANIZATION_MEMBERS" ADD CONSTRAINT "PK_ORGANIZATION_MEMBERS" PRIMARY KEY("ORGANIZATION_UUID", "USER_ID");
+
--- /dev/null
+CREATE TABLE "ORGANIZATION_MEMBERS"(
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "USER_ID" INTEGER NOT NULL,
+ "USER_UUID" VARCHAR(40) NOT NULL,
+);
+CREATE INDEX "ORG_MEMBERS_ON_USER_ID" ON "ORGANIZATION_MEMBERS"("USER_UUID");
+
--- /dev/null
+CREATE TABLE "ORGANIZATION_MEMBERS"(
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "USER_ID" INTEGER NOT NULL
+);
+ALTER TABLE "ORGANIZATION_MEMBERS" ADD CONSTRAINT "PK_ORGANIZATION_MEMBERS" PRIMARY KEY("ORGANIZATION_UUID", "USER_ID");
+CREATE INDEX "IX_ORG_MEMBERS_ON_USER_ID" ON "ORGANIZATION_MEMBERS"("USER_ID");
+
--- /dev/null
+CREATE TABLE "ORGANIZATION_MEMBERS"(
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "USER_ID" INTEGER NOT NULL,
+ "USER_UUID" VARCHAR(40) NOT NULL,
+);
+ALTER TABLE "ORGANIZATION_MEMBERS" ADD CONSTRAINT "PK_ORGANIZATION_MEMBERS" PRIMARY KEY("ORGANIZATION_UUID", "USER_ID");
+CREATE INDEX "IX_ORG_MEMBERS_ON_USER_ID" ON "ORGANIZATION_MEMBERS"("USER_ID");
+
--- /dev/null
+CREATE TABLE "ORGANIZATION_MEMBERS"(
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "USER_ID" INTEGER NOT NULL,
+ "USER_UUID" VARCHAR(40) NOT NULL,
+);
+ALTER TABLE "ORGANIZATION_MEMBERS" ADD CONSTRAINT "PK_ORGANIZATION_MEMBERS" PRIMARY KEY("ORGANIZATION_UUID", "USER_ID");
+CREATE INDEX "ORG_MEMBERS_ON_USER_UUID" ON "ORGANIZATION_MEMBERS"("USER_UUID");
+
--- /dev/null
+CREATE TABLE "ORGANIZATION_MEMBERS"(
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "USER_ID" INTEGER NOT NULL,
+ "USER_UUID" VARCHAR(40) NOT NULL,
+);
+CREATE INDEX "ORG_MEMBERS_ON_USER_ID" ON "ORGANIZATION_MEMBERS"("USER_UUID");
+ALTER TABLE "ORGANIZATION_MEMBERS" ADD CONSTRAINT "PK_ORGANIZATION_MEMBERS" PRIMARY KEY("ORGANIZATION_UUID", "USER_UUID");
--- /dev/null
+CREATE TABLE "ORGANIZATION_MEMBERS"(
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "USER_ID" INTEGER NOT NULL,
+ "USER_UUID" VARCHAR(40),
+);
+ALTER TABLE "ORGANIZATION_MEMBERS" ADD CONSTRAINT "PK_ORGANIZATION_MEMBERS" PRIMARY KEY("ORGANIZATION_UUID", "USER_ID");
+CREATE INDEX "IX_ORG_MEMBERS_ON_USER_ID" ON "ORGANIZATION_MEMBERS"("USER_ID");
+
--- /dev/null
+CREATE TABLE "USERS"(
+ "ID" INTEGER NOT NULL AUTO_INCREMENT (1,1),
+ "UUID" VARCHAR(255) NOT NULL,
+ "LOGIN" VARCHAR(255) NOT NULL,
+ "ORGANIZATION_UUID" VARCHAR(40),
+ "NAME" VARCHAR(200),
+ "EMAIL" VARCHAR(100),
+ "CRYPTED_PASSWORD" VARCHAR(100),
+ "SALT" VARCHAR(40),
+ "HASH_METHOD" VARCHAR(10),
+ "ACTIVE" BOOLEAN DEFAULT TRUE,
+ "SCM_ACCOUNTS" VARCHAR(4000),
+ "EXTERNAL_LOGIN" VARCHAR(255) NOT NULL,
+ "EXTERNAL_IDENTITY_PROVIDER" VARCHAR(100) NOT NULL,
+ "EXTERNAL_ID" VARCHAR(255) NOT NULL,
+ "IS_ROOT" BOOLEAN NOT NULL,
+ "USER_LOCAL" BOOLEAN,
+ "ONBOARDED" BOOLEAN NOT NULL,
+ "HOMEPAGE_TYPE" VARCHAR(40),
+ "HOMEPAGE_PARAMETER" VARCHAR(40),
+ "LAST_CONNECTION_DATE" BIGINT,
+ "CREATED_AT" BIGINT,
+ "UPDATED_AT" BIGINT
+);
+ALTER TABLE "USERS" ADD CONSTRAINT "PK_USERS" PRIMARY KEY("ID");
+CREATE UNIQUE INDEX "USERS_LOGIN" ON "USERS"("LOGIN");
+CREATE INDEX "USERS_UPDATED_AT" ON "USERS"("UPDATED_AT");
+CREATE UNIQUE INDEX "USERS_UUID" ON "USERS"("UUID");
+CREATE UNIQUE INDEX "UNIQ_EXTERNAL_ID" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER", "EXTERNAL_ID");
+CREATE UNIQUE INDEX "UNIQ_EXTERNAL_LOGIN" ON "USERS"("EXTERNAL_IDENTITY_PROVIDER", "EXTERNAL_LOGIN");
+
+
+CREATE TABLE "ORGANIZATION_MEMBERS"(
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "USER_ID" INTEGER NOT NULL,
+ "USER_UUID" VARCHAR(40),
+);
+ALTER TABLE "ORGANIZATION_MEMBERS" ADD CONSTRAINT "PK_ORGANIZATION_MEMBERS" PRIMARY KEY("ORGANIZATION_UUID", "USER_ID");
+CREATE INDEX "IX_ORG_MEMBERS_ON_USER_ID" ON "ORGANIZATION_MEMBERS"("USER_ID");
+
assertThat(docs)
.extracting(UserDoc::uuid)
.containsExactlyInAnyOrder(user.getUuid())
- .doesNotContain(anotherUser.getUuid());
+ .doesNotContain(anotherUser.getUuid());
}
@Test
underTest.commitAndIndex(db.getSession(), user);
List<UserDoc> docs = es.getDocuments(TYPE_USER, UserDoc.class);
- assertThat(docs)
- .extracting(UserDoc::uuid, UserDoc::organizationUuids)
- .containsExactlyInAnyOrder(tuple(user.getUuid(), asList(organization1.getUuid(), organization2.getUuid())));
+ assertThat(docs).hasSize(1);
+
+ UserDoc userDoc = docs.get(0);
+ assertThat(userDoc.uuid())
+ .isEqualTo(user.getUuid());
+
+ assertThat(userDoc.organizationUuids())
+ .containsExactlyInAnyOrder(organization1.getUuid(), organization2.getUuid());
}
@Test
}
public void addMembers(DbSession dbSession, OrganizationDto organization, List<UserDto> users) {
- Set<Integer> currentMemberIds = new HashSet<>(dbClient.organizationMemberDao().selectUserIdsByOrganizationUuid(dbSession, organization.getUuid()));
+ Set<String> currentMemberUuids = new HashSet<>(dbClient.organizationMemberDao().selectUserUuidsByOrganizationUuid(dbSession, organization.getUuid()));
List<UserDto> usersToAdd = users.stream()
.filter(UserDto::isActive)
- .filter(u -> !currentMemberIds.contains(u.getId()))
+ .filter(u -> !currentMemberUuids.contains(u.getUuid()))
.collect(toList());
if (usersToAdd.isEmpty()) {
return;
private void addMemberInDb(DbSession dbSession, OrganizationDto organization, UserDto user) {
dbClient.organizationMemberDao().insert(dbSession, new OrganizationMemberDto()
.setOrganizationUuid(organization.getUuid())
- .setUserId(user.getId()));
+ .setUserUuid(user.getUuid()));
dbClient.userGroupDao().insert(dbSession,
new UserGroupDto().setGroupUuid(defaultGroupFinder.findDefaultGroup(dbSession, organization.getUuid()).getUuid()).setUserUuid(user.getUuid()));
}
}
public void removeMembers(DbSession dbSession, OrganizationDto organization, List<UserDto> users) {
- Set<Integer> currentMemberIds = new HashSet<>(dbClient.organizationMemberDao().selectUserIdsByOrganizationUuid(dbSession, organization.getUuid()));
+ Set<String> currentMemberIds = new HashSet<>(dbClient.organizationMemberDao().selectUserUuidsByOrganizationUuid(dbSession, organization.getUuid()));
List<UserDto> usersToRemove = users.stream()
.filter(UserDto::isActive)
- .filter(u -> currentMemberIds.contains(u.getId()))
+ .filter(u -> currentMemberIds.contains(u.getUuid()))
.collect(toList());
if (usersToRemove.isEmpty()) {
return;
* Please note that no commit will not be executed.
*/
public void synchronizeUserOrganizationMembership(DbSession dbSession, UserDto user, ALM alm, Set<String> organizationAlmIds) {
- Set<String> userOrganizationUuids = dbClient.organizationMemberDao().selectOrganizationUuidsByUser(dbSession, user.getId());
+ Set<String> userOrganizationUuids = dbClient.organizationMemberDao().selectOrganizationUuidsByUser(dbSession, user.getUuid());
Set<String> userOrganizationUuidsWithMembersSyncEnabled = dbClient.organizationAlmBindingDao().selectByOrganizationUuids(dbSession, userOrganizationUuids).stream()
.filter(OrganizationAlmBindingDto::isMembersSyncEnable)
.map(OrganizationAlmBindingDto::getOrganizationUuid)
private void removeMemberInDb(DbSession dbSession, OrganizationDto organization, UserDto user) {
int userId = user.getId();
+ String userUuid = user.getUuid();
String organizationUuid = organization.getUuid();
dbClient.userPermissionDao().deleteOrganizationMemberPermissions(dbSession, organizationUuid, userId);
dbClient.permissionTemplateDao().deleteUserPermissionsByOrganization(dbSession, organizationUuid, userId);
dbClient.propertiesDao().deleteByOrganizationAndUser(dbSession, organizationUuid, userId);
dbClient.propertiesDao().deleteByOrganizationAndMatchingLogin(dbSession, organizationUuid, user.getLogin(), singletonList(DEFAULT_ISSUE_ASSIGNEE));
- dbClient.organizationMemberDao().delete(dbSession, organizationUuid, userId);
+ dbClient.organizationMemberDao().delete(dbSession, organizationUuid, userUuid);
}
}
QualityGateDto builtInQualityGate = dbClient.qualityGateDao().selectBuiltIn(dbSession);
OrganizationDto organization = insertOrganization(dbSession, newOrganization, builtInQualityGate);
beforeCommit.accept(organization);
- insertOrganizationMember(dbSession, organization, userCreator.getId());
+ insertOrganizationMember(dbSession, organization, userCreator.getUuid());
dbClient.qualityGateDao().associate(dbSession, uuidFactory.create(), organization, builtInQualityGate);
GroupDto ownerGroup = insertOwnersGroup(dbSession, organization);
GroupDto defaultGroup = defaultGroupCreator.create(dbSession, organization.getUuid());
new UserGroupDto().setGroupUuid(group.getUuid()).setUserUuid(createUserUuid));
}
- private void insertOrganizationMember(DbSession dbSession, OrganizationDto organizationDto, int userId) {
+ private void insertOrganizationMember(DbSession dbSession, OrganizationDto organizationDto, String userUuid) {
dbClient.organizationMemberDao().insert(dbSession, new OrganizationMemberDto()
.setOrganizationUuid(organizationDto.getUuid())
- .setUserId(userId));
+ .setUserUuid(userUuid));
}
}
return true;
}
try (DbSession dbSession = dbClient.openSession(false)) {
- Optional<OrganizationMemberDto> organizationMemberDto = dbClient.organizationMemberDao().select(dbSession, organizationUuid, requireNonNull(getUserId()));
+ Optional<OrganizationMemberDto> organizationMemberDto = dbClient.organizationMemberDao().select(dbSession, organizationUuid, requireNonNull(getUuid()));
if (organizationMemberDto.isPresent()) {
organizationMembership.add(organizationUuid);
}
private void addUserToDefaultOrganization(DbSession dbSession, UserDto userDto) {
String defOrgUuid = defaultOrganizationProvider.get().getUuid();
- dbClient.organizationMemberDao().insert(dbSession, new OrganizationMemberDto().setOrganizationUuid(defOrgUuid).setUserId(userDto.getId()));
+ dbClient.organizationMemberDao().insert(dbSession, new OrganizationMemberDto().setOrganizationUuid(defOrgUuid).setUserUuid(userDto.getUuid()));
}
private void addDefaultGroup(DbSession dbSession, UserDto userDto) {
underTest.synchronizeUserOrganizationMembership(db.getSession(), user, GITHUB, ImmutableSet.of("unknown"));
// User is member of no organization
- assertThat(db.getDbClient().organizationMemberDao().selectOrganizationUuidsByUser(db.getSession(), user.getId())).isEmpty();
+ assertThat(db.getDbClient().organizationMemberDao().selectOrganizationUuidsByUser(db.getSession(), user.getUuid())).isEmpty();
}
@Test
OrganizationDto result = underTest.create(dbSession, user, FULL_POPULATED_NEW_ORGANIZATION, EMPTY_ORGANIZATION_CONSUMER);
- assertThat(dbClient.organizationMemberDao().select(dbSession, result.getUuid(), user.getId())).isPresent();
+ assertThat(dbClient.organizationMemberDao().select(dbSession, result.getUuid(), user.getUuid())).isPresent();
assertThat(userIndex.search(UserQuery.builder().setOrganizationUuid(result.getUuid()).setTextQuery(user.getLogin()).build(), new SearchOptions()).getTotal()).isEqualTo(1L);
}
assertThat(session.hasMembership(organization)).isTrue();
// membership updated but not cache
- db.getDbClient().organizationMemberDao().delete(db.getSession(), organization.getUuid(), user.getId());
+ db.getDbClient().organizationMemberDao().delete(db.getSession(), organization.getUuid(), user.getUuid());
db.commit();
assertThat(session.hasMembership(organization)).isTrue();
}
.build(), u -> {
});
- assertThat(dbClient.organizationMemberDao().select(db.getSession(), defaultOrganizationProvider.get().getUuid(), dto.getId())).isPresent();
+ assertThat(dbClient.organizationMemberDao().select(db.getSession(), defaultOrganizationProvider.get().getUuid(), dto.getUuid())).isPresent();
}
@Test
.build(), u -> {
});
- assertThat(dbClient.organizationMemberDao().select(db.getSession(), defaultOrganizationProvider.get().getUuid(), dto.getId())).isNotPresent();
+ assertThat(dbClient.organizationMemberDao().select(db.getSession(), defaultOrganizationProvider.get().getUuid(), dto.getUuid())).isNotPresent();
}
private GroupDto createDefaultGroup() {
UserDto dto = underTest.reactivateAndCommit(db.getSession(), user, NewUser.builder().setLogin(user.getLogin()).setName(user.getName()).build(), u -> {
});
- assertThat(dbClient.organizationMemberDao().select(db.getSession(), defaultOrganizationProvider.get().getUuid(), dto.getId())).isPresent();
+ assertThat(dbClient.organizationMemberDao().select(db.getSession(), defaultOrganizationProvider.get().getUuid(), dto.getUuid())).isPresent();
}
@Test
UserDto dto = underTest.reactivateAndCommit(db.getSession(), user, NewUser.builder().setLogin(user.getLogin()).setName(user.getName()).build(), u -> {
});
- assertThat(dbClient.organizationMemberDao().select(db.getSession(), defaultOrganizationProvider.get().getUuid(), dto.getId())).isNotPresent();
+ assertThat(dbClient.organizationMemberDao().select(db.getSession(), defaultOrganizationProvider.get().getUuid(), dto.getUuid())).isNotPresent();
}
@Test
return Collections.emptySet();
}
try (DbSession dbSession = dbClient.openSession(false)) {
- return dbClient.organizationMemberDao().selectOrganizationUuidsByUser(dbSession, assignee.getId());
+ return dbClient.organizationMemberDao().selectOrganizationUuidsByUser(dbSession, assignee.getUuid());
}
}
.orElseThrow(() -> new IllegalStateException(format("Unknown project %s", projectUuid)));
OrganizationDto organizationDto = dbClient.organizationDao().selectByUuid(dbSession, project.getOrganizationUuid())
.orElseThrow(() -> new IllegalStateException(format("Unknown organizationMember %s", project.getOrganizationUuid())));
- checkArgument(dbClient.organizationMemberDao().select(dbSession, organizationDto.getUuid(), user.getId()).isPresent(),
+ checkArgument(dbClient.organizationMemberDao().select(dbSession, organizationDto.getUuid(), user.getUuid()).isPresent(),
"User '%s' is not member of organization '%s'", user.getLogin(), organizationDto.getKey());
}
}
.forEach(result::addOrganization);
if (userSession.isLoggedIn()) {
- result.setUserOrganizationUuids(dbClient.organizationMemberDao().selectOrganizationUuidsByUser(dbSession, userSession.getUserId()));
+ result.setUserOrganizationUuids(dbClient.organizationMemberDao().selectOrganizationUuidsByUser(dbSession, userSession.getUuid()));
}
}
}
@CheckForNull
- private Integer getUserIdIfFilterOnMembership(Request request) {
+ private String getUserIdIfFilterOnMembership(Request request) {
boolean filterOnAuthenticatedUser = request.mandatoryParamAsBoolean(PARAM_MEMBER);
- return (userSession.isLoggedIn() && filterOnAuthenticatedUser) ? userSession.getUserId() : null;
+ return (userSession.isLoggedIn() && filterOnAuthenticatedUser) ? userSession.getUuid() : null;
}
}
}
public void checkMembership(DbSession dbSession, OrganizationDto organization, UserId user) {
- checkArgument(dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), user.getId()).isPresent(),
+ checkArgument(dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), user.getUuid()).isPresent(),
"User '%s' is not member of organization '%s'", user.getLogin(), organization.getKey());
}
}
}
private void checkMembership(DbSession dbSession, OrganizationDto organization, UserDto user) {
- checkArgument(isMember(dbSession, organization, user.getId()),
+ checkArgument(isMember(dbSession, organization, user.getUuid()),
"User '%s' is not member of organization '%s'", user.getLogin(), organization.getKey());
}
- private boolean isMember(DbSession dbSession, OrganizationDto organization, int userId) {
- return dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), userId).isPresent();
+ private boolean isMember(DbSession dbSession, OrganizationDto organization, String userUuid) {
+ return dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), userUuid).isPresent();
}
private void checkMembershipOnPaidOrganization(OrganizationDto organization) {
dbClient.userPermissionDao().deleteByUserId(dbSession, userId);
dbClient.permissionTemplateDao().deleteUserPermissionsByUserId(dbSession, userId);
dbClient.qProfileEditUsersDao().deleteByUser(dbSession, user);
- dbClient.organizationMemberDao().deleteByUserId(dbSession, userId);
+ dbClient.organizationMemberDao().deleteByUserUuid(dbSession, user.getUuid());
dbClient.userPropertiesDao().deleteByUser(dbSession, user);
dbClient.almPatDao().deleteByUser(dbSession, user);
deactivateUser(dbSession, user);
}
private void checkMembership(DbSession dbSession, OrganizationDto organization, UserDto user) {
- checkArgument(dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), user.getId()).isPresent(),
+ checkArgument(dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), user.getUuid()).isPresent(),
"User '%s' is not member of organization '%s'", user.getLogin(), organization.getKey());
}
}
}
private void assertMember(String organizationUuid, UserDto user) {
- assertThat(dbClient.organizationMemberDao().select(dbSession, organizationUuid, user.getId())).isPresent();
+ assertThat(dbClient.organizationMemberDao().select(dbSession, organizationUuid, user.getUuid())).isPresent();
String defaultGroupUuid = dbClient.organizationDao().getDefaultGroupUuid(dbSession, organizationUuid).get();
assertThat(db.getDbClient().groupMembershipDao().selectGroups(db.getSession(), GroupMembershipQuery.builder()
.membership(IN)
executeRequest("foo", "bar");
OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, "bar").get();
- assertThat(dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), user.getId())).isPresent();
+ assertThat(dbClient.organizationMemberDao().select(dbSession, organization.getUuid(), user.getUuid())).isPresent();
assertThat(es.client().prepareSearch(TYPE_USER)
.setQuery(boolQuery()
.must(termQuery(FIELD_ORGANIZATION_UUIDS, organization.getUuid()))
sendRequest(org);
verifyOrganizationDoesNotExist(org);
- assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), org.getUuid(), user1.getId())).isNotPresent();
- assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), org.getUuid(), user2.getId())).isNotPresent();
- assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), otherOrg.getUuid(), user1.getId())).isPresent();
+ assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), org.getUuid(), user1.getUuid())).isNotPresent();
+ assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), org.getUuid(), user2.getUuid())).isNotPresent();
+ assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), otherOrg.getUuid(), user1.getUuid())).isPresent();
assertThat(userIndex.search(UserQuery.builder().setOrganizationUuid(org.getUuid()).build(), new SearchOptions()).getTotal()).isEqualTo(0);
assertThat(userIndex.search(UserQuery.builder().setOrganizationUuid(otherOrg.getUuid()).build(), new SearchOptions()).getTotal()).isEqualTo(1);
verify(projectLifeCycleListeners).onProjectsDeleted(emptySet());
underTest.delete(dbSession, org);
verifyOrganizationDoesNotExist(org);
- assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), org.getUuid(), user1.getId())).isNotPresent();
- assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), org.getUuid(), user2.getId())).isNotPresent();
- assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), otherOrg.getUuid(), user1.getId())).isPresent();
+ assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), org.getUuid(), user1.getUuid())).isNotPresent();
+ assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), org.getUuid(), user2.getUuid())).isNotPresent();
+ assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), otherOrg.getUuid(), user1.getUuid())).isPresent();
assertThat(userIndex.search(UserQuery.builder().setOrganizationUuid(org.getUuid()).build(), new SearchOptions()).getTotal()).isEqualTo(0);
assertThat(userIndex.search(UserQuery.builder().setOrganizationUuid(otherOrg.getUuid()).build(), new SearchOptions()).getTotal()).isEqualTo(1);
verify(projectLifeCycleListeners).onProjectsDeleted(emptySet());
}
private void assertNotAMember(String organizationUuid, UserDto user) {
- assertThat(dbClient.organizationMemberDao().select(dbSession, organizationUuid, user.getId())).isNotPresent();
+ assertThat(dbClient.organizationMemberDao().select(dbSession, organizationUuid, user.getUuid())).isNotPresent();
}
private void assertMember(String organizationUuid, UserDto user) {
- assertThat(dbClient.organizationMemberDao().select(dbSession, organizationUuid, user.getId())).isPresent();
+ assertThat(dbClient.organizationMemberDao().select(dbSession, organizationUuid, user.getUuid())).isPresent();
assertThat(userIndex.search(UserQuery.builder()
.setOrganizationUuid(organizationUuid)
.setTextQuery(user.getLogin())
Optional<UserDto> dbUser = db.users().selectUserByLogin("john");
assertThat(dbUser).isPresent();
- assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), defaultOrganizationProvider.get().getUuid(), dbUser.get().getId())).isPresent();
+ assertThat(db.getDbClient().organizationMemberDao().select(db.getSession(), defaultOrganizationProvider.get().getUuid(), dbUser.get().getUuid())).isPresent();
}
@Test
deactivate(user.getLogin());
- assertThat(dbClient.organizationMemberDao().select(db.getSession(), organization.getUuid(), user.getId())).isNotPresent();
- assertThat(dbClient.organizationMemberDao().select(db.getSession(), anotherOrganization.getUuid(), user.getId())).isNotPresent();
+ assertThat(dbClient.organizationMemberDao().select(db.getSession(), organization.getUuid(), user.getUuid())).isNotPresent();
+ assertThat(dbClient.organizationMemberDao().select(db.getSession(), anotherOrganization.getUuid(), user.getUuid())).isNotPresent();
}
@Test