) . ';';
}
+sub enum_constraint_name {
+ my ($self, $field_name) = @_;
+ $self->quote($field_name . '_chk' )
+}
+
+sub enum_constraint {
+ my ( $self, $field_name, $vals ) = @_;
+
+ return (
+ 'CONSTRAINT ' . $self->enum_constraint_name($field_name) .
+ ' CHECK (' . $self->quote($field_name) .
+ ' IN (' . join( ',', map qq('$_'), @$vals ) . '))'
+ )
+}
+
1;
#
my $data_type = lc $field->data_type;
my %extra = $field->extra;
- my $list = $extra{'list'} || [];
- # \todo deal with embedded quotes
- my $commalist = join( ', ', map { qq['$_'] } @$list );
if ( $data_type eq 'enum' ) {
- my $check_name = mk_name( $field_name . '_chk' );
- push @constraint_defs,
- "CONSTRAINT $check_name CHECK ($field_name IN ($commalist))";
- $data_type .= 'character varying';
+ push @constraint_defs, $future->enum_constraint($field_name, $extra{'list'} || [])
}
push @field_defs, $future->field($field);