Skip to content

Commit b5a9d6f

Browse files
committed
Split the uninstall awk script out from the makefile
1 parent 01f773e commit b5a9d6f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Makefile

+1-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ uninstall.sql: install.sql
4242
echo "CONNECT TO $(DBNAME)!" > $@
4343
echo "SET SCHEMA $(SCHEMANAME)!" >> $@
4444
echo "SET PATH SYSTEM PATH, USER, $(SCHEMANAME)!" >> $@
45-
awk '\
46-
/^CREATE +(FUNCTION|PROCEDURE) +([A-Za-z0-9_#$$@]+)\>/ { routine=$$2; } \
47-
/^[[:space:]]*\<SPECIFIC +([A-Za-z0-9_#$$@]+)\>/ { print "DROP SPECIFIC " routine " " $$2 "!"; } \
48-
/^CREATE +(ALIAS|TABLE|VIEW|ROLE|TRIGGER) +([A-Za-z0-9_#$$@]+)\>/ { print "DROP " $$2 " " gensub("!$$", "", 1, $$3) "!"; }' $< | tac >> $@
45+
awk -f uninstall.awk $< | tac >> $@
4946
echo "COMMIT!" >> $@
5047

5148
export_load.foo: sql.foo

uninstall.awk

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# For routines, remember whether we're dealing with a function or procedure...
2+
/^CREATE +(FUNCTION|PROCEDURE) +([A-Za-z0-9_#$@]+)\>/ {
3+
routine=$2;
4+
}
5+
# ...then construct a DROP statement for the SPECIFIC name (must easier than
6+
# dealing with a routine prototype)
7+
/^[[:space:]]*\<SPECIFIC +([A-Za-z0-9_#$@]+)\>/ {
8+
print "DROP SPECIFIC " routine " " $2 "!";
9+
}
10+
11+
# Everything else just converts easily (we don't bother with indexes here as
12+
# they'll be dropped when the corresponding table is)
13+
/^CREATE +(ALIAS|TABLE|VIEW|ROLE|TRIGGER|VARIABLE) +([A-Za-z0-9_#$@]+)\>/ {
14+
print "DROP " $2 " " gensub("!$$", "", 1, $3) "!";
15+
}

0 commit comments

Comments
 (0)