Skip to content

Instantly share code, notes, and snippets.

@lucleray
Created June 21, 2021 05:55
Show Gist options
  • Save lucleray/dc6825241cf03a0011853c7926291093 to your computer and use it in GitHub Desktop.
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
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
@lucleray
Copy link
Author

You need to install:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment