11#! /bin/bash
2+ # -*- indent-with-tabs: 1 -*-
23
34version=0.10
45program=${0##*/ }
@@ -69,11 +70,12 @@ trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)";
6970# Option parsing
7071
7172# Options
72- shortopts=DhqvV
73- longopts=no-download,help,quiet,verbose,version
73+ shortopts=DLZhqvV
74+ longopts=no-download,no-load,no-zap, help,quiet,verbose,version
7475
7576LOAD=1
7677DOWNLOAD=1
78+ DROP=1
7779QUIET=" "
7880
7981if [ " $( uname) " = " Linux" ]; then
9193
9294while true ; do
9395 case " $1 " in
94- -d| --download) LOAD=" " ;; # Only download
95- -D| --no-download) DOWNLOAD=" " ;; # Don't download, use existing file
96- -h| --help) usage; exit ;; # Show this help, then exit
97- -q| --quiet) QUIET=" -q" ;; # Don't show progress
98- -v| --verbose) VERBOSE=1;; # Be more talkative
99- -V| --version) version; exit ;; # Show program version, then exit
96+ -D| --no-download) DOWNLOAD=" " ;; # Don't download, use existing file
97+ -L| --no-load) LOAD=" " ; ;; # Don't load the database
98+ -Z| --no-zap) DROP=" " ;; # Don't drop new tables
99+ -h| --help) usage; exit ;; # Show this help, then exit
100+ -q| --quiet) QUIET=" -q" ;; # Don't show progress
101+ -v| --verbose) VERBOSE=1;; # Be more talkative
102+ -V| --version) version; exit ;; # Show program version, then exit
100103 --) shift ; break ;;
101104 * ) die " Internal error, inconsistent option specification: '$1 '" ;;
102105 esac
@@ -143,5 +146,13 @@ if [ "$LOAD" ]; then
143146 | sed -e ' s/ENGINE=MyISAM/ENGINE=InnoDB/' \
144147 | $parent /ietf/manage.py dbshell
145148 fi
149+
146150fi
147151
152+ if [ " $DROP " ]; then
153+ echo " Dropping tables not in the dump (so migrations can succeed) ..."
154+ diff <( zcat $DATADIR /ietf_utf8.sql.gz | grep ' ^DROP TABLE IF EXISTS' | tr -d ' `;' | field 5) \
155+ <( $parent /ietf/manage.py dbshell <<< ' show tables;' | tail -n +2) \
156+ | grep ' ^>' | awk ' {print "drop table if exists", $2, ";";}' \
157+ | tee /dev/stderr | $parent /ietf/manage.py dbshell
158+ fi
0 commit comments