Skip to content

Commit

Permalink
Implement EXCLUDE constraint for PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
KES777 authored and rabbiveesh committed Dec 21, 2023
1 parent dee6a8d commit adc0035
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/SQL/Translator/Producer/PostgreSQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,15 @@ sub create_constraint

push @fks, "$def";
}
elsif( $c->type eq EXCLUDE ) {
my $using = $c->options->[0]{ using };
$using = $using ? "USING $using" : '';
my $expression = $c->expression;
my $where = $c->options->[0]{ where };
$where = $where ? "WHERE $where" : '';
push @constraint_defs, "$def_start EXCLUDE $using ( $expression ) $where";
}


return \@constraint_defs, \@fks;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/SQL/Translator/Schema/Constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ This module exports the following constants for Schema features;
=item UNIQUE
=item EXCLUDE
=back
=cut
Expand All @@ -55,6 +57,7 @@ our @EXPORT = qw[
NULL
PRIMARY_KEY
UNIQUE
EXCLUDE
];

#
Expand All @@ -78,6 +81,8 @@ use constant PRIMARY_KEY => 'PRIMARY KEY';

use constant UNIQUE => 'UNIQUE';

use constant EXCLUDE => 'EXCLUDE';

1;

=pod
Expand Down
1 change: 1 addition & 0 deletions lib/SQL/Translator/Schema/Constraint.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ my %VALID_CONSTRAINT_TYPE = (
CHECK_C, 1,
FOREIGN_KEY, 1,
NOT_NULL, 1,
EXCLUDE, 1,
);

=head2 new
Expand Down

0 comments on commit adc0035

Please sign in to comment.