]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/update_postgresql_tables.in
Remove old bdb files + change DQUEUE to use dlist
[bacula/bacula] / bacula / src / cats / update_postgresql_tables.in
1 #!/bin/sh
2 #
3 # Shell script to update PostgreSQL tables from version 11 to 12
4 #
5 echo " "
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"
9 echo " "
10
11 bindir=@SQL_BINDIR@
12 PATH="$bindir:$PATH"
13 db_name=@db_name@
14
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;
25 COMMIT;
26
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';
35 COMMIT;
36
37 BEGIN; -- Can already exists if using 3.1.x release
38 CREATE TABLE PathHierarchy
39 (
40      PathId integer NOT NULL,
41      PPathId integer NOT NULL,
42      CONSTRAINT pathhierarchy_pkey PRIMARY KEY (PathId)
43 );
44
45 CREATE INDEX pathhierarchy_ppathid 
46           ON PathHierarchy (PPathId);
47
48 CREATE TABLE PathVisibility
49 (
50       PathId integer NOT NULL,
51       JobId integer NOT NULL,
52       Size int8 DEFAULT 0,
53       Files int4 DEFAULT 0,
54       CONSTRAINT pathvisibility_pkey PRIMARY KEY (JobId, PathId)
55 );
56
57 CREATE INDEX pathvisibility_jobid
58           ON PathVisibility (JobId);
59
60 COMMIT;
61
62 CREATE INDEX basefiles_jobid_idx ON BaseFiles ( JobId );
63
64 -- Remove bad PostgreSQL index
65 DROP INDEX file_fp_idx;
66
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)
71
72 CREATE INDEX file_jpfid_idx on File (JobId, PathId, FilenameId);
73
74 ANALYSE;
75
76 END-OF-DATA
77 then
78    echo "Update of Bacula PostgreSQL tables succeeded."
79 else
80    echo "Update of Bacula PostgreSQL tables failed."
81 fi
82 exit 0