70 lines
1.7 KiB
Perl
Executable File
70 lines
1.7 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
# This script removes all data associated with the given sessions.
|
|
# For each session it first removes all instances of that session and
|
|
# then cleans up any orphans.
|
|
|
|
use warnings;
|
|
use strict;
|
|
|
|
use Simba::CA;
|
|
|
|
$| = 1;
|
|
|
|
my $ca = Simba::CA->new({
|
|
dbi_file => $ENV{SIMBA_DB_CONN} || "$ENV{HOME}/.dbi/simba",
|
|
});
|
|
|
|
my $dbh = $ca->{dbh};
|
|
|
|
for my $session (@ARGV) {
|
|
print "deleting session $session\n";
|
|
my $n_instances = $dbh->do("delete from instances where session=?", {}, $session);
|
|
print "\t$n_instances instances deleted\n";
|
|
$dbh->commit();
|
|
}
|
|
remove_orphaned_sessions();
|
|
remove_orphaned_files();
|
|
remove_orphaned_versions();
|
|
$dbh->disconnect();
|
|
exit();
|
|
|
|
sub remove_orphaned_sessions {
|
|
my $sessions
|
|
= $dbh->selectcol_arrayref(
|
|
q{select s.id from instances i right outer join sessions s on i.session=s.id where i.id is null}
|
|
);
|
|
|
|
for my $session (@$sessions) {
|
|
$dbh->do(q{delete from sessions where id=?}, {}, $session);
|
|
print "\tsession $session deleted\n";
|
|
}
|
|
$dbh->commit();
|
|
}
|
|
|
|
sub remove_orphaned_files {
|
|
my $files
|
|
= $dbh->selectcol_arrayref(
|
|
q{select f.id from instances i right outer join files f on i.file=f.id where i.id is null}
|
|
);
|
|
|
|
for my $file (@$files) {
|
|
$dbh->do(q{delete from files where id=?}, {}, $file);
|
|
print "\tfile $file deleted\n";
|
|
}
|
|
$dbh->commit();
|
|
}
|
|
|
|
sub remove_orphaned_versions {
|
|
my $versions
|
|
= $dbh->selectcol_arrayref(
|
|
q{select v.id from instances i right outer join versions2 v on i.version=v.id where i.id is null}
|
|
);
|
|
|
|
for my $version (@$versions) {
|
|
$dbh->do(q{delete from versions2 where id=?}, {}, $version);
|
|
print "\tversion $version deleted\n";
|
|
}
|
|
$dbh->commit();
|
|
}
|