update.setLong(2, row.getLong(1));
return true;
});
+
+ massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select uuid from active_rules where rule_uuid is null");
+ massUpdate.update("delete from active_rules where uuid = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(1));
+ return true;
+ });
}
}
update.setLong(2, row.getLong(1));
return true;
});
+
+ massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select uuid from deprecated_rule_keys where rule_uuid is null");
+ massUpdate.update("delete from deprecated_rule_keys where uuid = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(1));
+ return true;
+ });
}
}
update.setLong(2, row.getLong(1));
return true;
});
+
+ massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select rule_id, organization_uuid from rules_metadata where rule_uuid is null");
+ massUpdate.update("delete from rules_metadata where rule_id = ? and organization_uuid = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setLong(1, row.getLong(1));
+ update.setString(2, row.getString(2));
+ return true;
+ });
}
}
update.setLong(3, userId);
return true;
});
+
+ massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select group_uuid, user_id from groups_users where user_uuid is null");
+ massUpdate.update("delete from groups_users where group_uuid = ? and user_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(1));
+ update.setLong(2, row.getLong(2));
+
+ return true;
+ });
}
}
update.setLong(3, userId);
return true;
});
+
+ massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select organization_uuid, user_id from organization_members where user_uuid is null");
+ massUpdate.update("delete from organization_members where organization_uuid = ? and user_id = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(1));
+ update.setLong(2, row.getLong(2));
+
+ return true;
+ });
}
}
update.setString(2, permTemplatesUuid);
return true;
});
+
+ massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select uuid from perm_templates_users where user_uuid is null");
+ massUpdate.update("delete from perm_templates_users where uuid = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(1));
+ return true;
+ });
}
}
update.setString(2, permTemplatesUuid);
return true;
});
+
+ massUpdate = context.prepareMassUpdate();
+
+ massUpdate.select("select uuid from qprofile_edit_users where user_uuid is null");
+ massUpdate.update("delete from qprofile_edit_users where uuid = ?");
+
+ massUpdate.execute((row, update) -> {
+ update.setString(1, row.getString(1));
+ return true;
+ });
}
}
insertActiveRule("uuid-ar-1", 1L, "uuid-profile-1");
insertActiveRule("uuid-ar-2", 1L, "uuid-profile-2");
insertActiveRule("uuid-ar-3", 2L, "uuid-profile-1");
+ // orphan FK
+ insertActiveRule("uuid-ar-4", 10L, "uuid-profile-1");
}
@Test
insertDeprecatedRuleKeyRow("uuid-drk-1", 1L);
insertDeprecatedRuleKeyRow("uuid-drk-2", 1L);
insertDeprecatedRuleKeyRow("uuid-drk-3", 2L);
+ // orphan FK
+ insertDeprecatedRuleKeyRow("uuid-drk-4", 10L);
}
@Test
insertRuleMetadata(1L, "org-1");
insertRuleMetadata(1L, "org-2");
insertRuleMetadata(2L, "org-1");
+ // orphan FK
+ insertRuleMetadata(10L, "org-1");
}
@Test
insertGroupUser(userId_3, groupUuid_3);
String groupUuid_4 = Uuids.createFast();
insertGroupUser(userId_1, groupUuid_4);
+ // orphan FK
+ String groupUuid_5 = Uuids.createFast();
+ insertGroupUser(100L, groupUuid_5);
underTest.execute();
+ assertThat(db.countRowsOfTable("groups_users")).isEqualTo(4);
assertThatGroupsUserUserUuidIsEqualTo(userId_1, groupUuid_1, userUuid_1);
assertThatGroupsUserUserUuidIsEqualTo(userId_2, groupUuid_2, userUuid_2);
assertThatGroupsUserUserUuidIsEqualTo(userId_3, groupUuid_3, userUuid_3);
String organizationUuid_5 = Uuids.createFast();
insertOrganizationMember(userId_1, organizationUuid_5);
+ // orphan FK
+ String organizationUuid_6 = Uuids.createFast();
+ insertOrganizationMember(100L, organizationUuid_6);
+
underTest.execute();
+ assertThat(db.countRowsOfTable("organization_members")).isEqualTo(5);
assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_1, organizationUuid_1, userUuid_1);
assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_2, organizationUuid_2, userUuid_2);
assertThatQProfileChangeRulesProfileUuidIsEqualTo(userId_3, organizationUuid_3, userUuid_3);
String permTemplatesUserUuid_5 = Uuids.createFast();
insertPermTemplatesUser(permTemplatesUserUuid_5, userId_1);
+ // orphan FK
+ String permTemplatesUserUuid_6 = Uuids.createFast();
+ insertPermTemplatesUser(permTemplatesUserUuid_6, 100L);
+
underTest.execute();
+ assertThat(db.countRowsOfTable("perm_templates_users")).isEqualTo(5);
assertThatPermTemplatesUsersUserUuidIsEqualTo(permTemplatesUserUuid_1, userUuid_1);
assertThatPermTemplatesUsersUserUuidIsEqualTo(permTemplatesUserUuid_2, userUuid_2);
assertThatPermTemplatesUsersUserUuidIsEqualTo(permTemplatesUserUuid_3, userUuid_3);
String qprofileEditUserUuid_5 = Uuids.createFast();
insertQProfileEditUser(qprofileEditUserUuid_5, userId_1);
+ // orphan FK
+ String qprofileEditUserUuid_6 = Uuids.createFast();
+ insertQProfileEditUser(qprofileEditUserUuid_6, 100L);
+
underTest.execute();
+ assertThat(db.countRowsOfTable("qprofile_edit_users")).isEqualTo(5);
assertThatQProfileEditUserUserUuidIsEqualTo(qprofileEditUserUuid_1, userUuid_1);
assertThatQProfileEditUserUserUuidIsEqualTo(qprofileEditUserUuid_2, userUuid_2);
assertThatQProfileEditUserUserUuidIsEqualTo(qprofileEditUserUuid_3, userUuid_3);