mycelium / scripts /sanitize_blank_bootstrap.awk
alm108's picture
Add verified blank-instance schema bootstrap
2a2189c
Raw History Blame Contribute Delete
1.32 kB
# Convert a plain-text pg_dump into a portable, data-free structural bootstrap.
#
# The source is allowed to contain schema plus COPY data because this filter
# treats every data-bearing statement as untrusted. The wrapper performs
# input-hash and output invariant checks before replacing the destination.
function emit(line) {
if (line == "") {
pending_blank_lines++
return
}
while (pending_blank_lines > 0) {
print ""
pending_blank_lines--
}
print line
}
BEGIN {
in_copy = 0
pending_blank_lines = 0
print "-- Portable Mycelium structural bootstrap."
print "-- Generated mechanically from the verified source dump; contains no graph records."
print "-- Structural schema is not a declaration of canonical semantic ontology."
print ""
}
{
sub(/\r$/, "")
sub(/[ \t]+$/, "")
}
in_copy {
if ($0 == "\\.") {
in_copy = 0
}
next
}
/^COPY / {
in_copy = 1
next
}
/^\\(un)?restrict / { next }
/^ALTER .* OWNER TO [^;]+;$/ { next }
/^SELECT pg_catalog\.setval\(/ { next }
/^-- Data for Name:/ { next }
/^-- Name: .*; Type: TABLE DATA;/ { next }
/^-- Name: .*; Type: SEQUENCE SET;/ { next }
{ emit($0) }
END {
if (in_copy) {
print "unterminated COPY block" > "/dev/stderr"
exit 65
}
}