Migrate schema to meet 30 char length of database id limitation

Some databases restrict the id of database objects to be max 30 char long.
Migrate the ReviewDB to meet this requirement.

This change changes two tables, that were introduced in Schema 74:
ACCOUNT_GROUP_INCLUDES_BY_UUID => ACCOUNT_GROUP_BY_ID
ACCOUNT_GROUP_INCLUDES_BY_UUID_AUDIT => ACCOUNT_GROUP_BY_ID_AUD

one column:
ACCOUNTS.SHOW_USERNAME_IN_REVIEW_CATEGORY => SHOW_USER_IN_REVIEW

and three indexes:
account_project_watches_byProject => account_project_watches_byP
patch_set_approvals_closedByUser => patch_set_approvals_closedByU
submodule_subscription_access_bySubscription =>
submodule_subscr_acc_byS

Change-Id: I93589a406274b952350174a4e79a7602ea57d05a
This commit is contained in:
David Ostrovsky
2013-07-12 00:57:56 +02:00
parent adf540382b
commit d3bd961be5
23 changed files with 288 additions and 146 deletions

View File

@@ -32,7 +32,7 @@ import com.google.gerrit.acceptance.TestAccount;
import com.google.gerrit.acceptance.rest.account.AccountInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.account.GroupCache;
@@ -223,9 +223,9 @@ public class AddRemoveGroupMembersIT extends AbstractDaemonTest {
throws OrmException {
AccountGroup g = groupCache.get(new AccountGroup.NameKey(group));
Set<AccountGroup.UUID> ids = Sets.newHashSet();
ResultSet<AccountGroupIncludeByUuid> all =
db.accountGroupIncludesByUuid().byGroup(g.getId());
for (AccountGroupIncludeByUuid m : all) {
ResultSet<AccountGroupById> all =
db.accountGroupById().byGroup(g.getId());
for (AccountGroupById m : all) {
ids.add(m.getIncludeUUID());
}
assertTrue(ids.size() == includes.length);
@@ -252,8 +252,8 @@ public class AddRemoveGroupMembersIT extends AbstractDaemonTest {
private void assertNoIncludes(String group) throws OrmException {
AccountGroup g = groupCache.get(new AccountGroup.NameKey(group));
Iterator<AccountGroupIncludeByUuid> it =
db.accountGroupIncludesByUuid().byGroup(g.getId()).iterator();
Iterator<AccountGroupById> it =
db.accountGroupById().byGroup(g.getId()).iterator();
assertFalse(it.hasNext());
}
}

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.common.data;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import java.util.List;
@@ -24,7 +24,7 @@ public class GroupDetail {
public AccountInfoCache accounts;
public AccountGroup group;
public List<AccountGroupMember> members;
public List<AccountGroupIncludeByUuid> includes;
public List<AccountGroupById> includes;
public GroupReference ownerGroup;
public boolean canModify;
@@ -43,7 +43,7 @@ public class GroupDetail {
members = m;
}
public void setIncludes(List<AccountGroupIncludeByUuid> i) {
public void setIncludes(List<AccountGroupById> i) {
includes = i;
}

View File

@@ -128,7 +128,7 @@ public final class AccountGeneralPreferences {
protected boolean reversePatchSetOrder;
@Column(id = 11)
protected boolean showUsernameInReviewCategory;
protected boolean showUserInReview;
@Column(id = 12)
protected boolean relativeDateInChangeTable;
@@ -210,11 +210,11 @@ public final class AccountGeneralPreferences {
}
public boolean isShowUsernameInReviewCategory() {
return showUsernameInReviewCategory;
return showUserInReview;
}
public void setShowUsernameInReviewCategory(final boolean showUsernameInReviewCategory) {
this.showUsernameInReviewCategory = showUsernameInReviewCategory;
this.showUserInReview = showUsernameInReviewCategory;
}
public DateFormat getDateFormat() {
@@ -265,7 +265,7 @@ public final class AccountGeneralPreferences {
useFlashClipboard = true;
copySelfOnEmail = false;
reversePatchSetOrder = false;
showUsernameInReviewCategory = false;
showUserInReview = false;
downloadUrl = null;
downloadCommand = null;
dateFormat = null;

View File

@@ -18,7 +18,7 @@ import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.CompoundKey;
/** Membership of an {@link AccountGroup} in an {@link AccountGroup}. */
public final class AccountGroupIncludeByUuid {
public final class AccountGroupById {
public static class Key extends CompoundKey<AccountGroup.Id> {
private static final long serialVersionUID = 1L;
@@ -60,14 +60,14 @@ public final class AccountGroupIncludeByUuid {
@Column(id = 1, name = Column.NONE)
protected Key key;
protected AccountGroupIncludeByUuid() {
protected AccountGroupById() {
}
public AccountGroupIncludeByUuid(final AccountGroupIncludeByUuid.Key k) {
public AccountGroupById(final AccountGroupById.Key k) {
key = k;
}
public AccountGroupIncludeByUuid.Key getKey() {
public AccountGroupById.Key getKey() {
return key;
}

View File

@@ -20,7 +20,7 @@ import com.google.gwtorm.client.CompoundKey;
import java.sql.Timestamp;
/** Inclusion of an {@link AccountGroup} in another {@link AccountGroup}. */
public final class AccountGroupIncludeByUuidAudit {
public final class AccountGroupByIdAud {
public static class Key extends CompoundKey<AccountGroup.Id> {
private static final long serialVersionUID = 1L;
@@ -75,23 +75,23 @@ public final class AccountGroupIncludeByUuidAudit {
@Column(id = 4, notNull = false)
protected Timestamp removedOn;
protected AccountGroupIncludeByUuidAudit() {
protected AccountGroupByIdAud() {
}
public AccountGroupIncludeByUuidAudit(final AccountGroupIncludeByUuid m,
public AccountGroupByIdAud(final AccountGroupById m,
final Account.Id adder, final Timestamp when) {
final AccountGroup.Id group = m.getGroupId();
final AccountGroup.UUID include = m.getIncludeUUID();
key = new AccountGroupIncludeByUuidAudit.Key(group, include, when);
key = new AccountGroupByIdAud.Key(group, include, when);
addedBy = adder;
}
public AccountGroupIncludeByUuidAudit(final AccountGroupIncludeByUuid m,
public AccountGroupByIdAud(final AccountGroupById m,
final Account.Id adder) {
this(m, adder, now());
}
public AccountGroupIncludeByUuidAudit.Key getKey() {
public AccountGroupByIdAud.Key getKey() {
return key;
}

View File

@@ -15,24 +15,24 @@
package com.google.gerrit.reviewdb.server;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gwtorm.server.Access;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.PrimaryKey;
import com.google.gwtorm.server.Query;
import com.google.gwtorm.server.ResultSet;
public interface AccountGroupIncludeByUuidAccess extends
Access<AccountGroupIncludeByUuid, AccountGroupIncludeByUuid.Key> {
public interface AccountGroupByIdAccess extends
Access<AccountGroupById, AccountGroupById.Key> {
@PrimaryKey("key")
AccountGroupIncludeByUuid get(AccountGroupIncludeByUuid.Key key) throws OrmException;
AccountGroupById get(AccountGroupById.Key key) throws OrmException;
@Query("WHERE key.includeUUID = ?")
ResultSet<AccountGroupIncludeByUuid> byIncludeUUID(AccountGroup.UUID uuid) throws OrmException;
ResultSet<AccountGroupById> byIncludeUUID(AccountGroup.UUID uuid) throws OrmException;
@Query("WHERE key.groupId = ?")
ResultSet<AccountGroupIncludeByUuid> byGroup(AccountGroup.Id id) throws OrmException;
ResultSet<AccountGroupById> byGroup(AccountGroup.Id id) throws OrmException;
@Query("")
ResultSet<AccountGroupIncludeByUuid> all() throws OrmException;
ResultSet<AccountGroupById> all() throws OrmException;
}

View File

@@ -15,20 +15,20 @@
package com.google.gerrit.reviewdb.server;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuidAudit;
import com.google.gerrit.reviewdb.client.AccountGroupByIdAud;
import com.google.gwtorm.server.Access;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.PrimaryKey;
import com.google.gwtorm.server.Query;
import com.google.gwtorm.server.ResultSet;
public interface AccountGroupIncludeByUuidAuditAccess extends
Access<AccountGroupIncludeByUuidAudit, AccountGroupIncludeByUuidAudit.Key> {
public interface AccountGroupByIdAudAccess extends
Access<AccountGroupByIdAud, AccountGroupByIdAud.Key> {
@PrimaryKey("key")
AccountGroupIncludeByUuidAudit get(AccountGroupIncludeByUuidAudit.Key key)
AccountGroupByIdAud get(AccountGroupByIdAud.Key key)
throws OrmException;
@Query("WHERE key.groupId = ? AND key.includeUUID = ?")
ResultSet<AccountGroupIncludeByUuidAudit> byGroupInclude(AccountGroup.Id groupId,
ResultSet<AccountGroupByIdAud> byGroupInclude(AccountGroup.Id groupId,
AccountGroup.UUID incGroupUUID) throws OrmException;
}

View File

@@ -105,10 +105,10 @@ public interface ReviewDb extends Schema {
SubmoduleSubscriptionAccess submoduleSubscriptions();
@Relation(id = 29)
AccountGroupIncludeByUuidAccess accountGroupIncludesByUuid();
AccountGroupByIdAccess accountGroupById();
@Relation(id = 30)
AccountGroupIncludeByUuidAuditAccess accountGroupIncludesByUuidAudit();
AccountGroupByIdAudAccess accountGroupByIdAud();
/** Create the next unique id for an {@link Account}. */
@Sequence(startWith = 1000000)

View File

@@ -34,17 +34,16 @@ ON account_group_members (group_id);
-- *********************************************************************
-- AccountGroupIncludeByUuidAccess
-- AccountGroupByIdAccess
-- @PrimaryKey covers: byGroup
CREATE INDEX account_group_includes_by_uuid_byInclude
ON account_group_includes_by_uuid (include_uuid);
CREATE INDEX account_group_id_byInclude
ON account_group_by_id (include_uuid);
-- *********************************************************************
-- AccountProjectWatchAccess
-- @PrimaryKey covers: byAccount
-- covers: byProject
CREATE INDEX account_project_watches_byProject
CREATE INDEX account_project_watches_byP
ON account_project_watches (project_name);
@@ -114,7 +113,7 @@ CREATE INDEX patch_set_approvals_openByUser
ON patch_set_approvals (change_open, account_id);
-- covers: closedByUser
CREATE INDEX patch_set_approvals_closedByUser
CREATE INDEX patch_set_approvals_closedByU
ON patch_set_approvals (change_open, account_id, change_sort_key);
@@ -163,5 +162,5 @@ ON starred_changes (change_id);
-- *********************************************************************
-- SubmoduleSubscriptionAccess
CREATE INDEX submodule_subscription_access_bySubscription
CREATE INDEX submodule_subscr_acc_byS
ON submodule_subscriptions (submodule_project_name, submodule_branch_name);

View File

@@ -82,17 +82,16 @@ ON account_group_members (group_id);
-- *********************************************************************
-- AccountGroupIncludeByUuidAccess
-- AccountGroupByIdAccess
-- @PrimaryKey covers: byGroup
CREATE INDEX account_group_includes_by_uuid_byInclude
ON account_group_includes_by_uuid (include_uuid);
CREATE INDEX account_group_id_byInclude
ON account_group_by_id (include_uuid);
-- *********************************************************************
-- AccountProjectWatchAccess
-- @PrimaryKey covers: byAccount
-- covers: byProject
CREATE INDEX account_project_watches_byProject
CREATE INDEX account_project_watches_byP
ON account_project_watches (project_name);
@@ -170,7 +169,7 @@ ON patch_set_approvals (account_id)
WHERE change_open = 'Y';
-- covers: closedByUser
CREATE INDEX patch_set_approvals_closedByUser
CREATE INDEX patch_set_approvals_closedByU
ON patch_set_approvals (account_id, change_sort_key)
WHERE change_open = 'N';
@@ -222,5 +221,5 @@ ON starred_changes (change_id);
-- *********************************************************************
-- SubmoduleSubscriptionAccess
CREATE INDEX submodule_subscription_access_bySubscription
CREATE INDEX submodule_subscr_acc_byS
ON submodule_subscriptions (submodule_project_name, submodule_branch_name);

View File

@@ -20,7 +20,7 @@ import com.google.gerrit.common.data.GroupReference;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gwtorm.server.OrmException;
@@ -122,19 +122,19 @@ public class GroupDetailFactory implements Callable<GroupDetail> {
return members;
}
private List<AccountGroupIncludeByUuid> loadIncludes() throws OrmException {
List<AccountGroupIncludeByUuid> groups = new ArrayList<AccountGroupIncludeByUuid>();
private List<AccountGroupById> loadIncludes() throws OrmException {
List<AccountGroupById> groups = new ArrayList<AccountGroupById>();
for (final AccountGroupIncludeByUuid m : db.accountGroupIncludesByUuid().byGroup(groupId)) {
for (final AccountGroupById m : db.accountGroupById().byGroup(groupId)) {
if (control.canSeeGroup(m.getIncludeUUID())) {
gic.want(m.getIncludeUUID());
groups.add(m);
}
}
Collections.sort(groups, new Comparator<AccountGroupIncludeByUuid>() {
public int compare(final AccountGroupIncludeByUuid o1,
final AccountGroupIncludeByUuid o2) {
Collections.sort(groups, new Comparator<AccountGroupById>() {
public int compare(final AccountGroupById o1,
final AccountGroupById o2) {
GroupDescription.Basic a = gic.get(o1.getIncludeUUID());
GroupDescription.Basic b = gic.get(o2.getIncludeUUID());
return n(a).compareTo(n(b));

View File

@@ -19,7 +19,7 @@ import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.cache.CacheModule;
import com.google.gwtorm.server.SchemaFactory;
@@ -152,7 +152,7 @@ public class GroupIncludeCacheImpl implements GroupIncludeCache {
}
Set<AccountGroup.UUID> ids = Sets.newHashSet();
for (AccountGroupIncludeByUuid agi : db.accountGroupIncludesByUuid()
for (AccountGroupById agi : db.accountGroupById()
.byGroup(group.get(0).getId())) {
ids.add(agi.getIncludeUUID());
}
@@ -177,7 +177,7 @@ public class GroupIncludeCacheImpl implements GroupIncludeCache {
final ReviewDb db = schema.open();
try {
Set<AccountGroup.Id> ids = Sets.newHashSet();
for (AccountGroupIncludeByUuid agi : db.accountGroupIncludesByUuid()
for (AccountGroupById agi : db.accountGroupById()
.byIncludeUUID(key)) {
ids.add(agi.getGroupId());
}
@@ -207,7 +207,7 @@ public class GroupIncludeCacheImpl implements GroupIncludeCache {
final ReviewDb db = schema.open();
try {
Set<AccountGroup.UUID> ids = Sets.newHashSet();
for (AccountGroupIncludeByUuid agi : db.accountGroupIncludesByUuid().all()) {
for (AccountGroupById agi : db.accountGroupById().all()) {
if (!AccountGroup.isInternalGroup(agi.getIncludeUUID())) {
ids.add(agi.getIncludeUUID());
}

View File

@@ -18,7 +18,7 @@ import com.google.gerrit.common.data.GroupDetail;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.CurrentUser;
@@ -113,7 +113,7 @@ public class GroupMembers {
}
}
if (groupDetail.includes != null) {
for (final AccountGroupIncludeByUuid groupInclude : groupDetail.includes) {
for (final AccountGroupById groupInclude : groupDetail.includes) {
final AccountGroup includedGroup =
groupCache.get(groupInclude.getIncludeUUID());
if (includedGroup != null && !seen.contains(includedGroup.getGroupUUID())) {

View File

@@ -18,8 +18,8 @@ import com.google.gerrit.common.errors.NameAlreadyUsedException;
import com.google.gerrit.common.errors.PermissionDeniedException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuidAudit;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupByIdAud;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.reviewdb.client.AccountGroupMemberAudit;
import com.google.gerrit.reviewdb.client.AccountGroupName;
@@ -161,21 +161,21 @@ public class PerformCreateGroup {
private void addGroups(final AccountGroup.Id groupId,
final Collection<? extends AccountGroup.UUID> groups) throws OrmException {
final List<AccountGroupIncludeByUuid> includeList =
new ArrayList<AccountGroupIncludeByUuid>();
final List<AccountGroupIncludeByUuidAudit> includesAudit =
new ArrayList<AccountGroupIncludeByUuidAudit>();
final List<AccountGroupById> includeList =
new ArrayList<AccountGroupById>();
final List<AccountGroupByIdAud> includesAudit =
new ArrayList<AccountGroupByIdAud>();
for (AccountGroup.UUID includeUUID : groups) {
final AccountGroupIncludeByUuid groupInclude =
new AccountGroupIncludeByUuid(new AccountGroupIncludeByUuid.Key(groupId, includeUUID));
final AccountGroupById groupInclude =
new AccountGroupById(new AccountGroupById.Key(groupId, includeUUID));
includeList.add(groupInclude);
final AccountGroupIncludeByUuidAudit audit =
new AccountGroupIncludeByUuidAudit(groupInclude, currentUser.getAccountId());
final AccountGroupByIdAud audit =
new AccountGroupByIdAud(groupInclude, currentUser.getAccountId());
includesAudit.add(audit);
}
db.accountGroupIncludesByUuid().insert(includeList);
db.accountGroupIncludesByUuidAudit().insert(includesAudit);
db.accountGroupById().insert(includeList);
db.accountGroupByIdAud().insert(includesAudit);
for (AccountGroup.UUID uuid : groups) {
groupIncludeCache.evictMemberIn(uuid);

View File

@@ -27,8 +27,8 @@ import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuidAudit;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupByIdAud;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.GroupControl;
@@ -95,8 +95,8 @@ public class AddIncludedGroups implements RestModifyView<GroupResource, Input> {
input = Input.init(input);
GroupControl control = resource.getControl();
Map<AccountGroup.UUID, AccountGroupIncludeByUuid> newIncludedGroups = Maps.newHashMap();
List<AccountGroupIncludeByUuidAudit> newIncludedGroupsAudits = Lists.newLinkedList();
Map<AccountGroup.UUID, AccountGroupById> newIncludedGroups = Maps.newHashMap();
List<AccountGroupByIdAud> newIncludedGroupsAudits = Lists.newLinkedList();
List<GroupInfo> result = Lists.newLinkedList();
Account.Id me = ((IdentifiedUser) control.getCurrentUser()).getAccountId();
@@ -108,23 +108,23 @@ public class AddIncludedGroups implements RestModifyView<GroupResource, Input> {
}
if (!newIncludedGroups.containsKey(d.getGroupUUID())) {
AccountGroupIncludeByUuid.Key agiKey =
new AccountGroupIncludeByUuid.Key(group.getId(),
AccountGroupById.Key agiKey =
new AccountGroupById.Key(group.getId(),
d.getGroupUUID());
AccountGroupIncludeByUuid agi = db.accountGroupIncludesByUuid().get(agiKey);
AccountGroupById agi = db.accountGroupById().get(agiKey);
if (agi == null) {
agi = new AccountGroupIncludeByUuid(agiKey);
agi = new AccountGroupById(agiKey);
newIncludedGroups.put(d.getGroupUUID(), agi);
newIncludedGroupsAudits.add(new AccountGroupIncludeByUuidAudit(agi, me));
newIncludedGroupsAudits.add(new AccountGroupByIdAud(agi, me));
}
}
result.add(json.format(d));
}
if (!newIncludedGroups.isEmpty()) {
db.accountGroupIncludesByUuidAudit().insert(newIncludedGroupsAudits);
db.accountGroupIncludesByUuid().insert(newIncludedGroups.values());
for (AccountGroupIncludeByUuid agi : newIncludedGroups.values()) {
db.accountGroupByIdAud().insert(newIncludedGroupsAudits);
db.accountGroupById().insert(newIncludedGroups.values());
for (AccountGroupById agi : newIncludedGroups.values()) {
groupIncludeCache.evictMemberIn(agi.getIncludeUUID());
}
groupIncludeCache.evictMembersOf(group.getGroupUUID());

View File

@@ -26,8 +26,8 @@ import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuidAudit;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupByIdAud;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
@@ -68,8 +68,8 @@ public class DeleteIncludedGroups implements RestModifyView<GroupResource, Input
input = Input.init(input);
final GroupControl control = resource.getControl();
final Map<AccountGroup.UUID, AccountGroupIncludeByUuid> includedGroups = getIncludedGroups(internalGroup.getId());
final List<AccountGroupIncludeByUuid> toRemove = Lists.newLinkedList();
final Map<AccountGroup.UUID, AccountGroupById> includedGroups = getIncludedGroups(internalGroup.getId());
final List<AccountGroupById> toRemove = Lists.newLinkedList();
for (final String includedGroup : input.groups) {
GroupDescription.Basic d = groupsCollection.get().parse(includedGroup);
@@ -78,7 +78,7 @@ public class DeleteIncludedGroups implements RestModifyView<GroupResource, Input
d.getName()));
}
AccountGroupIncludeByUuid g = includedGroups.remove(d.getGroupUUID());
AccountGroupById g = includedGroups.remove(d.getGroupUUID());
if (g != null) {
toRemove.add(g);
}
@@ -86,8 +86,8 @@ public class DeleteIncludedGroups implements RestModifyView<GroupResource, Input
if (!toRemove.isEmpty()) {
writeAudits(toRemove);
db.accountGroupIncludesByUuid().delete(toRemove);
for (final AccountGroupIncludeByUuid g : toRemove) {
db.accountGroupById().delete(toRemove);
for (final AccountGroupById g : toRemove) {
groupIncludeCache.evictMemberIn(g.getIncludeUUID());
}
groupIncludeCache.evictMembersOf(internalGroup.getGroupUUID());
@@ -96,24 +96,24 @@ public class DeleteIncludedGroups implements RestModifyView<GroupResource, Input
return Response.none();
}
private Map<AccountGroup.UUID, AccountGroupIncludeByUuid> getIncludedGroups(
private Map<AccountGroup.UUID, AccountGroupById> getIncludedGroups(
final AccountGroup.Id groupId) throws OrmException {
final Map<AccountGroup.UUID, AccountGroupIncludeByUuid> groups =
final Map<AccountGroup.UUID, AccountGroupById> groups =
Maps.newHashMap();
for (final AccountGroupIncludeByUuid g : db.accountGroupIncludesByUuid().byGroup(groupId)) {
for (final AccountGroupById g : db.accountGroupById().byGroup(groupId)) {
groups.put(g.getIncludeUUID(), g);
}
return groups;
}
private void writeAudits(final List<AccountGroupIncludeByUuid> toBeRemoved)
private void writeAudits(final List<AccountGroupById> toBeRemoved)
throws OrmException {
final Account.Id me = ((IdentifiedUser) self.get()).getAccountId();
final List<AccountGroupIncludeByUuidAudit> auditUpdates = Lists.newLinkedList();
for (final AccountGroupIncludeByUuid g : toBeRemoved) {
AccountGroupIncludeByUuidAudit audit = null;
for (AccountGroupIncludeByUuidAudit a : db
.accountGroupIncludesByUuidAudit().byGroupInclude(g.getGroupId(),
final List<AccountGroupByIdAud> auditUpdates = Lists.newLinkedList();
for (final AccountGroupById g : toBeRemoved) {
AccountGroupByIdAud audit = null;
for (AccountGroupByIdAud a : db
.accountGroupByIdAud().byGroupInclude(g.getGroupId(),
g.getIncludeUUID())) {
if (a.isActive()) {
audit = a;
@@ -126,7 +126,7 @@ public class DeleteIncludedGroups implements RestModifyView<GroupResource, Input
auditUpdates.add(audit);
}
}
db.accountGroupIncludesByUuidAudit().update(auditUpdates);
db.accountGroupByIdAud().update(auditUpdates);
}
static class DeleteIncludedGroup implements

View File

@@ -25,7 +25,7 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.extensions.restapi.TopLevelResource;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.group.AddIncludedGroups.PutIncludedGroup;
import com.google.gwtorm.server.OrmException;
@@ -78,8 +78,8 @@ public class IncludedGroupsCollection implements
private boolean isMember(AccountGroup parent, GroupDescription.Basic member)
throws OrmException {
return dbProvider.get().accountGroupIncludesByUuid().get(
new AccountGroupIncludeByUuid.Key(
return dbProvider.get().accountGroupById().get(
new AccountGroupById.Key(
parent.getId(),
member.getGroupUUID())) != null;
}

View File

@@ -20,7 +20,7 @@ import com.google.common.collect.Lists;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.account.GroupControl;
import com.google.gerrit.server.group.GroupJson.GroupInfo;
@@ -58,8 +58,8 @@ public class ListIncludedGroups implements RestReadView<GroupResource> {
boolean ownerOfParent = rsrc.getControl().isOwner();
List<GroupInfo> included = Lists.newArrayList();
for (AccountGroupIncludeByUuid u : dbProvider.get()
.accountGroupIncludesByUuid()
for (AccountGroupById u : dbProvider.get()
.accountGroupById()
.byGroup(rsrc.toAccountGroup().getId())) {
try {
GroupControl i = controlFactory.controlFor(u.getIncludeUUID());

View File

@@ -24,7 +24,7 @@ import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupMember;
import com.google.gerrit.server.account.AccountInfo;
import com.google.gerrit.server.account.GroupCache;
@@ -119,7 +119,7 @@ public class ListMembers implements RestReadView<GroupResource> {
if (recursive) {
if (groupDetail.includes != null) {
for (final AccountGroupIncludeByUuid includedGroup : groupDetail.includes) {
for (final AccountGroupById includedGroup : groupDetail.includes) {
if (!seenGroups.contains(includedGroup.getIncludeUUID())) {
members.putAll(getMembers(includedGroup.getIncludeUUID(), seenGroups));
}

View File

@@ -32,7 +32,7 @@ import java.util.List;
/** A version of the database schema. */
public abstract class SchemaVersion {
/** The current schema version. */
public static final Class<Schema_81> C = Schema_81.class;
public static final Class<Schema_82> C = Schema_82.class;
public static class Module extends AbstractModule {
@Override
@@ -159,6 +159,18 @@ public abstract class SchemaVersion {
db.schemaVersion().update(Collections.singleton(curr));
}
/** Rename an existing table. */
protected void renameTable(ReviewDb db, String from, String to)
throws OrmException {
final JdbcSchema s = (JdbcSchema) db;
final JdbcExecutor e = new JdbcExecutor(s);
try {
s.renameTable(e, from, to);
} finally {
e.close();
}
}
/** Rename an existing column. */
protected void renameColumn(ReviewDb db, String table, String from, String to)
throws OrmException {

View File

@@ -14,33 +14,13 @@
package com.google.gerrit.server.schema;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.sql.SQLException;
import java.sql.Statement;
public class Schema_66 extends SchemaVersion {
@Inject
Schema_66(Provider<Schema_65> prior) {
super(prior);
}
@Override
protected void migrateData(ReviewDb db, UpdateUI ui)
throws OrmException, SQLException {
final Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
try {
stmt.executeUpdate("UPDATE accounts SET reverse_patch_set_order = 'Y' "+
"WHERE display_patch_sets_in_reverse_order = 'Y'");
stmt.executeUpdate("UPDATE accounts SET show_username_in_review_category = 'Y' " +
"WHERE display_person_name_in_review_category = 'Y'");
} finally {
stmt.close();
}
}
}

View File

@@ -16,8 +16,8 @@ package com.google.gerrit.server.schema;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuid;
import com.google.gerrit.reviewdb.client.AccountGroupIncludeByUuidAudit;
import com.google.gerrit.reviewdb.client.AccountGroupById;
import com.google.gerrit.reviewdb.client.AccountGroupByIdAud;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.server.OrmException;
@@ -51,10 +51,10 @@ public class Schema_74 extends SchemaVersion {
// Initialize some variables
Connection conn = ((JdbcSchema) db).getConnection();
ArrayList<AccountGroupIncludeByUuid> newIncludes =
new ArrayList<AccountGroupIncludeByUuid>();
ArrayList<AccountGroupIncludeByUuidAudit> newIncludeAudits =
new ArrayList<AccountGroupIncludeByUuidAudit>();
ArrayList<AccountGroupById> newIncludes =
new ArrayList<AccountGroupById>();
ArrayList<AccountGroupByIdAud> newIncludeAudits =
new ArrayList<AccountGroupByIdAud>();
// Iterate over all entries in account_group_includes
Statement oldGroupIncludesStmt = conn.createStatement();
@@ -75,8 +75,8 @@ public class Schema_74 extends SchemaVersion {
}
// Create the new include entry
AccountGroupIncludeByUuid destIncludeEntry = new AccountGroupIncludeByUuid(
new AccountGroupIncludeByUuid.Key(oldGroupId, uuidFromIncludeId));
AccountGroupById destIncludeEntry = new AccountGroupById(
new AccountGroupById.Key(oldGroupId, uuidFromIncludeId));
// Iterate over all the audits (for this group)
PreparedStatement oldAuditsQuery = conn.prepareStatement(
@@ -89,8 +89,8 @@ public class Schema_74 extends SchemaVersion {
int removedBy = oldGroupIncludeAudits.getInt("removed_by");
// Create the new audit entry
AccountGroupIncludeByUuidAudit destAuditEntry =
new AccountGroupIncludeByUuidAudit(destIncludeEntry, addedBy,
AccountGroupByIdAud destAuditEntry =
new AccountGroupByIdAud(destIncludeEntry, addedBy,
oldGroupIncludeAudits.getTimestamp("added_on"));
// If this was a "removed on" entry, note that
@@ -108,7 +108,7 @@ public class Schema_74 extends SchemaVersion {
oldGroupIncludesStmt.close();
// Now insert all of the new entries to the database
db.accountGroupIncludesByUuid().insert(newIncludes);
db.accountGroupIncludesByUuidAudit().insert(newIncludeAudits);
db.accountGroupById().insert(newIncludes);
db.accountGroupByIdAud().insert(newIncludeAudits);
}
}

View File

@@ -0,0 +1,152 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.schema;
import com.google.common.collect.ImmutableMap;
import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gwtorm.jdbc.JdbcExecutor;
import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.schema.sql.DialectMySQL;
import com.google.gwtorm.schema.sql.SqlDialect;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;
import java.util.Set;
public class Schema_82 extends SchemaVersion {
private Map<String,String> tables = ImmutableMap.of(
"account_group_includes_by_uuid", "account_group_by_id",
"account_group_includes_by_uuid_audit", "account_group_by_id_aud");
private Map<String,Index> indexes = ImmutableMap.of(
"account_project_watches_byProject",
new Index("account_project_watches", "account_project_watches_byP"),
"patch_set_approvals_closedByUser",
new Index("patch_set_approvals", "patch_set_approvals_closedByU"),
"submodule_subscription_access_bySubscription",
new Index("submodule_subscriptions", "submodule_subscr_acc_byS")
);
@Inject
Schema_82(Provider<Schema_81> prior) {
super(prior);
}
@Override
protected void preUpdateSchema(ReviewDb db) throws OrmException, SQLException {
final JdbcSchema s = (JdbcSchema) db;
final JdbcExecutor e = new JdbcExecutor(s);
renameTables(db, s, e);
renameColumn(db, s, e);
renameIndexes(db);
}
private void renameTables(final ReviewDb db, final JdbcSchema s,
final JdbcExecutor e) throws OrmException, SQLException {
SqlDialect dialect = ((JdbcSchema) db).getDialect();
final Set<String> existingTables = dialect.listTables(s.getConnection());
for (Map.Entry<String, String> entry : tables.entrySet()) {
// Does source table exist?
if (existingTables.contains(entry.getKey())) {
// Does target table exist?
if (!existingTables.contains(entry.getValue())) {
s.renameTable(e, entry.getKey(), entry.getValue());
}
}
}
}
private void renameColumn(final ReviewDb db, final JdbcSchema s,
final JdbcExecutor e) throws SQLException, OrmException {
SqlDialect dialect = ((JdbcSchema) db).getDialect();
final Set<String> existingColumns =
dialect.listColumns(s.getConnection(), "accounts");
// Does source column exist?
if (!existingColumns.contains("show_username_in_review_category")) {
return;
}
// Does target column exist?
if (existingColumns.contains("show_user_in_review")) {
return;
}
s.renameColumn(e, "accounts", "show_username_in_review_category",
"show_user_in_review");
// MySQL loose check constraint during the column renaming.
// Well it doesn't implemented anyway,
// check constraints are get parsed but do nothing
if (dialect instanceof DialectMySQL) {
Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
try {
addCheckConstraint(stmt);
} finally {
stmt.close();
}
}
}
private void renameIndexes(ReviewDb db) throws SQLException {
SqlDialect dialect = ((JdbcSchema) db).getDialect();
Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
try {
// MySQL doesn't have alter index stmt, drop & create
if (dialect instanceof DialectMySQL) {
for (Map.Entry<String, Index> entry : indexes.entrySet()) {
stmt.executeUpdate("DROP INDEX " + entry.getKey() + " ON "
+ entry.getValue().table);
}
stmt.executeUpdate("CREATE INDEX account_project_watches_byP ON " +
"account_project_watches (project_name)");
stmt.executeUpdate("CREATE INDEX patch_set_approvals_closedByU ON " +
"patch_set_approvals (change_open, account_id, change_sort_key)");
stmt.executeUpdate("CREATE INDEX submodule_subscr_acc_bys ON " +
"submodule_subscriptions (submodule_project_name, " +
"submodule_branch_name)");
} else {
for (Map.Entry<String, Index> entry : indexes.entrySet()) {
stmt.executeUpdate("ALTER INDEX " + entry.getKey() + " RENAME TO "
+ entry.getValue().index);
}
}
} catch (SQLException e) {
// we don't care
// better we would check if index was already renamed
// gwtorm doesn't expose this functionality
} finally {
stmt.close();
}
}
private void addCheckConstraint(Statement stmt) throws SQLException {
// add check constraint for the destination column
stmt.executeUpdate("ALTER TABLE accounts ADD CONSTRAINT "
+ "show_user_in_review_check CHECK "
+ "(show_user_in_review IN('Y', 'N'))");
}
static class Index {
String table;
String index;
Index(String tableName, String indexName) {
this.table = tableName;
this.index = indexName;
}
}
}