Files
moonwell-core-vanilla/sql/touch_migration.sh
T
Michael Serajnik baa6ff835c Use bash shebang in touch_migration.sh. (#2286)
Without it, at least on macOS it seems like it defaults to using sh, which
causes the `-e` flag of `echo` to not be interpreted and instead prepended to
the created migration file.
2023-11-16 18:56:23 +02:00

14 lines
619 B
Bash
Executable File

#!/usr/bin/env bash
DATE=`date +%Y%m%d%H%M%S`
FPATH=migrations/"$DATE"_world.sql
touch "$FPATH"
if [ -e "$FPATH" ]; then
echo -e "DROP PROCEDURE IF EXISTS add_migration;\r\ndelimiter ??\r\nCREATE PROCEDURE \`add_migration\`()\r\nBEGIN\r\nDECLARE v INT DEFAULT 1;\r\nSET v = (SELECT COUNT(*) FROM \`migrations\` WHERE \`id\`='$DATE');\r\nIF v=0 THEN\r\nINSERT INTO \`migrations\` VALUES ('$DATE');\r\n-- Add your query below.\r\n\r\n\r\n\r\n-- End of migration.\r\nEND IF;\r\nEND??\r\ndelimiter ; \r\nCALL add_migration();\r\nDROP PROCEDURE IF EXISTS add_migration;" > $FPATH
else
echo "FAILED to create file"
fi