Script that exports your database schema to files that are included in your git history This is in the server repository
- Create a folder in your root directory called "databaseSchema"
- In that folder create an executable file "export-db-schema.sh"
File Contents
#!/bin/bash
GIT_MYSQL=./schema
DATABASE_NAME=frasset_data
for T in `mysql -u export -p123 -N -B -e 'show tables from <database-name>'`;
do
echo "Backing up $T"
# mysqldump --skip-comments --compact -u <username> -p<password> <database-name> $T > $GIT_MYSQL/$T.sql
mysqldump --skip-comments --no-data --skip-add-drop-table -u <username> -p<password> frasset_data $T | sed 's/ AUTO_INCREMENT=[0-9]*//g' > $GIT_MYSQL/tables/$T.sql
done;
mysqldump --no-data --skip-add-drop-table -u <username> -p<password> <database-name> | sed 's/ AUTO_INCREMENT=[0-9]*//g' > $GIT_MYSQL/<database-name>_schema-all-tables.sql
-
Replace in the script file
-
Create a sub folder "databaseSchema/schema"
-
Create a sub folder "databaseSchema/schema/tables"
-
In your package.json add this script:
"export-db-schema": "cd databaseSchema && ./export-db-schema.sh"