Skip to content

Commit

Permalink
fixed for multiple primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
tsucchi committed Jan 18, 2017
1 parent a18e066 commit a0b8b5d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/Otogiri/Plugin/TableInfo/Pg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ sub _is_sequence_column {

sub _build_pk_defs {
my ($self, $table) = @_;
my $result = "";
for my $column ( $table->primary_key() ) {
$result .= "ALTER TABLE ONLY " . $table->name . "\n";
$result .= " ADD CONSTRAINT " . $column->{PG_COLUMN} . " PRIMARY KEY (" . $column->name . ");\n";
my @pks = $table->primary_key();
my $result = '';
if ( @pks ) {
my @pk_names = map { $_->name } @pks;
$result = "ALTER TABLE ONLY " . $table->name . "\n";
$result .= " ADD CONSTRAINT " . $pks[0]->{PG_COLUMN} . " PRIMARY KEY (" . join(', ', @pk_names) . ");\n";
}
return $result;
}
Expand Down

0 comments on commit a0b8b5d

Please sign in to comment.