From 4c5b21fbdc8782db4482080de5d451f6b3c74cbb Mon Sep 17 00:00:00 2001 From: Eugen Konkov Date: Sat, 21 Oct 2017 14:35:18 +0300 Subject: [PATCH] Implement EXCLUDE constraint for PostgreSQL --- lib/SQL/Translator/Producer/PostgreSQL.pm | 9 +++++++++ lib/SQL/Translator/Schema/Constants.pm | 5 +++++ lib/SQL/Translator/Schema/Constraint.pm | 1 + 3 files changed, 15 insertions(+) diff --git a/lib/SQL/Translator/Producer/PostgreSQL.pm b/lib/SQL/Translator/Producer/PostgreSQL.pm index 455f745df..b05f1ee11 100644 --- a/lib/SQL/Translator/Producer/PostgreSQL.pm +++ b/lib/SQL/Translator/Producer/PostgreSQL.pm @@ -601,6 +601,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; } diff --git a/lib/SQL/Translator/Schema/Constants.pm b/lib/SQL/Translator/Schema/Constants.pm index e56e0628f..032383e80 100644 --- a/lib/SQL/Translator/Schema/Constants.pm +++ b/lib/SQL/Translator/Schema/Constants.pm @@ -35,6 +35,8 @@ This module exports the following constants for Schema features; =item UNIQUE +=item EXCLUDE + =back =cut @@ -55,6 +57,7 @@ our @EXPORT = qw[ NULL PRIMARY_KEY UNIQUE + EXCLUDE ]; # @@ -78,6 +81,8 @@ use constant PRIMARY_KEY => 'PRIMARY KEY'; use constant UNIQUE => 'UNIQUE'; +use constant EXCLUDE => 'EXCLUDE'; + 1; =pod diff --git a/lib/SQL/Translator/Schema/Constraint.pm b/lib/SQL/Translator/Schema/Constraint.pm index 7742bf777..e6208863f 100644 --- a/lib/SQL/Translator/Schema/Constraint.pm +++ b/lib/SQL/Translator/Schema/Constraint.pm @@ -40,6 +40,7 @@ my %VALID_CONSTRAINT_TYPE = ( CHECK_C, 1, FOREIGN_KEY, 1, NOT_NULL, 1, + EXCLUDE, 1, ); =head2 new