Remove Gerrit 1.x to 2.x import tools

Its been almost 2 full months since the first release of Gerrit 2.x.
Any administrator still running Gerrit 1.x on Google App Engine must
have converted by now to Gerrit2, and if they haven't, they really
need to consider doing it as soon as possible, as the upgrade path
is already very painful due to schema changes in Gerrit 2.x.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce 2009-03-27 20:20:10 -07:00
parent d03e5f9095
commit e86cb93d36
8 changed files with 0 additions and 1135 deletions

View File

@ -1,155 +0,0 @@
Gerrit2 - Importing From Gerrit1
================================
To switch from Google App Engine running Gerrit1 to a Gerrit2 based
system, you need to export all of the data from the GAE data store
and load it into PostgreSQL, converting the schema in the process.
[NOTE]
You must be using a source build of both Gerrit1 and Gerrit2.
The Gerrit2 binary packages do not include the conversion tools
necessary to upgrade from Gerrit1.
[NOTE]
To get a source build of Gerrit1, use the version immediately before
it merged into Gerrit2: `git checkout v2.0-rc0^2`
GAE Backup
----------
Create a PostgreSQL database to house the backup:
====
createdb -E UTF-8 gaeback
====
From the Gerrit1 sources, load the schema:
====
psql -f backup/create.sql gaeback
====
Ensure you have a copy of the Google App Engine SDK in
`../../google_appengine`. This path is hardcoded into the backup
script. (Or edit the backup script to import the SDK directory.)
Execute the backup task, supplying the credentials of
an application developer:
====
webapp/backup_gae.py \
-d gaeback \
-s yourapp.appspot.com \
-e you@example.com
====
Backups are not incremental, they dump the entire data store.
The backup does not clear the database. If you are doing
repeated conversions, it is recommended that you use `dropdb`
to drop the database and recreate it before each backup.
Backups are not consistent. You may want to consider uploading the
application in administrator-only mode, so end-users cannot modify
the data store while the backup is taking place:
====
make update APPID=yourapp ADMIN_ONLY=1
====
To restore normal access:
====
make update APPID=yourapp
====
Export Dump File
----------------
Rename the schema to `gerrit1`, and then dump it into a
backup file:
====
psql -c 'ALTER SCHEMA public RENAME TO gerrit1' gaeback
pg_dump -O -Fc gaeback >yourapp.dump
====
Gerrit2 Database Setup
----------------------
Tell Gerrit about your database connection information. Note that
the username you use here *must* be the default of `gerrit2` and
the database name *must* be the default of `reviewdb`, unless you
modify `gerrit1_import/1-to-2.sh`.
====
./gerrit.war --cat extra/GerritServer.properties_example >GerritServer.properties
====
Make sure the user exists in PostgreSQL:
====
createuser -A -D -P -E gerrit2
====
Gerrit2 Import
--------------
Create a short SQL script to set the `system_config` table correctly
for the import process. This might look like:
====
$ cat config.sql
UPDATE system_config
SET git_base_path='/srv/git';
====
where `git_base_path` is pointing to the same directory that
`codereview.basedir` was set to in your Gerrit1 mgrapp config file.
The import task requires read access to these repositories.
In the Gerrit2 source tree use `1-to-2.sh` to finish the conversion
process:
====
sh gerrit1_import/1-to-2.sh yourapp.dump config.sql
====
Fixup Groups
------------
During the Gerrit1 to Gerrit2 schema conversion process some
additional groups may have been created. This was necessary
to enforce the same permissions within a project while moving
to a system that assigns permissions only to groups, and not
to individual users.
You may want to browse #admin,groups once logged in through
the web UI and cleanup any group names that were generated
automatically by the import process.
User Account Migration
----------------------
After import `system_config.allow_google_account_upgrade` will be
set to `Y` to permit users to upgrade their account from a Google
Account in Google App Engine to an OpenID based Google Account.
Its strongly encouraged for administrators to set this flag to 'N'
once the following query drops to 0, or close to 0:
====
SELECT COUNT(*) FROM account_external_ids e
WHERE e.external_id LIKE 'Google Account %'
AND NOT EXISTS (SELECT 1
FROM account_external_ids o
WHERE o.account_id = e.account_id
AND o.external_id LIKE '%.google.com%/id?id=%');
====
the above query lists all users who have not yet converted their
accounts to the OpenID authentication scheme. Unfortunately the
conversion must be done by each individual user logging in, as the
OpenID token is per-user, and per-site.

