USE bacula;

ALTER TABLE Media ADD COLUMN MediaTypeId INTEGER UNSIGNED DEFAULT 0 REFERENCES MediaType;
ALTER TABLE Media ADD COLUMN DeviceId INTEGER UNSIGNED DEFAULT 0 REFERENCES Device;
ALTER TABLE Media ADD COLUMN LocationId INTEGER UNSIGNED DEFAULT 0 REFERENCES Location;
ALTER TABLE Media ADD COLUMN RecycleCount INTEGER UNSIGNED DEFAULT 0;
ALTER TABLE Media ADD COLUMN InitialWrite DATETIME DEFAULT 0;
ALTER TABLE Media ADD COLUMN ScratchPoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool;
ALTER TABLE Media ADD COLUMN RecyclePoolId INTEGER UNSIGNED DEFAULT 0 REFERENCES Pool;


CREATE TABLE MAC (
   JobId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
   OriginalJobId INTEGER UNSIGNED NOT NULL,
   JobType BINARY(1) NOT NULL,
   JobLevel BINARY(1) NOT NULL,
   SchedTime DATETIME NOT NULL,
   StartTime DATETIME NOT NULL,
   EndTime DATETIME NOT NULL,
   JobTDate BIGINT UNSIGNED NOT NULL,
   PRIMARY KEY(JobId)
   );

CREATE TABLE Location (
   LocationId INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
   Location TINYBLOB NOT NULL,
   PRIMARY KEY(LocationId)
   );


DELETE FROM Version;
INSERT INTO Version (VersionId) VALUES (9);
