Change project ownership to be strictly one group
Like group ownership, a project can only be owned by one group. This simplifies the data model considerably, and starts to make a pattern where rights are granted to one group, and one group only, for any particular rights concept, especially ownership. When importing from Gerrit1 we generate a synthetic group for each project that has more than one entity in its ownership. This produces ~33 additional groups on the Android site, we can sort the ownership mess out later once its in Gerrit2. Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -76,6 +76,9 @@ public final class Project {
|
||||
@Column(length = Integer.MAX_VALUE, notNull = false)
|
||||
protected String description;
|
||||
|
||||
@Column
|
||||
protected AccountGroup.Id ownerGroupId;
|
||||
|
||||
protected Project() {
|
||||
}
|
||||
|
||||
@@ -103,4 +106,12 @@ public final class Project {
|
||||
public void setDescription(final String d) {
|
||||
description = d;
|
||||
}
|
||||
|
||||
public AccountGroup.Id getOwnerGroupId() {
|
||||
return ownerGroupId;
|
||||
}
|
||||
|
||||
public void setOwnerGroupId(final AccountGroup.Id id) {
|
||||
ownerGroupId = id;
|
||||
}
|
||||
}
|
||||
|
@@ -1,59 +0,0 @@
|
||||
// Copyright 2008 Google Inc.
|
||||
//
|
||||
// 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.client.reviewdb;
|
||||
|
||||
import com.google.gwtorm.client.Column;
|
||||
import com.google.gwtorm.client.CompoundKey;
|
||||
|
||||
/** Single {@link Account} as owner/manager of a project. */
|
||||
public final class ProjectLeadAccount {
|
||||
public static class Key extends CompoundKey<Project.NameKey> {
|
||||
@Column
|
||||
protected Project.NameKey projectName;
|
||||
|
||||
@Column
|
||||
protected Account.Id accountId;
|
||||
|
||||
protected Key() {
|
||||
projectName = new Project.NameKey();
|
||||
accountId = new Account.Id();
|
||||
}
|
||||
|
||||
public Key(final Project.NameKey p, final Account.Id a) {
|
||||
projectName = p;
|
||||
accountId = a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project.NameKey getParentKey() {
|
||||
return projectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.google.gwtorm.client.Key<?>[] members() {
|
||||
return new com.google.gwtorm.client.Key<?>[] {accountId};
|
||||
}
|
||||
}
|
||||
|
||||
@Column(name = Column.NONE)
|
||||
protected Key key;
|
||||
|
||||
protected ProjectLeadAccount() {
|
||||
}
|
||||
|
||||
public ProjectLeadAccount(final ProjectLeadAccount.Key k) {
|
||||
key = k;
|
||||
}
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
// Copyright 2008 Google Inc.
|
||||
//
|
||||
// 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.client.reviewdb;
|
||||
|
||||
import com.google.gwtorm.client.Access;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.PrimaryKey;
|
||||
import com.google.gwtorm.client.Query;
|
||||
import com.google.gwtorm.client.ResultSet;
|
||||
|
||||
public interface ProjectLeadAccountAccess extends
|
||||
Access<ProjectLeadAccount, ProjectLeadAccount.Key> {
|
||||
@PrimaryKey("key")
|
||||
ProjectLeadAccount get(ProjectLeadAccount.Key key) throws OrmException;
|
||||
|
||||
@Query("WHERE key.projectName= ?")
|
||||
ResultSet<ProjectLeadAccount> byProject(Project.NameKey id)
|
||||
throws OrmException;
|
||||
|
||||
@Query("WHERE key.accountId = ?")
|
||||
ResultSet<ProjectLeadAccount> byAccount(Account.Id id) throws OrmException;
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
// Copyright 2008 Google Inc.
|
||||
//
|
||||
// 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.client.reviewdb;
|
||||
|
||||
import com.google.gwtorm.client.Column;
|
||||
import com.google.gwtorm.client.CompoundKey;
|
||||
|
||||
/** {@link AccountGroup} as owner/manager of a project. */
|
||||
public final class ProjectLeadGroup {
|
||||
public static class Key extends CompoundKey<Project.NameKey> {
|
||||
@Column
|
||||
protected Project.NameKey projectName;
|
||||
|
||||
@Column
|
||||
protected AccountGroup.Id groupId;
|
||||
|
||||
protected Key() {
|
||||
projectName = new Project.NameKey();
|
||||
groupId = new AccountGroup.Id();
|
||||
}
|
||||
|
||||
public Key(final Project.NameKey p, final AccountGroup.Id a) {
|
||||
projectName = p;
|
||||
groupId = a;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Project.NameKey getParentKey() {
|
||||
return projectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public com.google.gwtorm.client.Key<?>[] members() {
|
||||
return new com.google.gwtorm.client.Key<?>[] {groupId};
|
||||
}
|
||||
}
|
||||
|
||||
@Column(name = Column.NONE)
|
||||
protected Key key;
|
||||
|
||||
protected ProjectLeadGroup() {
|
||||
}
|
||||
|
||||
public ProjectLeadGroup(final ProjectLeadGroup.Key k) {
|
||||
key = k;
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
// Copyright 2008 Google Inc.
|
||||
//
|
||||
// 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.client.reviewdb;
|
||||
|
||||
import com.google.gwtorm.client.Access;
|
||||
import com.google.gwtorm.client.OrmException;
|
||||
import com.google.gwtorm.client.PrimaryKey;
|
||||
import com.google.gwtorm.client.Query;
|
||||
import com.google.gwtorm.client.ResultSet;
|
||||
|
||||
public interface ProjectLeadGroupAccess extends
|
||||
Access<ProjectLeadGroup, ProjectLeadGroup.Key> {
|
||||
@PrimaryKey("key")
|
||||
ProjectLeadGroup get(ProjectLeadGroup.Key key) throws OrmException;
|
||||
|
||||
@Query("WHERE key.projectName= ?")
|
||||
ResultSet<ProjectLeadGroup> byProject(Project.NameKey id) throws OrmException;
|
||||
|
||||
@Query("WHERE key.groupId = ?")
|
||||
ResultSet<ProjectLeadGroup> byGroup(AccountGroup.Id id) throws OrmException;
|
||||
}
|
@@ -62,12 +62,6 @@ public interface ReviewDb extends Schema {
|
||||
@Relation
|
||||
BranchAccess branches();
|
||||
|
||||
@Relation
|
||||
ProjectLeadAccountAccess projectLeadAccounts();
|
||||
|
||||
@Relation
|
||||
ProjectLeadGroupAccess projectLeadGroups();
|
||||
|
||||
@Relation
|
||||
ChangeAccess changes();
|
||||
|
||||
|
@@ -168,14 +168,10 @@ INSERT INTO account_group_members
|
||||
o.group_name = g.name
|
||||
AND a.preferred_email = o.email;
|
||||
|
||||
UPDATE account_groups
|
||||
SET name = 'Administrators'
|
||||
WHERE name = 'admin';
|
||||
|
||||
UPDATE system_config
|
||||
SET admin_group_id = (SELECT group_id
|
||||
FROM account_groups
|
||||
WHERE name = 'Administrators');
|
||||
WHERE name = 'admin');
|
||||
|
||||
UPDATE account_groups
|
||||
SET owner_group_id = (SELECT admin_group_id FROM system_config);
|
||||
@@ -184,10 +180,12 @@ DELETE FROM projects;
|
||||
INSERT INTO projects
|
||||
(project_id,
|
||||
description,
|
||||
name) SELECT
|
||||
name,
|
||||
owner_group_id) SELECT
|
||||
p.project_id,
|
||||
p.comment,
|
||||
p.name
|
||||
p.name,
|
||||
(SELECT admin_group_id FROM system_config)
|
||||
FROM gerrit1.projects p;
|
||||
|
||||
DELETE FROM account_project_watches;
|
||||
@@ -213,31 +211,98 @@ INSERT INTO branches
|
||||
FROM gerrit1.branches b, gerrit1.projects p
|
||||
WHERE p.gae_key = b.project_key;
|
||||
|
||||
DELETE FROM project_lead_accounts;
|
||||
INSERT INTO project_lead_accounts
|
||||
(project_name,
|
||||
account_id) SELECT
|
||||
p.name,
|
||||
a.account_id
|
||||
FROM projects p,
|
||||
accounts a,
|
||||
gerrit1.project_owner_users o
|
||||
CREATE TEMPORARY TABLE need_groups (project_id INT NOT NULL);
|
||||
INSERT INTO need_groups
|
||||
SELECT p.project_id
|
||||
FROM projects p, gerrit1.project_owner_groups o
|
||||
WHERE p.project_id = o.project_id
|
||||
GROUP BY p.project_id
|
||||
HAVING COUNT(*) > 1;
|
||||
INSERT INTO need_groups
|
||||
SELECT p.project_id
|
||||
FROM projects p
|
||||
WHERE EXISTS (SELECT 1 FROM gerrit1.project_owner_users u
|
||||
WHERE u.project_id = p.project_id)
|
||||
AND NOT EXISTS (SELECT 1 FROM need_groups n
|
||||
WHERE n.project_id = p.project_id);
|
||||
|
||||
INSERT INTO account_groups
|
||||
(group_id,
|
||||
owner_group_id,
|
||||
description,
|
||||
name) SELECT
|
||||
nextval('account_group_id'),
|
||||
(SELECT admin_group_id FROM system_config),
|
||||
p.name || ' maintainers',
|
||||
substring(p.name from '^.*/([^/]*)$') || '_' || p.project_id || '-owners'
|
||||
FROM projects p, need_groups g
|
||||
WHERE p.project_id = g.project_id;
|
||||
|
||||
UPDATE account_groups
|
||||
SET owner_group_id = group_id
|
||||
WHERE name IN (SELECT
|
||||
substring(p.name from '^.*/([^/]*)$') || '_' || p.project_id || '-owners'
|
||||
FROM projects p, need_groups g
|
||||
WHERE p.project_id = g.project_id);
|
||||
|
||||
UPDATE projects
|
||||
SET owner_group_id = (SELECT group_id
|
||||
FROM account_groups
|
||||
WHERE name = substring(projects.name
|
||||
from '^.*/([^/]*)$') || '_' || projects.project_id || '-owners')
|
||||
WHERE project_id IN (SELECT project_id FROM need_groups);
|
||||
|
||||
INSERT INTO account_group_members
|
||||
(account_id,
|
||||
group_id) SELECT DISTINCT
|
||||
q.account_id,
|
||||
p.owner_group_id
|
||||
FROM projects p,
|
||||
need_groups n,
|
||||
gerrit1.account_groups og,
|
||||
gerrit1.project_owner_groups o,
|
||||
account_groups g,
|
||||
account_group_members q
|
||||
WHERE
|
||||
n.project_id = p.project_id
|
||||
AND o.project_id = p.project_id
|
||||
AND og.gae_key = o.group_key
|
||||
AND g.name = og.name
|
||||
AND q.group_id = g.group_id
|
||||
UNION
|
||||
SELECT
|
||||
a.account_id,
|
||||
p.owner_group_id
|
||||
FROM accounts a,
|
||||
projects p,
|
||||
need_groups n,
|
||||
gerrit1.project_owner_users o
|
||||
WHERE
|
||||
n.project_id = p.project_id
|
||||
AND o.project_id = p.project_id
|
||||
AND a.preferred_email = o.email;
|
||||
|
||||
DELETE FROM project_lead_groups;
|
||||
INSERT INTO project_lead_groups
|
||||
(project_name,
|
||||
group_id) SELECT
|
||||
p.name,
|
||||
g.group_id
|
||||
FROM projects p,
|
||||
account_groups g,
|
||||
UPDATE projects
|
||||
SET owner_group_id = (
|
||||
SELECT g.group_id
|
||||
FROM account_groups g,
|
||||
gerrit1.project_owner_groups o,
|
||||
gerrit1.account_groups og
|
||||
WHERE p.project_id = o.project_id
|
||||
WHERE projects.project_id = o.project_id
|
||||
AND og.gae_key = o.group_key
|
||||
AND g.name = og.name;
|
||||
AND g.name = og.name)
|
||||
WHERE project_id NOT IN (SELECT project_id FROM need_groups)
|
||||
AND EXISTS (
|
||||
SELECT g.group_id
|
||||
FROM account_groups g,
|
||||
gerrit1.project_owner_groups o,
|
||||
gerrit1.account_groups og
|
||||
WHERE projects.project_id = o.project_id
|
||||
AND og.gae_key = o.group_key
|
||||
AND g.name = og.name);
|
||||
|
||||
DROP TABLE need_groups;
|
||||
|
||||
|
||||
DELETE FROM changes;
|
||||
INSERT INTO changes
|
||||
@@ -501,6 +566,9 @@ FROM gerrit1.account_stars s,
|
||||
WHERE a.preferred_email = s.email
|
||||
AND c.change_id = s.change_id;
|
||||
|
||||
UPDATE account_groups
|
||||
SET name = 'Administrators'
|
||||
WHERE name = 'admin';
|
||||
|
||||
-- Fix change.nbr_patch_sets
|
||||
--
|
||||
|
Reference in New Issue
Block a user