Project

General

Profile

1 4426 aaronmk
#!/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 4463 aaronmk
echo 'SET standard_conforming_strings = off;'
12 5887 aaronmk
echo 'SET escape_string_warning = off;'
13 4426 aaronmk
sed \
14 6784 aaronmk
-e 's/^  ((UNIQUE|FULLTEXT) )?KEY "([^"]*)" \([^)]*\)/  "\3_index" boolean/' \
15 4426 aaronmk
-e "s/\/\*.* (SET NAMES )([0-9A-Za-z_]+) \*\/;/\1'\2';/" \
16 5885 aaronmk
-e 's/ CHARACTER SET [0-9A-Za-z_]+//g' \
17 6070 aaronmk
-e "s/ COMMENT '[^']*'//g" \
18 6785 aaronmk
-e 's/ blob/ bytea/g' \
19 4426 aaronmk
-e 's/ longtext/ text/g' \
20 6165 aaronmk
-e 's/ (int|mediumint|smallint|tinyint)([ (])/ integer\2/g' \
21 4426 aaronmk
-e 's/ double/ double precision/g' \
22 6309 aaronmk
-e 's/ (integer|bigint|double precision|float)(\([^)]*\))?( unsigned)?/ \1/g' \
23 4455 aaronmk
-e "s/'0000-00-00'/'-infinity'/g" \
24 4426 aaronmk
"$@"