3 # Copyright (C) 2000-2015 Kern Sibbald
4 # License: BSD 2-Clause; see file LICENSE-FOSS
6 # Shell script to update PostgreSQL tables from Bacula Community version 3.0.x to 5.0.0
9 echo "This script will update a Bacula PostgreSQL database from version 11 to 12"
10 echo " which is needed to convert from Bacula Community version 3.0.x to 5.0.x"
13 bindir=@POSTGRESQL_BINDIR@
15 db_name=${db_name:-@db_name@}
17 DBVERSION=`psql -d ${db_name} -t --pset format=unaligned -c "select VersionId from Version" $*`
18 if [ $DBVERSION != 11 ] ; then
20 echo "The existing database is version $DBVERSION !!"
21 echo "This script can only update an existing version 11 database to version 12."
22 echo "Error. Cannot upgrade this database."
27 if psql -f - -d ${db_name} $* <<END-OF-DATA
28 BEGIN; -- Necessary for Bacula core
29 ALTER TABLE JobMedia DROP Copy ;
30 ALTER TABLE Job ADD COLUMN HasCache smallint default 0;
31 ALTER TABLE Job ADD COLUMN Reviewed smallint default 0;
32 ALTER TABLE Job ADD COLUMN Comment text;
33 ALTER TABLE JobHisto ADD COLUMN HasCache smallint default 0;
34 ALTER TABLE JobHisto ADD COLUMN Reviewed smallint default 0;
35 ALTER TABLE JobHisto ADD COLUMN Comment text;
36 UPDATE Version SET VersionId=12;
39 BEGIN; -- Can conflict with previous Bweb installation
40 ALTER TABLE Status ADD COLUMN Severity int;
41 UPDATE Status SET Severity = 15;
42 UPDATE Status SET Severity = 100 where JobStatus = 'f';
43 UPDATE Status SET Severity = 90 where JobStatus = 'A';
44 UPDATE Status SET Severity = 10 where JobStatus = 'T';
45 UPDATE Status SET Severity = 20 where JobStatus = 'e';
46 UPDATE Status SET Severity = 25 where JobStatus = 'E';
49 BEGIN; -- Can already exists if using 3.1.x release
50 CREATE TABLE PathHierarchy
52 PathId integer NOT NULL,
53 PPathId integer NOT NULL,
54 CONSTRAINT pathhierarchy_pkey PRIMARY KEY (PathId)
57 CREATE INDEX pathhierarchy_ppathid
58 ON PathHierarchy (PPathId);
60 CREATE TABLE PathVisibility
62 PathId integer NOT NULL,
63 JobId integer NOT NULL,
66 CONSTRAINT pathvisibility_pkey PRIMARY KEY (JobId, PathId)
69 CREATE INDEX pathvisibility_jobid
70 ON PathVisibility (JobId);
74 CREATE INDEX basefiles_jobid_idx ON BaseFiles ( JobId );
76 -- suppress output for index modification
77 SET client_min_messages TO 'fatal';
79 -- Remove bad PostgreSQL index
80 DROP INDEX file_fp_idx;
82 -- Create the good one
83 -- If you want to create this index during production, you can use
84 -- CREATE INDEX CONCURRENTLY file_jpf_idx ON File (JobId, PathId, FilenameId)
85 -- to make it without locks (require PostgreSQL 8.2 version)
87 CREATE INDEX file_jpfid_idx on File (JobId, PathId, FilenameId);
90 SET client_min_messages TO DEFAULT;
96 echo "Update of Bacula PostgreSQL tables succeeded."
98 echo "Update of Bacula PostgreSQL tables failed."