]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/cats/update_postgresql_tables.in
Fix syntax of renaming postgresql per Dan.
[bacula/bacula] / bacula / src / cats / update_postgresql_tables.in
1 #!/bin/sh
2 #
3 # Shell script to update PostgreSQL tables from version 1.34 to 1.35.5
4 #
5 echo " "
6 echo "This script will update a Bacula PostgreSQL database from version 7 to 8"
7 echo "Depending on the size of your database,"
8 echo "this script may take several minutes to run."
9 echo " "
10 bindir=@SQL_BINDIR@
11
12 if $bindir/psql $* -f - <<END-OF-DATA
13 \c bacula
14
15 ALTER TABLE media ADD COLUMN EndFile integer;
16 UPDATE media SET EndFile=0;
17 ALTER TABLE media ALTER COLUMN EndFile SET NOT NULL;
18 ALTER TABLE media ADD COLUMN EndBlock integer;
19 UPDATE media SET EndBlock=0;
20 ALTER TABLE media ALTER COLUMN EndBlock SET NOT NULL;
21
22 UPDATE Filename SET Name='' WHERE Name=' ';
23
24 alter table file rename column filenameid to filenameidold;
25 alter table file add column filenameid integer;
26 update file set filenameid = filenameidold;
27 alter table file alter column filenameid set not null;
28 alter table file drop column filenameidold;
29
30 DELETE FROM Version;
31 INSERT INTO Version (VersionId) VALUES (8);
32
33 create index file_jobid_idx on file (jobid);
34 create index file_pathid_idx on file(pathid);
35 create index file_filenameid_idx on file(filenameid);
36 create index file_jpfid_idx on file (jobid, pathid, filenameid);
37
38 create table CDImages 
39 (
40    MediaId integer not null,
41    LastBurn timestamp without time zone not null,
42    primary key (MediaId)
43 );
44
45 vacuum;
46
47 END-OF-DATA
48 then
49    echo "Update of Bacula PostgreSQL tables succeeded."
50 else
51    echo "Update of Bacula PostgreSQL tables failed."
52 fi
53 exit 0