#!/usr/bin/perl

use warnings;
use strict;

while (<>) {
    s/\[([^]]+)\]/"$1"/g;
    s/^\s*GO\s*$/;/;
    s/tinyint/smallint/;
    s/binary(?:\s*\([^)]+\))?/bytea/ig;
    s/smalldatetime/TIMESTAMP/ig;
    s/DATETIME/TIMESTAMP/ig;
    s/(?:NON)?CLUSTERED//g;
    s/int\s*IDENTITY\s*\(\d+,\s*\d+\)/SERIAL/ig;
    # mssql uses stupid names for indexes apparently; ditch them and
    # let pgsql choose
    s/(CREATE\s+(?:UNIQUE\s+)?INDEX\s+)\S+\s+(ON\s+)/$1$2/gi;
    print $_;
}
