]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/cats/update_postgresql_tables.in
Fix open of SQLite3 db where user does not have write permission
[bacula/bacula] / bacula / src / cats / update_postgresql_tables.in
index 8739ffce6ae34518d09d433d5226559973c5c5d2..e6149ae54d9c276649f25c9d49b91a3b12fa65bf 100755 (executable)
@@ -1,46 +1,76 @@
 #!/bin/sh
 #
-# Shell script to update PostgreSQL tables from version 1.34 to 1.35.5
+# Shell script to update PostgreSQL tables from version 1.38 to 2.0.0 or higher
 #
 echo " "
-echo "This script will update a Bacula PostgreSQL database from version 7 to 8"
+echo "This script will update a Bacula PostgreSQL database from version 9 to 10"
+echo " which is needed to convert from Bacula version 1.38.x to 2.0.0 or higher"
 echo "Depending on the size of your database,"
 echo "this script may take several minutes to run."
 echo " "
 bindir=@SQL_BINDIR@
 
-if $bindir/psql $* -f - <<END-OF-DATA
-\c bacula
+if $bindir/psql -f - -d bacula $* <<END-OF-DATA
 
-ALTER TABLE media ADD COLUMN EndFile integer;
-UPDATE media SET EndFile=0;
-ALTER TABLE media ALTER COLUMN EndFile SET NOT NULL;
-ALTER TABLE media ADD COLUMN EndBlock integer;
-UPDATE media SET EndBlock=0;
-ALTER TABLE media ALTER COLUMN EndBlock SET NOT NULL;
+ALTER TABLE media ADD COLUMN DeviceId integer;
+UPDATE media SET DeviceId=0;
+ALTER TABLE media ADD COLUMN MediaTypeId integer;
+UPDATE media SET MediaTypeId=0;
+ALTER TABLE media ADD COLUMN LocationId integer;
+UPDATE media SET LocationId=0;
+ALTER TABLE media ADD COLUMN RecycleCount integer;
+UPDATE media SET RecycleCount=0;
+ALTER TABLE media ADD COLUMN InitialWrite timestamp without time zone;
+ALTER TABLE media ADD COLUMN scratchpoolid integer;
+UPDATE media SET scratchpoolid=0;
+ALTER TABLE media ADD COLUMN recyclepoolid integer;
+UPDATE media SET recyclepoolid=0;
+ALTER TABLE media ADD COLUMN enabled integer;
+UPDATE media SET enabled=1;
+ALTER TABLE media ADD COLUMN Comment TEXT;
 
-UPDATE Filename SET Name='' WHERE Name=' ';
+ALTER TABLE job ADD COLUMN RealEndTime timestamp without time zone;
+ALTER TABLE job ADD COLUMN PriorJobId integer;
+UPDATE job SET PriorJobId=0;
 
-alter table file rename column filenameid to filenameidold;
-alter table file add column filenameid integer;
-update file set filenameid = filenameidold;
-alter table file alter column filenameid set not null;
-alter table file drop column filenameidold;
+ALTER TABLE jobmedia DROP COLUMN Stripe;
 
-DELETE FROM Version;
-INSERT INTO Version (VersionId) VALUES (8);
+CREATE TABLE Location (
+   LocationId SERIAL NOT NULL,
+   Location TEXT NOT NULL,
+   Cost integer default 0,
+   Enabled integer,
+   PRIMARY KEY (LocationId)
+);
+
+CREATE TABLE LocationLog (
+   LocLogId SERIAL NOT NULL,
+   Date timestamp   without time zone,
+   Comment TEXT NOT NULL,
+   MediaId INTEGER DEFAULT 0,
+   LocationId INTEGER DEFAULT 0,
+   newvolstatus text not null
+       check (newvolstatus in ('Full','Archive','Append',
+             'Recycle','Purged','Read-Only','Disabled',
+             'Error','Busy','Used','Cleaning','Scratch')),
+   newenabled smallint,
+   PRIMARY KEY(LocLogId)
+);
 
-create index file_jobid_idx on file (jobid);
-create index file_pathid_idx on file(pathid);
-create index file_filenameid_idx on file(filenameid);
-create index file_jpfid_idx on file (jobid, pathid, filenameid);
 
-create table CDImages 
+CREATE TABLE Log
 (
-   MediaId integer not null,
-   LastBurn timestamp without time zone not null,
-   primary key (MediaId)
+    LogId            serial      not null,
+    JobId            integer     not null,
+    Time             timestamp   without time zone,
+    LogText          text        not null,
+    primary key (LogId)
 );
+create index log_name_idx on Log (JobId);
+
+
+DELETE FROM version;
+INSERT INTO version (versionId) VALUES (10);
 
 vacuum;