View File

@ -46,8 +46,3 @@ Gerrit resources:
* link:http://code.google.com/p/gerrit/[Project Site]
* link:http://code.google.com/p/gerrit/wiki/Issues?tm=3[Issue Tracking]
Upgrading
---------
* link:gerrit1-import.html[From Gerrit1]

View File

@ -1,3 +1 @@
See Documentation/install.txt
To import from Gerrit1, see Documentation/gerrit1-import.txt.

View File

@ -1,52 +0,0 @@
#!/bin/sh
# To get a gerrit1.dump:
# psql -c 'ALTER SCHEMA public RENAME TO gerrit1' $src
# pg_dump -O -Fc $src >gerrit1.dump
#
# Your config.sql should look like:
# UPDATE system_config
# SET
# site_path='/home/gerrit2/site_dir'
# ,git_base_path='/srv/git'
# ;
v1data="$1"
cfgsql="$2"
nobuild="$3"
if [ -z "$v1data" -o -z "$cfgsql" ]
then
echo >&2 "usage: $0 gerrit1.dump config.sql [-n]"
exit 1
fi
dstdb=reviewdb
user=gerrit2
if [ -z "$nobuild" ]
then
mvn package || exit
fi
out=target/gerrit-*.war
g2="java -jar $out"
dropdb $dstdb
createdb -E UTF-8 -O $user $dstdb || exit
pg_restore -O -d $dstdb $v1data || exit
$g2 CreateSchema || exit
psql -f gerrit1_import/import_gerrit1_a.sql $dstdb || exit
psql -f $cfgsql $dstdb || exit
$g2 ImportGerrit1 || exit
psql -f gerrit1_import/import_gerrit1_b.sql $dstdb || exit
echo >&2
echo >&2 "Creating secondary indexes..."
echo >&2 " ignore failures unless on a production system"
$g2 --cat sql/query_index.sql | psql $dstdb
echo >&2
psql -c 'DROP SCHEMA gerrit1 CASCADE' $dstdb
psql -c 'VACUUM FULL VERBOSE ANALYZE' $dstdb
echo "CONVERT Gerrit 1 -> Gerrit 2 SUCCESSFUL"

View File

@ -1,25 +0,0 @@
#!/bin/sh
# This script assumes the Gerrit1 import has already been
# renamed to 'gerrit1' schema:
#
# psql -c 'ALTER SCHEMA public RENAME TO gerrit1' $src
#
src=android_codereview
tmp=safedump
N="N.$$.sql"
dropdb $tmp
createdb -E UTF-8 $tmp &&
pg_dump -O -Fc $src >$N &&
pg_restore -d $tmp $N &&
psql -c 'UPDATE gerrit1.accounts SET
mailing_address = NULL
,mailing_address_country = NULL
,phone_number = NULL
,fax_number = NULL
,cla_comments = NULL' $tmp &&
pg_dump -O -Fc $tmp | bzip2 -9 >gerrit1.dump.bz2
dropdb $tmp
rm -f $N

View File

