summaryrefslogtreecommitdiffstats
path: root/gerrit1_import/1-to-2.sh
blob: 6eba78d876e57c85ec5d24e267efbbb6666d83f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/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"