File size: 1,320 Bytes
2a2189c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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
    }
}