Posts tagged with “version_control”

Database structure backup & Data dictionary automatically generation

Two bash script achieved the goals in this subject.

1. Exporting data dictionary

cat utils/exportDbDictionary 
if [ $# != 2 ] ; then
    echo "USAGE: $0 dbname tablename"
    echo " e.g.: $0 IDServer AspNetUsers"
    exit 1;


[ -d $document_path/$1 ] || mkdir -p $document_path/$1
mysqlshow $1 $2 | sed 's/+/|/g' | sed '1,2d' | sed '$d' | awk -F"[|]" '{print $2"|"$3"|"$5"|"$6"|"$7"|"$10}' | sed 's/ *$//g' > $document_path/$1/$

People should always add comments to their field definitions. As soon as the definition of a table has been done, run this script could automatically generate a markdown table with the name of

2. export database structure without auto_incrment= statements

cat utils/backupDbStructure 
mysqldump -d --databases YourDB1 YourDB2 YourDB3 | sed 's/ AUTO_INCREMENT=[0-9]*//g' > $backupFile

When you made some changes to your database, run backupDbStruture script will automatically generate the latest table structure into one file. You could commit it later with your code change together.