Skip to content

Instantly share code, notes, and snippets.

@markusfisch
Last active June 29, 2019 01:01
Show Gist options
  • Save markusfisch/889657 to your computer and use it in GitHub Desktop.
Save markusfisch/889657 to your computer and use it in GitHub Desktop.
Makefile to generate create/drop/recreate scripts from a bunch of SQL files
CREATE=create.sql
DROP=drop.sql
RECREATE=recreate.sql
all: recreate
recreate: clean create drop
cat $(DROP) $(CREATE) > $(RECREATE)
create:
rm -f $(CREATE)
grep -Evh "^[ ]*[/*]+" *.sql > $(CREATE)
drop:
egrep "(CREATE TABLE)" $(CREATE) | tac | \
sed -e "s_CREATE_DROP_g;s_\$$_;_g" > $(DROP)
clean:
rm -f $(CREATE) $(DROP) $(RECREATE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment