30 |
$out->{index}->{$2}->{$table} = $1; |
$out->{index}->{$2}->{$table} = $1; |
31 |
} |
} |
32 |
|
|
33 |
if (/\s*inherits\s*\(\s*(\S+)\s*\)/) { |
if (/\s*inherits\s*\(\s*(\S+)\s*\)/i) { |
34 |
$out->{inherits}->{$table} = $1; |
$out->{inherits}->{$table} = $1; |
35 |
} |
} |
36 |
|
|
37 |
if (s/^\s*(\S+)(.+?)references\s+(\S+)\s*\((\S+)\)/$1$2/i) { |
if (s/^\s*(\S+)(.+?)references\s+(\S+)\s*\((\S+)\)([^,]*)([,\s]*)$/\t$1$2$6/i) { |
38 |
@{ $out->{references}->{$table}->{$1} } = ( $3, $4 ); |
# if (/^\s*(\S+)(.+?)references\s+(\S+)\s*\((\S+)\)/) { |
39 |
|
@{ $out->{references}->{$table}->{$1} } = ( $3, $4, $5 ); |
40 |
} |
} |
41 |
|
|
42 |
print "$_\n"; |
print "$_\n"; |
47 |
print STDERR Dumper($out); |
print STDERR Dumper($out); |
48 |
|
|
49 |
foreach my $table (keys %{ $out->{inherits} }) { |
foreach my $table (keys %{ $out->{inherits} }) { |
50 |
my $parent = $out->{inherits}->{$table} || die; |
my $parent = $out->{inherits}->{$table} || die "$table doesn't inherit anything"; |
51 |
my $pk = $out->{table_pk}->{$parent} || die; |
my $pk = $out->{table_pk}->{$parent} || die "$parent doesn't have primary key"; |
52 |
my $seq = $parent . '_' . $pk . '_seq'; |
my $seq = $parent . '_' . $pk . '_seq'; |
53 |
print qq{alter table $table alter column $pk set default nextval('$seq');\n}; |
print qq{alter table $table alter column $pk set default nextval('$seq');\n}; |
54 |
} |
} |
77 |
END IF; |
END IF; |
78 |
END; |
END; |
79 |
\$\$ language 'plpgsql'; |
\$\$ language 'plpgsql'; |
80 |
|
CREATE TRIGGER $func BEFORE INSERT ON $table FOR EACH ROW EXECUTE PROCEDURE $func(); |
81 |
}; |
}; |
82 |
} |
} |
83 |
} |
} |