create table status (
	drive_sn varchar(32),
	drive_vendor varchar(32),
	product_type varchar(32),
        firmware_version varchar(32),
	host varchar(32),
	logical_drive_name varchar(32),
	stat_type varchar(32),
	time timestamp without time zone,
	tape_volser varchar(32),
	power_hrs int,
	motion_hrs int,
	cleaning_bit int,
	mb_user_read int,
	mb_user_write int,
	mb_dev_read int,
	mb_dev_write int,
	read_errors int,
	write_errors int,
	track_retries int,
	underrun int,
	mount_count int,
	wp int
);

create index status_drive_sn_idx on status(drive_sn);
create index status_host_idx on status(host);
create index status_logical_drive_name on status(logical_drive_name);
create index status_product_type_idx on status(product_type);
create index status_stat_type_idx on status(stat_type);
create index status_tape_volser_idx on status(tape_volser);
create index status_time_idx on status(time);

create view drive_info as
select distinct on (logical_drive_name) logical_drive_name as drive,
	host, product_type as type, drive_vendor as vendor,
	drive_sn as sn, firmware_version as firmware
from status order by logical_drive_name, time desc;
