78 |
open(DUMP,"$dump") || die "can't open dump file $dump"; |
open(DUMP,"$dump") || die "can't open dump file $dump"; |
79 |
|
|
80 |
while(<DUMP>) { |
while(<DUMP>) { |
81 |
chomp; |
chomp; s/\r//g; |
82 |
print "Processing line: $_\n" if $DEBUG; |
print "Processing line: $_\n" if $DEBUG; |
83 |
|
|
84 |
# nuke comments or empty lines |
# nuke comments or empty lines |
91 |
|
|
92 |
if ($create) { # are we inside create table? |
if ($create) { # are we inside create table? |
93 |
|
|
|
# FIX: nuke keys |
|
|
next if (/^\s+key/i && !/^\s+primary key/i); |
|
|
|
|
94 |
# int,auto_increment -> serial |
# int,auto_increment -> serial |
95 |
if (/int.*auto_increment/i) { |
if (/int.*auto_increment/i) { |
96 |
|
|
97 |
|
|
98 |
# this was simple solution, but squence isn't |
# this was simple solution, but squence isn't |
99 |
# initialized correctly so I have to do a work-around |
# initialized correctly so I have to do a work-around |
100 |
# |
# |
103 |
if (/^\s*(\w+)\s+/) { |
if (/^\s*(\w+)\s+/) { |
104 |
$seq="${table}_${1}_seq"; |
$seq="${table}_${1}_seq"; |
105 |
push @sequences,"$table.$1"; |
push @sequences,"$table.$1"; |
106 |
s/(\w+) \w*int.*auto_increment/$1 int4 default nextval('$seq') not null/ig; |
s/(\s+)\w*int.*auto_increment[^,]*/$1int4 default nextval('$seq') not null/ig; |
107 |
} else { |
} else { |
108 |
die "can't get name of field!"; |
die "can't get name of field!"; |
109 |
} |
} |
159 |
# FIX: unique for multipe columns (col1,col2) are unsupported! |
# FIX: unique for multipe columns (col1,col2) are unsupported! |
160 |
next if (/unique/i); |
next if (/unique/i); |
161 |
|
|
162 |
|
# FIX: nuke keys |
163 |
|
next if (/^\s+key/i && !/^\s+primary key/i); |
164 |
|
|
165 |
# quote column names |
# quote column names |
166 |
s/(^\s*)(\S+)(\s*)/$1"$2"$3/gi if (!/key/i); |
s/(^\s*)(\S+)(\s*)/$1"$2"$3/gi if (!/key/i); |
167 |
|
|