Skip to content

Instantly share code, notes, and snippets.

@CNBorn
Created March 5, 2010 03:41
Show Gist options
  • Save CNBorn/322430 to your computer and use it in GitHub Desktop.
Save CNBorn/322430 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# A bash Script to migrate Sqlite3 DB when Django Model Schema changes.
# It will only migrate tables whose Schema unchanged.
# cp this script to your Django Project Directory,
# then run as sqlitemig.sh yoursqlitedbname.db
# Written by CNBorn[%]hotmail.com
#echo $1
if test ! -f "$1"
then
echo "no such file $1"
exit 1
fi
savedate=$(date +%Y-%m-%d-%H%M%S)
#echo $savedate
backupdb=$savedate"_"$1
#echo $backupdb
tmptxtfile=$savedate"_"txtdump.tmp
python manage.py validate
sqlite3 $1 .dump > $tmptxtfile
cp $1 $backupdb
rm $1
python manage.py syncdb
sqlite3 $1 ".read $tmptxtfile"
rm $tmptxtfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment