Project

General

Profile

1
#!/bin/sh
2
# Translates a PostgreSQL DB dump for the local server's version
3
# Usage: self {input...|<input} >translated
4

    
5
sedEreFlag="$(test "$(uname)" = Darwin && echo E || echo r)"
6

    
7
sed () { "$(which sed)" -"$sedEreFlag" "$@";}
8

    
9
pg_version="$(pg_dump --version|sed -n 's/^.* ([0-9]+).*$/\1/p')"
10
# PostgreSQL 9.x started putting plpgsql into template0, screwing everything up.
11
# We solve this by putting plpgsql in the dump so that versions before 9.x get
12
# it, and removing it when restoring to a 9.x server.
13
if test "$pg_version" -ge 9; then
14
    grep -v -F 'CREATE PROCEDURAL LANGUAGE plpgsql;' "$@"
15
else cat "$@" # pass through
16
fi
(8-8/49)