' (' . join( ', ', map $_[0]->shim->quote($_), $_[1]->fields ) . ');'
}
+sub unique_constraint_single {
+ my ($self, $constraint) = @_;
+
+ 'CONSTRAINT ' .
+ $self->unique_constraint_name($constraint) .
+ ' UNIQUE (' . join( ', ', $constraint->fields ) . ')'
+}
+
+sub unique_constraint_name {
+ my ($self, $constraint) = @_;
+ $self->shim->quote($constraint->name || $constraint->table->name . '_uc' )
+}
+
+sub unique_constraint_multiple {
+ my ($self, $constraint) = @_;
+
+ 'CREATE UNIQUE NONCLUSTERED INDEX ' .
+ $self->unique_constraint_name($constraint) .
+ ' ON ' . $self->shim->quote($constraint->table->name) . ' (' .
+ join( ', ', $constraint->fields ) . ')' .
+ ' WHERE ' . join( ' AND ',
+ map $self->shim->quote($_->name) . ' IS NOT NULL',
+ grep { $_->is_nullable } $constraint->fields ) . ';'
+}
+
1;
$c_def = $future->primary_key_constraint($constraint)
}
elsif ( $type eq UNIQUE ) {
- $name = $name_ur || mk_name( $table_name . '_uc' );
- my @nullable = grep { $_->is_nullable } $constraint->fields;
- if (!@nullable) {
- $c_def =
- "CONSTRAINT $name UNIQUE " .
- '(' . join( ', ', @fields ) . ')';
+ if (!grep { $_->is_nullable } $constraint->fields) {
+ $c_def = $future->unique_constraint_single($constraint)
} else {
- push @index_defs,
- "CREATE UNIQUE NONCLUSTERED INDEX $name_ur ON $table_name_ur (" .
- join( ', ', @fields ) . ')' .
- ' WHERE ' . join( ' AND ', map unreserve($_->name) . ' IS NOT NULL', @nullable ) . ';';
+ push @index_defs, $future->unique_constraint_multiple($constraint);
next;
}
}