moved removal of orphaned records into their own functions and after the
loop.
This commit is contained in:
parent
dbd472cac6
commit
71e2f16454
|
@ -21,8 +21,15 @@ for my $session (@ARGV) {
|
||||||
print "deleting session $session\n";
|
print "deleting session $session\n";
|
||||||
my $n_instances = $dbh->do("delete from instances where session=?", {}, $session);
|
my $n_instances = $dbh->do("delete from instances where session=?", {}, $session);
|
||||||
print "\t$n_instances instances deleted\n";
|
print "\t$n_instances instances deleted\n";
|
||||||
|
$dbh->commit();
|
||||||
|
}
|
||||||
|
remove_orphaned_sessions();
|
||||||
|
remove_orphaned_files();
|
||||||
|
remove_orphaned_versions();
|
||||||
|
$dbh->disconnect();
|
||||||
|
exit();
|
||||||
|
|
||||||
# remove orphaned records:
|
sub remove_orphaned_sessions {
|
||||||
my $sessions
|
my $sessions
|
||||||
= $dbh->selectcol_arrayref(
|
= $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}
|
q{select s.id from instances i right outer join sessions s on i.session=s.id where i.id is null}
|
||||||
|
@ -32,7 +39,10 @@ for my $session (@ARGV) {
|
||||||
$dbh->do(q{delete from sessions where id=?}, {}, $session);
|
$dbh->do(q{delete from sessions where id=?}, {}, $session);
|
||||||
print "\tsession $session deleted\n";
|
print "\tsession $session deleted\n";
|
||||||
}
|
}
|
||||||
|
$dbh->commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
sub remove_orphaned_files {
|
||||||
my $files
|
my $files
|
||||||
= $dbh->selectcol_arrayref(
|
= $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}
|
q{select f.id from instances i right outer join files f on i.file=f.id where i.id is null}
|
||||||
|
@ -42,7 +52,10 @@ for my $session (@ARGV) {
|
||||||
$dbh->do(q{delete from files where id=?}, {}, $file);
|
$dbh->do(q{delete from files where id=?}, {}, $file);
|
||||||
print "\tfile $file deleted\n";
|
print "\tfile $file deleted\n";
|
||||||
}
|
}
|
||||||
|
$dbh->commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
sub remove_orphaned_versions {
|
||||||
my $versions
|
my $versions
|
||||||
= $dbh->selectcol_arrayref(
|
= $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}
|
q{select v.id from instances i right outer join versions2 v on i.version=v.id where i.id is null}
|
||||||
|
@ -54,4 +67,3 @@ for my $session (@ARGV) {
|
||||||
}
|
}
|
||||||
$dbh->commit();
|
$dbh->commit();
|
||||||
}
|
}
|
||||||
$dbh->disconnect();
|
|
||||||
|
|
Loading…
Reference in New Issue