3 # Helper script to produce alter tables for inherited tables and
4 # indexes from source shema
11 my ($table, $inherit);
16 if (/create\s+table\s+(\S+)/i) {
22 if (/primary\s+key\s*\(\s*(\S+)\s*\)/i ) {
23 $out->{table_pk}->{$table} = $1;
25 if (/^\s*(\S+)\s*.+?--\s*((?:unique\s+)*index)/i) {
26 $out->{index}->{$2}->{$table} = $1;
29 if (/\s*inherits\s*\(\s*(\S+)\s*\)/) {
30 $out->{inherits}->{$table} = $1;
35 #print STDERR Dumper($out);
37 foreach my $table (keys %{ $out->{inherits} }) {
38 my $parent = $out->{inherits}->{$table} || die;
39 my $pk = $out->{table_pk}->{$parent} || die;
40 my $seq = $parent . '_' . $pk . '_seq';
41 print qq{alter table $table alter column $pk set default nextval('$seq');\n};
44 foreach my $type (keys %{ $out->{index} }) {
45 foreach my $table (keys %{ $out->{index}->{$type} }) {
46 my $f = $out->{index}->{$type}->{$table} || die;
47 my $i = $table . '_' . $f . '_ind';
48 print qq{create $type $i on $table($f);\n};