From 722715c01fe9fefd30d768da1f57a7838db14af3 Mon Sep 17 00:00:00 2001 From: Horst Schirmeier Date: Wed, 5 Nov 2014 17:20:27 +0100 Subject: [PATCH] fail-cleanup-db.sh: cleanup unused DB entries 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). Change-Id: I4dce1e46277d470f8c3eca31447ca71f63c6353f --- scripts/fail-cleanup-db.sh | 149 +++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100755 scripts/fail-cleanup-db.sh diff --git a/scripts/fail-cleanup-db.sh b/scripts/fail-cleanup-db.sh new file mode 100755 index 00000000..66ca12d9 --- /dev/null +++ b/scripts/fail-cleanup-db.sh @@ -0,0 +1,149 @@ +#!/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 <