]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/update_postgresql_tables.in
Add BDB_VERSION for scripts + prepare update 11 to 12 + automate BDB_VERSION checking
[bacula/bacula] / bacula / src / cats / update_postgresql_tables.in
1 #!/bin/sh
2 #
3 # Shell script to update MySQL tables from Bacula Community version 3.0.x to 5.0.0
4 #
5 echo " "
6 echo "This script will update a Bacula MySQL database from version 11 to 12"
7 echo "  which is needed to convert from Bacula Community version 3.0.x to 5.0.x"
8 echo " "
9
10 bindir=@SQL_BINDIR@
11 PATH="$bindir:$PATH"
12 db_name=@db_name@
13
14 DBVERSION=`psql ${db_name} -t --pset format=unaligned -c "select VersionId from Version"`
15 if [ $DBVERSION != 11 ] ; then
16    echo " "
17    echo "The existing database is version $DBVERSION !!"
18    echo "This script can only update an existing version 11 database to version 12."
19    echo "Error. Cannot upgrade this database."
20    echo " "
21    exit 1
22 fi
23
24 if psql -f - -d ${db_name} $* <<END-OF-DATA
25 BEGIN; -- Necessary for Bacula core
26 ALTER TABLE JobMedia DROP Copy ;
27 ALTER TABLE Job ADD COLUMN HasCache smallint default 0;
28 ALTER TABLE Job ADD COLUMN Reviewed smallint default 0;
29 ALTER TABLE Job ADD COLUMN Comment text;
30 ALTER TABLE JobHisto ADD COLUMN HasCache smallint default 0;
31 ALTER TABLE JobHisto ADD COLUMN Reviewed smallint default 0;
32 ALTER TABLE JobHisto ADD COLUMN Comment text;
33 UPDATE Version SET VersionId=12;
34 COMMIT;
35
36 BEGIN; -- Can conflict with previous Bweb installation
37 ALTER TABLE Status ADD COLUMN Severity int;
38 UPDATE Status SET Severity = 15;
39 UPDATE Status SET Severity = 100 where JobStatus = 'f';
40 UPDATE Status SET Severity = 90 where JobStatus = 'A';
41 UPDATE Status SET Severity = 10 where JobStatus = 'T';
42 UPDATE Status SET Severity = 20 where JobStatus = 'e';
43 UPDATE Status SET Severity = 25 where JobStatus = 'E';
44 COMMIT;
45
46 BEGIN; -- Can already exists if using 3.1.x release
47 CREATE TABLE PathHierarchy
48 (
49      PathId integer NOT NULL,
50      PPathId integer NOT NULL,
51      CONSTRAINT pathhierarchy_pkey PRIMARY KEY (PathId)
52 );
53
54 CREATE INDEX pathhierarchy_ppathid 
55           ON PathHierarchy (PPathId);
56
57 CREATE TABLE PathVisibility
58 (
59       PathId integer NOT NULL,
60       JobId integer NOT NULL,
61       Size int8 DEFAULT 0,
62       Files int4 DEFAULT 0,
63       CONSTRAINT pathvisibility_pkey PRIMARY KEY (JobId, PathId)
64 );
65
66 CREATE INDEX pathvisibility_jobid
67           ON PathVisibility (JobId);
68
69 COMMIT;
70
71 CREATE INDEX basefiles_jobid_idx ON BaseFiles ( JobId );
72
73 -- Remove bad PostgreSQL index
74 DROP INDEX file_fp_idx;
75
76 -- Create the good one
77 -- If you want to create this index during production, you can use 
78 -- CREATE INDEX CONCURRENTLY file_jpf_idx ON File (JobId, PathId, FilenameId)
79 -- to make it without locks (require PostgreSQL 8.2 version)
80
81 CREATE INDEX file_jpfid_idx on File (JobId, PathId, FilenameId);
82
83 ANALYSE;
84
85 UPDATE Version SET VersionId=12;
86
87 END-OF-DATA
88 then
89    echo "Update of Bacula PostgreSQL tables succeeded."
90 else
91    echo "Update of Bacula PostgreSQL tables failed."
92 fi
93 exit 0