Project

General

Profile

1
#!/bin/sh
2
# Translates a MySQL DB export to PostgreSQL
3
# The export must be created with:
4
# `--compatible=postgresql --add-locks=false --set-charset`
5
# Usage: self {input...|<input} >translated
6

    
7
sedEreFlag="$(test "$(uname)" = Darwin && echo E || echo r)"
8

    
9
sed () { "$(which sed)" -"$sedEreFlag" "$@";}
10

    
11
sed \
12
-e 's/^  KEY "([^"]*)" \([^)]*\)/  "\1_index" boolean/' \
13
-e "s/\/\*.* (SET NAMES )([0-9A-Za-z_]+) \*\/;/\1'\2';/" \
14
-e 's/ longtext/ text/g' \
15
-e 's/ (int|smallint|tinyint)([ (])/ integer\2/g' \
16
-e 's/ double/ double precision/g' \
17
-e 's/ (integer|double precision|float)(\([^)]*\))?( unsigned)?/ \1/g' \
18
"$@"
(32-32/57)