#!/bin/bash # # This script removes dangling rows from the database, for example 'trace' # entries with a variant_id not mentioned in the 'variants' table, or result # rows referencing a nonexistent 'fsppilot' entry. IOW, this script enforces # referential integrity as it would be maintained by foreign key constraints # (that can only be used with InnoDB tables). # if [ -z "$1" -o -z "$2" ] then echo "usage: $0 dbname resulttable" >&2 exit 1 fi DB=$1 RESULT=$2 MYSQL=mysql function table_exists() { N=$(echo "SHOW TABLES LIKE '$1'" | $MYSQL $DB | wc -l) [ $N -gt 0 ] return } if table_exists trace then echo -n "removing widowed entries in trace ..." echo " "$( $MYSQL $DB <