Created
June 21, 2021 05:55
-
-
Save lucleray/dc6825241cf03a0011853c7926291093 to your computer and use it in GitHub Desktop.
Create a migration file by reading local changes made to db/create-tables.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
slugify='node_modules/.bin/slugify' | |
git show HEAD:db/create-tables.sql > db/tmporigin.sql | |
cp db/create-tables.sql db/tmpnew.sql | |
today="$(date -u +'%Y%m%d%H%M')" | |
file_name="db/migrations/$($slugify "$today $1").sql" | |
file_content=$(apgdiff --add-defaults db/tmporigin.sql db/tmpnew.sql) | |
if [[ -z "$file_content" ]]; then | |
echo "⚠️ No migration detected" | |
else | |
echo $file_content > $file_name | |
echo "🖍 Created ${file_name}" | |
fi | |
rm db/tmpnew.sql db/tmporigin.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to install:
apgdiff
slugify-cli
, installed in the folder's npm packages