@ -1,718 +0,0 @@
-- PostgreSQL conversion from Gerrit 1 -> Gerrit 2
--
-- If this is the first time the Gerrit1 schema has been used it
-- needs to be renamed:
-- psql -c 'ALTER SCHEMA public RENAME TO gerrit1' $srcdb
--
-- Make sure there is a current dump file:
-- pg_dump -O -Fc $src >gerrit1.dump
--
-- Write your "UPDATE system_config SET ..." and put it into
-- some config.sql script. At least git_base_path must be set.
--
-- Execute the conversion script:
-- gerrit1_import/1-to-2.sh gerrit1.dump config.sql
--
DELETE FROM accounts;
INSERT INTO accounts
(account_id,
registered_on,
full_name,
preferred_email,
ssh_user_name,
contact_address,
contact_country,
contact_phone_nbr,
contact_fax_nbr,
default_context
) SELECT
nextval('account_id'),
a.created,
a.real_name,
a.user_email,
CASE WHEN a.user_email LIKE '%@%'
THEN lower(substring(a.user_email from '^(.*)@.*$'))
ELSE NULL
END,
a.mailing_address,
a.mailing_address_country,
a.phone_number,
a.fax_number,
a.default_context
FROM gerrit1.accounts a;
UPDATE system_config
SET allow_google_account_upgrade = 'Y';
DELETE FROM account_external_ids;
INSERT INTO account_external_ids
(account_id,
external_id,
email_address) SELECT
l.account_id,
'Google Account ' || a.user_email,
a.user_email
FROM gerrit1.accounts a, accounts l
WHERE l.preferred_email = a.user_email;
DELETE FROM contributor_agreements;
INSERT INTO contributor_agreements
(active,
require_contact_information,
auto_verify,
short_name,
short_description,
agreement_url,
id) VALUES (
'Y',
'Y',
'Y',
'Individual',
'If you are going to be contributing code on your own, this is the one you want. You can sign this one online.',
'static/cla_individual.html',
nextval('contributor_agreement_id'));
INSERT INTO contributor_agreements
(active,
require_contact_information,
auto_verify,
short_name,
short_description,
agreement_url,
id) VALUES (
'Y',
'N',
'N',
'Corporate',
'If you are going to be contributing code on behalf of your company, this is the one you want. We\'ll give you a form that will need to printed, signed and sent back via post, email or fax.',
'static/cla_corporate.html',
nextval('contributor_agreement_id'));
DELETE FROM account_agreements;
INSERT INTO account_agreements
(accepted_on,
status,
account_id,
review_comments,
reviewed_by,
reviewed_on,
cla_id) SELECT
a.individual_cla_timestamp,
CASE WHEN a.cla_verified = 'Y' THEN 'V'
ELSE 'n'
END,
r.account_id,
a.cla_comments,
(SELECT m.account_id FROM accounts m
WHERE m.preferred_email = a.cla_verified_by),
a.cla_verified_timestamp,
i.id
FROM contributor_agreements i,
gerrit1.accounts a,
accounts r
WHERE i.short_name = 'Individual'
AND a.individual_cla_version = 1
AND r.preferred_email = a.user_email;
INSERT INTO account_agreements
(accepted_on,
status,
account_id,
review_comments,
reviewed_by,
reviewed_on,
cla_id) SELECT
CASE WHEN a.individual_cla_timestamp IS NOT NULL
THEN a.individual_cla_timestamp
ELSE a.created
END,
'V',
r.account_id,
a.cla_comments,
(SELECT m.account_id FROM accounts m
WHERE m.preferred_email = a.cla_verified_by),
a.cla_verified_timestamp,
i.id
FROM contributor_agreements i,
gerrit1.accounts a,
accounts r
WHERE i.short_name = 'Corporate'
AND a.individual_cla_version = 0
AND a.cla_verified = 'Y'
AND r.preferred_email = a.user_email;
DELETE FROM account_groups;
INSERT INTO account_groups
(group_id,
description,
name) SELECT
nextval('account_group_id'),
g.comment,
g.name
FROM gerrit1.account_groups g;
INSERT INTO account_groups
(group_id,
description,
name) VALUES
(nextval('account_group_id'),
'Any user, signed-in or not',
'Anonymous Users');
INSERT INTO account_groups
(group_id,
description,
name) VALUES
(nextval('account_group_id'),
'Any signed-in user',
'Registered Users');
DELETE FROM account_group_members;
INSERT INTO account_group_members
(account_id,
group_id) SELECT
a.account_id,
g.group_id
FROM accounts a,
account_groups g,
gerrit1.account_group_users o
WHERE
o.group_name = g.name
AND a.preferred_email = o.email;
UPDATE system_config
SET
use_contributor_agreements = 'Y'
,admin_group_id = (SELECT group_id
FROM account_groups
WHERE name = 'admin')
,anonymous_group_id = (SELECT group_id
FROM account_groups
WHERE name = 'Anonymous Users')
,registered_group_id = (SELECT group_id
FROM account_groups
WHERE name = 'Registered Users');
UPDATE account_groups
SET owner_group_id = (SELECT admin_group_id FROM system_config);
DELETE FROM projects WHERE project_id <> 0;
INSERT INTO projects
(project_id,
description,
name,
use_contributor_agreements,
owner_group_id) SELECT
p.project_id,
p.comment,
p.name,
'Y',
(SELECT admin_group_id FROM system_config)
FROM gerrit1.projects p;
DELETE FROM account_project_watches;
INSERT INTO account_project_watches
(account_id,
project_id) SELECT
a.account_id,
p.project_id
FROM gerrit1.projects p,
accounts a,
gerrit1.account_unclaimed_changes_projects q
WHERE a.preferred_email = q.email
AND p.gae_key = q.project_key;
DELETE FROM branches;
INSERT INTO branches
(branch_id,
project_name,
branch_name) SELECT
nextval('branch_id'),
p.name,
b.name
FROM gerrit1.branches b, gerrit1.projects p
WHERE p.gae_key = b.project_key;
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;
UPDATE projects
SET owner_group_id = (
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)
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
(created_on,
last_updated_on,
owner_account_id,
dest_project_name,
dest_branch_name,
status,
open,
nbr_patch_sets,
current_patch_set_id,
subject,
change_id) SELECT
c.created,
c.modified,
a.account_id,
p.name,
b.name,
CASE WHEN c.merged = 'Y' THEN 'M'
WHEN c.closed = 'Y' THEN 'A'
ELSE 'n'
END,
CASE WHEN c.merged = 'Y' THEN 'N'
WHEN c.closed = 'Y' THEN 'N'
ELSE 'Y'
END,
c.n_patchsets,
c.n_patchsets,
c.subject,
c.change_id
FROM gerrit1.changes c,
accounts a,
gerrit1.projects p,
gerrit1.branches b
WHERE
a.preferred_email = c.owner
AND p.gae_key = c.dest_project_key
AND b.gae_key = c.dest_branch_key
;
UPDATE gerrit1.messages
SET sender = substring(sender from '<(.*)>')
WHERE sender LIKE '%<%>';
UPDATE gerrit1.messages
SET sender = NULL
WHERE sender = 'code-review@android.com';
UPDATE gerrit1.messages
SET body = 'Change has been successfully merged into the git repository.'
WHERE body LIKE '
Hi.
Your change has been successfully merged into the git repository.
-Your friendly git merger%'
AND sender IS NULL;
UPDATE gerrit1.messages
SET body = 'Change could not be merged because of a missing dependency. As soon as its dependencies are submitted, the change will be submitted.'
WHERE (body LIKE '
Hi.
Your change could not be merged because of a missing dependency.%
-Your friendly git merger%'
OR body LIKE '
Your change could not be merged because of a missing dependency.
As soon as all dependencies are submitted, your change will be
resubmitted automatically.%'
) AND sender IS NULL;
UPDATE gerrit1.messages
SET body = 'Change cannot be merged because of a path conflict.'
WHERE body LIKE '
Hi.
Your change has not been successfully merged into the git repository
because of a path conflict.
-Your friendly git merger%'
AND sender is NULL;
UPDATE gerrit1.messages
SET body = TRIM(both '
' FROM body);
DELETE FROM change_messages;
INSERT INTO change_messages
(change_id,
uuid,
author_id,
written_on,
message) SELECT
c.change_id,
substr(m.gae_key, length(m.change_key) + length('wLEgdNZXNzYWdlG')),
a.account_id,
m.date_sent,
m.body
FROM gerrit1.messages m
LEFT OUTER JOIN accounts a ON a.preferred_email = m.sender,
gerrit1.changes c
WHERE
c.gae_key = m.change_key;
DELETE FROM patch_sets;
INSERT INTO patch_sets
(revision,
change_id,
patch_set_id,
created_on,
uploader_account_id) SELECT
r.revision_id,
c.change_id,
p.patchset_id,
p.created,
a.account_id
FROM gerrit1.patch_sets p
JOIN accounts a ON a.preferred_email = p.owner
JOIN gerrit1.changes c ON p.change_key = c.gae_key
LEFT OUTER JOIN gerrit1.revisions r ON r.gae_key = p.revision_key;
DELETE FROM patch_set_info;
INSERT INTO patch_set_info
(subject,
message,
author_name,
author_email,
author_when,
author_tz,
committer_name,
committer_email,
committer_when,
committer_tz,
change_id,
patch_set_id) SELECT DISTINCT
(SELECT c.subject FROM changes c
WHERE c.change_id = p.change_id
AND c.current_patch_set_id = p.patch_set_id),
r.message,
r.author_name,
r.author_email,
r.author_when,
r.author_tz,
r.committer_name,
r.committer_email,
r.committer_when,
r.committer_tz,
p.change_id,
p.patch_set_id
FROM gerrit1.revisions r, patch_sets p
WHERE r.revision_id = p.revision;
DELETE FROM patch_set_ancestors;
INSERT INTO patch_set_ancestors
(ancestor_revision,
change_id,
patch_set_id,
position
) SELECT DISTINCT
p.parent_id,
ps.change_id,
ps.patch_set_id,
p.position
FROM gerrit1.revision_ancestors p,
patch_sets ps
WHERE ps.revision = p.child_id;
DELETE FROM patches;
INSERT INTO patches
(change_type,
patch_type,
nbr_comments,
change_id,
patch_set_id,
file_name) SELECT
p.status,
CASE WHEN p.multi_way_diff = 'Y' THEN 'N'
ELSE 'U'
END,
p.n_comments,
c.change_id,
ps.patchset_id,
p.filename
FROM gerrit1.patches p,
gerrit1.patch_sets ps,
gerrit1.changes c
WHERE p.patchset_key = ps.gae_key
AND ps.change_key = c.gae_key;
DELETE FROM patch_comments;
INSERT INTO patch_comments
(line_nbr,
author_id,
written_on,
status,
side,
message,
change_id,
patch_set_id,
file_name,
uuid) SELECT
c.lineno,
a.account_id,
c.written,
CASE WHEN c.draft = 'Y' THEN 'd'
ELSE 'P'
END,
CASE WHEN c.is_left = 'Y' THEN 0
ELSE 1
END,
c.body,
o_c.change_id,
o_ps.patchset_id,
o_p.filename,
c.message_id
FROM gerrit1.comments c,
accounts a,
gerrit1.patches o_p,
gerrit1.patch_sets o_ps,
gerrit1.changes o_c
WHERE o_p.patchset_key = o_ps.gae_key
AND o_ps.change_key = o_c.gae_key
AND o_p.gae_key = c.patch_key
AND a.preferred_email = c.author;
DELETE FROM change_approvals;
INSERT INTO change_approvals
(value,
change_id,
account_id,
category_id) SELECT
1,
c.change_id,
a.account_id,
'VRIF'
FROM gerrit1.review_status s,
gerrit1.changes c,
accounts a
WHERE
s.verified = 'Y'
AND s.change_key = c.gae_key
AND a.preferred_email = s.email;
INSERT INTO change_approvals
(value,
change_id,
account_id,
category_id) SELECT
CASE WHEN s.lgtm = 'lgtm' THEN 2
WHEN s.lgtm = 'yes' THEN 1
WHEN s.lgtm = 'abstain' THEN 0
WHEN s.lgtm = 'no' THEN -1
WHEN s.lgtm = 'reject' THEN -2
ELSE NULL
END,
c.change_id,
a.account_id,
'CRVW'
FROM gerrit1.review_status s,
gerrit1.changes c,
accounts a
WHERE
s.lgtm IS NOT NULL
AND s.change_key = c.gae_key
AND a.preferred_email = s.email;
DELETE FROM starred_changes;
INSERT INTO starred_changes
(account_id,
change_id) SELECT
a.account_id,
c.change_id
FROM gerrit1.account_stars s,
accounts a,
changes c
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
--
UPDATE changes
SET nbr_patch_sets = (SELECT MAX(p.patch_set_id)
FROM patch_sets p
WHERE p.change_id = changes.change_id);
-- Fix change.last_updated_on
--
CREATE TEMPORARY TABLE temp_dates (
change_id INT NOT NULL,
dt TIMESTAMP NOT NULL);
INSERT INTO temp_dates
SELECT change_id,written_on
FROM patch_comments
WHERE status = 'P';
INSERT INTO temp_dates
SELECT change_id,written_on FROM change_messages;
INSERT INTO temp_dates
SELECT change_id,merge_submitted
FROM gerrit1.changes
WHERE merge_submitted IS NOT NULL
AND merged = 'Y';
UPDATE changes
SET last_updated_on = (SELECT MAX(m.dt)
FROM temp_dates m
WHERE m.change_id = changes.change_id)
WHERE EXISTS (SELECT 1 FROM temp_dates m
WHERE m.change_id = changes.change_id);
DROP TABLE temp_dates;
-- Fix patches.nbr_comments
--
UPDATE patches
SET nbr_comments = (SELECT COUNT(*)
FROM patch_comments c
WHERE c.status = 'P'
AND c.change_id = patches.change_id
AND c.patch_set_id = patches.patch_set_id
AND c.file_name = patches.file_name);
SELECT
(SELECT COUNT(*) FROM gerrit1.accounts) as accounts_g1,
(SELECT COUNT(*) FROM accounts) as accounts_g1
WHERE
(SELECT COUNT(*) FROM gerrit1.accounts)
!=(SELECT COUNT(*) FROM accounts);
SELECT
(SELECT COUNT(*) FROM gerrit1.changes) as changes_g1,
(SELECT COUNT(*) FROM changes) as changes_g2
WHERE
(SELECT COUNT(*) FROM gerrit1.changes)
!=(SELECT COUNT(*) FROM changes);
SELECT
(SELECT COUNT(*) FROM gerrit1.messages) as messages_g1,
(SELECT COUNT(*) FROM change_messages) as messages_g2
WHERE
(SELECT COUNT(*) FROM gerrit1.messages)
!=(SELECT COUNT(*) FROM change_messages);
SELECT
(SELECT COUNT(*) FROM gerrit1.patch_sets) as patch_sets_g1,
(SELECT COUNT(*) FROM patch_sets) as patch_sets_g2
WHERE
(SELECT COUNT(*) FROM gerrit1.patch_sets)
!=(SELECT COUNT(*) FROM patch_sets);
SELECT
(SELECT COUNT(*) FROM gerrit1.patches g, gerrit1.patch_sets p
WHERE g.patchset_key = p.gae_key) as patches_g1,
(SELECT COUNT(*) FROM patches) as patches_g2
WHERE
(SELECT COUNT(*) FROM gerrit1.patches g, gerrit1.patch_sets p
WHERE g.patchset_key = p.gae_key)
!=(SELECT COUNT(*) FROM patches);
SELECT
(SELECT COUNT(*) FROM gerrit1.comments) as comments_g1,
(SELECT COUNT(*) FROM patch_comments) as comments_g2
WHERE
(SELECT COUNT(*) FROM gerrit1.comments)
!=(SELECT COUNT(*) FROM patch_comments);
-- Reset sequences
--
-- account_group_id (above)
-- account_id (above)
-- branch_id (above)
SELECT setval('change_id',(SELECT MAX(change_id) FROM changes));
-- contributor_agreement_id (above)
SELECT setval('project_id',(SELECT MAX(project_id) FROM projects));
-- Grant access to read tables needed for import
--
GRANT SELECT ON gerrit1.project_code_reviews TO gerrit2;
GRANT SELECT ON gerrit1.approval_right_groups TO gerrit2;
GRANT SELECT ON gerrit1.approval_right_users TO gerrit2;
GRANT SELECT ON gerrit1.approval_rights TO gerrit2;
GRANT SELECT ON gerrit1.account_groups TO gerrit2;

View File

@ -1,27 +0,0 @@
-- Enable notifyNewChanges for project owners, approvers
-- Almost everyone has asked for this feature in Gerrit1,
-- so turn it on by default for people who are most likely
-- going to want it.
--
UPDATE account_project_watches
SET notify_new_changes = 'Y'
WHERE notify_new_changes = 'N'
AND EXISTS (SELECT 1
FROM projects p,
account_group_members g
WHERE p.project_id = account_project_watches.project_id
AND g.account_id = account_project_watches.account_id
AND g.group_id = p.owner_group_id);
UPDATE account_project_watches
SET notify_new_changes = 'Y'
WHERE notify_new_changes = 'N'
AND EXISTS (SELECT 1
FROM project_rights r,
account_group_members g
WHERE r.project_id = account_project_watches.project_id
AND r.category_id = 'CRVW'
AND r.max_value >= 2
AND g.account_id = account_project_watches.account_id
AND g.group_id = r.group_id);

View File

@ -1,151 +0,0 @@
-- Transfers all account data from one account to another.
--
-- Create /tmp/link_accounts.csv as "junk,from_email,to_email"
-- chmod a+r /tmp/link_accounts.csv
-- (must be on the PostgreSQL server)
DROP TABLE links;
DROP TABLE to_del;
CREATE TEMP TABLE links
(date_junk VARCHAR(255),
from_email VARCHAR(255),
to_email VARCHAR(255));
COPY links FROM '/tmp/link_accounts.csv' DELIMITER ',';
ALTER TABLE links DROP date_junk;
ALTER TABLE links ADD from_id INT;
ALTER TABLE links ADD to_id INT;
UPDATE links
SET from_id = (SELECT account_id FROM accounts
WHERE preferred_email = links.from_email)
, to_id = (SELECT account_id FROM accounts
WHERE preferred_email = links.to_email);
DELETE FROM links
WHERE (from_email = to_email)
OR (from_id IS NULL AND to_id IS NULL);
CREATE TEMP TABLE to_del (old_id INT);
BEGIN TRANSACTION;
INSERT INTO account_external_ids
(email_address, account_id, external_id)
SELECT
l.from_email
,l.to_id
,'Google Account ' || l.from_email
FROM links l
WHERE l.to_id IS NOT NULL
AND NOT EXISTS (SELECT 1 FROM account_external_ids e
WHERE e.email_address = l.from_email
AND e.account_id = l.to_id
AND e.external_id = 'Google Account ' || l.from_email);
INSERT INTO account_external_ids
(email_address, account_id, external_id)
SELECT
l.to_email
,l.from_id
,'Google Account ' || l.to_email
FROM links l
WHERE l.from_id IS NOT NULL AND l.to_id IS NULL
AND NOT EXISTS (SELECT 1 FROM account_external_ids e
WHERE e.email_address = l.to_email
AND e.account_id = l.from_id
AND e.external_id = 'Google Account ' || l.to_email);
INSERT INTO starred_changes
(account_id, change_id)
SELECT l.to_id, s.change_id
FROM links l, starred_changes s
WHERE l.from_id IS NOT NULL
AND l.to_id IS NOT NULL
AND s.account_id = l.from_id
AND NOT EXISTS (SELECT 1 FROM starred_changes e
WHERE e.account_id = l.to_id
AND e.change_id = s.change_id);
INSERT INTO account_project_watches
(account_id, project_id)
SELECT l.to_id, s.project_id
FROM links l, account_project_watches s
WHERE l.from_id IS NOT NULL
AND l.to_id IS NOT NULL
AND s.account_id = l.from_id
AND NOT EXISTS (SELECT 1 FROM account_project_watches e
WHERE e.account_id = l.to_id
AND e.project_id = s.project_id);
INSERT INTO account_group_members
(account_id, group_id)
SELECT l.to_id, s.group_id
FROM links l, account_group_members s
WHERE l.from_id IS NOT NULL
AND l.to_id IS NOT NULL
AND s.account_id = l.from_id
AND NOT EXISTS (SELECT 1 FROM account_group_members e
WHERE e.account_id = l.to_id
AND e.group_id = s.group_id);
UPDATE changes
SET owner_account_id = (SELECT l.to_id
FROM links l
WHERE l.from_id = owner_account_id)
WHERE EXISTS (SELECT 1 FROM links l
WHERE l.to_id IS NOT NULL
AND l.from_id IS NOT NULL
AND l.from_id = owner_account_id);
UPDATE change_approvals
SET account_id = (SELECT l.to_id
FROM links l
WHERE l.from_id = account_id)
WHERE EXISTS (SELECT 1 FROM links l
WHERE l.to_id IS NOT NULL
AND l.from_id IS NOT NULL
AND l.from_id = account_id)
AND NOT EXISTS (SELECT 1 FROM change_approvals e, links l
WHERE e.change_id = change_approvals.change_id
AND e.account_id = l.to_id
AND e.category_id = change_approvals.category_id
AND l.from_id = change_approvals.account_id);
UPDATE change_messages
SET author_id = (SELECT l.to_id
FROM links l
WHERE l.from_id = author_id)
WHERE EXISTS (SELECT 1 FROM links l
WHERE l.to_id IS NOT NULL
AND l.from_id IS NOT NULL
AND l.from_id = author_id);
UPDATE patch_comments
SET author_id = (SELECT l.to_id
FROM links l
WHERE l.from_id = author_id)
WHERE EXISTS (SELECT 1 FROM links l
WHERE l.to_id IS NOT NULL
AND l.from_id IS NOT NULL
AND l.from_id = author_id);
-- Destroy the from account
--
INSERT INTO to_del
SELECT from_id FROM links
WHERE to_id IS NOT NULL
AND from_id IS NOT NULL;
DELETE FROM account_agreements WHERE account_id IN (SELECT old_id FROM to_del);
DELETE FROM account_external_ids WHERE account_id IN (SELECT old_id FROM to_del);
DELETE FROM account_group_members WHERE account_id IN (SELECT old_id FROM to_del);
DELETE FROM account_project_watches WHERE account_id IN (SELECT old_id FROM to_del);
DELETE FROM account_ssh_keys WHERE account_id IN (SELECT old_id FROM to_del);
DELETE FROM accounts WHERE account_id IN (SELECT old_id FROM to_del);
DELETE FROM starred_changes WHERE account_id IN (SELECT old_id FROM to_del);
DELETE FROM change_approvals WHERE account_id IN (SELECT old_id FROM to_del);
COMMIT;