From a3bc062952ca90e66ba2c66f1904de556b6872c6 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Sun, 7 Jun 2020 11:45:47 +0000 Subject: [PATCH] Added cleanout of local tables missing from db dump (assuming they have been created by migrations) and added new switches --no-load and --no-zap to docker/updatedb - Legacy-Id: 17924 --- docker/updatedb | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/docker/updatedb b/docker/updatedb index 569d86d57..af7bcdb30 100755 --- a/docker/updatedb +++ b/docker/updatedb @@ -1,4 +1,5 @@ #!/bin/bash +# -*- indent-with-tabs: 1 -*- version=0.10 program=${0##*/} @@ -69,11 +70,12 @@ trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; # Option parsing # Options -shortopts=DhqvV -longopts=no-download,help,quiet,verbose,version +shortopts=DLZhqvV +longopts=no-download,no-load,no-zap,help,quiet,verbose,version LOAD=1 DOWNLOAD=1 +DROP=1 QUIET="" if [ "$(uname)" = "Linux" ]; then @@ -91,12 +93,13 @@ fi while true ; do case "$1" in - -d| --download) LOAD="";; # Only download - -D| --no-download) DOWNLOAD="";; # Don't download, use existing file - -h| --help) usage; exit;; # Show this help, then exit - -q| --quiet) QUIET="-q";; # Don't show progress - -v| --verbose) VERBOSE=1;; # Be more talkative - -V| --version) version; exit;; # Show program version, then exit + -D| --no-download) DOWNLOAD="";; #Don't download, use existing file + -L| --no-load) LOAD=""; ;; # Don't load the database + -Z| --no-zap) DROP="";; # Don't drop new tables + -h| --help) usage; exit;; # Show this help, then exit + -q| --quiet) QUIET="-q";; # Don't show progress + -v| --verbose) VERBOSE=1;; # Be more talkative + -V| --version) version; exit;; # Show program version, then exit --) shift; break;; *) die "Internal error, inconsistent option specification: '$1'";; esac @@ -143,5 +146,13 @@ if [ "$LOAD" ]; then | sed -e 's/ENGINE=MyISAM/ENGINE=InnoDB/' \ | $parent/ietf/manage.py dbshell fi + fi +if [ "$DROP" ]; then + echo "Dropping tables not in the dump (so migrations can succeed) ..." + diff <(zcat $DATADIR/ietf_utf8.sql.gz | grep '^DROP TABLE IF EXISTS' | tr -d '`;' | field 5) \ + <($parent/ietf/manage.py dbshell <<< 'show tables;' | tail -n +2) \ + | grep '^>' | awk '{print "drop table if exists", $2, ";";}' \ + | tee /dev/stderr | $parent/ietf/manage.py dbshell +fi \ No newline at end of file