]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/update_postgresql_tables.in
Change DB version from 11 to 12
[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 export PATH="$bindir:$PATH"
13 db_name=@db_name@
14
15 if psql -f - -d ${db_name} $* <<END-OF-DATA
16 BEGIN;
17 ALTER TABLE JobMedia DROP Copy ;
18 ALTER TABLE Job ADD COLUMN HasCache smallint default 0;
19 ALTER TABLE Job ADD COLUMN Comment text;
20 ALTER TABLE JobHisto ADD COLUMN Comment text;
21 ALTER TABLE JobHisto ADD COLUMN HasCache smallint default 0;
22
23 ALTER TABLE Status ADD COLUMN Severity int;
24 UPDATE Status SET Severity = 15;
25 UPDATE Status SET Severity = 100 where JobStatus = 'f';
26 UPDATE Status SET Severity = 90 where JobStatus = 'A';
27 UPDATE Status SET Severity = 10 where JobStatus = 'T';
28 UPDATE Status SET Severity = 20 where JobStatus = 'e';
29 UPDATE Status SET Severity = 25 where JobStatus = 'E';
30
31 CREATE TABLE PathHierarchy
32 (
33      PathId integer NOT NULL,
34      PPathId integer NOT NULL,
35      CONSTRAINT pathhierarchy_pkey PRIMARY KEY (PathId)
36 );
37
38 CREATE INDEX pathhierarchy_ppathid 
39           ON PathHierarchy (PPathId);
40
41 CREATE TABLE PathVisibility
42 (
43       PathId integer NOT NULL,
44       JobId integer NOT NULL,
45       Size int8 DEFAULT 0,
46       Files int4 DEFAULT 0,
47       CONSTRAINT pathvisibility_pkey PRIMARY KEY (JobId, PathId)
48 );
49
50 CREATE INDEX pathvisibility_jobid
51           ON PathVisibility (JobId);
52
53
54 UPDATE Version SET VersionId=12;
55 COMMIT;
56
57 CREATE INDEX basefiles_jobid_idx ON BaseFiles ( JobId );
58
59 -- Remove bad PostgreSQL index
60 DROP INDEX file_fp_idx;
61
62 -- Create the good one
63 -- If you want to create this index during production, you can use 
64 -- CREATE INDEX CONCURRENTLY file_jpf_idx ON File (JobId, PathId, FilenameId)
65 -- to make it without locks (require PostgreSQL 8.2 version)
66
67 CREATE INDEX file_jpfid_idx on File (JobId, PathId, FilenameId);
68
69 ANALYSE;
70
71 END-OF-DATA
72 then
73    echo "Update of Bacula PostgreSQL tables succeeded."
74 else
75    echo "Update of Bacula PostgreSQL tables failed."
76 fi
77 exit 0