create index files_backupnum on files(backupnum) ;

-- cleanup, just in case
delete from files where (shareid,backupnum) not in (select shareid,num from backups) ;

create unique index backups_share_num on backups(shareid,num) ;
alter table files add foreign key (shareid,backupnum) references backups(shareid,num) on delete cascade;

