3 # Shell script to update PostgreSQL tables from version 11 to 12
6 echo "This script will update a Bacula PostgreSQL database from version 11 to 12"
7 echo " which is needed to convert from Bacula Enterprise 2.6 to 4.0 or "
8 echo " Standard version 3.0 to 5.0"
15 if psql -f - -d ${db_name} $* <<END-OF-DATA
16 BEGIN; -- Necessary for Bacula core
17 ALTER TABLE JobMedia DROP Copy ;
18 ALTER TABLE Job ADD COLUMN HasCache smallint default 0;
19 ALTER TABLE Job ADD COLUMN Reviewed smallint default 0;
20 ALTER TABLE Job ADD COLUMN Comment text;
21 ALTER TABLE JobHisto ADD COLUMN HasCache smallint default 0;
22 ALTER TABLE JobHisto ADD COLUMN Reviewed smallint default 0;
23 ALTER TABLE JobHisto ADD COLUMN Comment text;
24 UPDATE Version SET VersionId=12;
27 BEGIN; -- Can conflict with previous Bweb installation
28 ALTER TABLE Status ADD COLUMN Severity int;
29 UPDATE Status SET Severity = 15;
30 UPDATE Status SET Severity = 100 where JobStatus = 'f';
31 UPDATE Status SET Severity = 90 where JobStatus = 'A';
32 UPDATE Status SET Severity = 10 where JobStatus = 'T';
33 UPDATE Status SET Severity = 20 where JobStatus = 'e';
34 UPDATE Status SET Severity = 25 where JobStatus = 'E';
37 BEGIN; -- Can already exists if using 3.1.x release
38 CREATE TABLE PathHierarchy
40 PathId integer NOT NULL,
41 PPathId integer NOT NULL,
42 CONSTRAINT pathhierarchy_pkey PRIMARY KEY (PathId)
45 CREATE INDEX pathhierarchy_ppathid
46 ON PathHierarchy (PPathId);
48 CREATE TABLE PathVisibility
50 PathId integer NOT NULL,
51 JobId integer NOT NULL,
54 CONSTRAINT pathvisibility_pkey PRIMARY KEY (JobId, PathId)
57 CREATE INDEX pathvisibility_jobid
58 ON PathVisibility (JobId);
62 CREATE INDEX basefiles_jobid_idx ON BaseFiles ( JobId );
64 -- Remove bad PostgreSQL index
65 DROP INDEX file_fp_idx;
67 -- Create the good one
68 -- If you want to create this index during production, you can use
69 -- CREATE INDEX CONCURRENTLY file_jpf_idx ON File (JobId, PathId, FilenameId)
70 -- to make it without locks (require PostgreSQL 8.2 version)
72 CREATE INDEX file_jpfid_idx on File (JobId, PathId, FilenameId);
78 echo "Update of Bacula PostgreSQL tables succeeded."
80 echo "Update of Bacula PostgreSQL tables failed."