39 |
return( ( sprintf("dbi:Pg:dbname=%s;host=%s", $db_name, $db_host), |
return( ( sprintf("dbi:Pg:dbname=%s;host=%s", $db_name, $db_host), |
40 |
$user, $password, { 'RaiseError' => 1 } ) ); |
$user, $password, { 'RaiseError' => 1 } ) ); |
41 |
}, |
}, |
42 |
'delay' => sub { system('sync'); select(undef, undef, undef, 0.005) }, |
'delay' => sub { system('sync'); select(undef, undef, undef, 0.5) }, |
43 |
|
'delay' => sub { }, |
44 |
'datatypes' => {}, |
'datatypes' => {}, |
45 |
'relational' => sub { |
'relational' => sub { |
46 |
my $table = shift; |
my $table = shift; |
149 |
} |
} |
150 |
else |
else |
151 |
{ |
{ |
152 |
|
if ($r =~ /^_start_t\s/) |
153 |
|
{ |
154 |
|
$r .= ' NOT NULL'; |
155 |
|
} |
156 |
push @r, $r; |
push @r, $r; |
157 |
} |
} |
158 |
} |
} |
166 |
$type = ($type eq 'bigserial') ? 'bigint' : 'int'; |
$type = ($type eq 'bigserial') ? 'bigint' : 'int'; |
167 |
$type = $config{$db_conf}{'datatypes'}{lc $type} || $type; |
$type = $config{$db_conf}{'datatypes'}{lc $type} || $type; |
168 |
|
|
169 |
|
if ($rel eq '_table') |
170 |
|
{ |
171 |
|
$type .= " NOT NULL"; |
172 |
|
} |
173 |
|
|
174 |
push @r, "$rel $type"; |
push @r, "$rel $type"; |
175 |
} |
} |
176 |
|
|
177 |
my $sql = "CREATE TABLE $table (\n" . join(",\n", map(" $_", @r)) . "\n);\n"; |
my $sql = "CREATE TABLE $table (\n" . join(",\n", map(" $_", @r)) . "\n);\n"; |
178 |
|
|
179 |
print $sql if $db_conf ne 'stdout'; |
print STDERR $sql; |
180 |
$db->do( $sql ); |
$db->do( $sql ); |
181 |
$config{$db_conf}{'delay'}->(); |
$config{$db_conf}{'delay'}->(); |
182 |
} |
} |
197 |
{ |
{ |
198 |
$sql = $config{$db_conf}{'relational'}->($table, $rel, $structure{$table}{REL}{$rel}); |
$sql = $config{$db_conf}{'relational'}->($table, $rel, $structure{$table}{REL}{$rel}); |
199 |
} |
} |
200 |
print $sql if $db_conf ne 'stdout'; |
print STDERR $sql; |
201 |
$db->do($sql); |
$db->do($sql); |
202 |
$config{$db_conf}{'delay'}->(); |
$config{$db_conf}{'delay'}->(); |
203 |
} |
} |