use MooseX::Declare;
class SQL::Translator::Producer {
use SQL::Translator::Constants qw(:sqlt_types);
- use MooseX::Types::Moose qw(Bool HashRef Str);
+ use MooseX::Types::Moose qw(ArrayRef Bool HashRef ScalarRef Str);
use SQL::Translator::Types qw(Column Table Translator);
has 'data_type_mapping' => (
$column_def .= ' NOT NULL' unless $column->is_nullable;
$column_def;
}
+
+ method _default_value(ScalarRef|Str $default, ArrayRef $exceptions) {
+ if ($exceptions and ! ref $default) {
+ for (my $i = 0; $i < @$exceptions; $i += 2) {
+ my ($pat, $val) = @$exceptions[ $i, $i + 1 ];
+ if (ref $pat and $default =~ $pat) {
+ $default = $val;
+ last;
+ } elsif (lc $default eq lc $pat) {
+ $default = $val;
+ last
+ }
+ }
+ }
+
+ return ref($default) ? " DEFAULT $$default" : " DEFAULT '$default'";
+ }
}
use MooseX::Declare;
-role SQL::Translator::Producer::SQL::PostgreSQL {
+role SQL::Translator::Producer::SQL::PostgreSQL {
use SQL::Translator::Constants qw(:sqlt_types :sqlt_constants);
use SQL::Translator::Types qw(Column Constraint Index Table View);
my ( %index_name );
my $add_drop_view = $options->{add_drop_view};
my $view_name = $view->name;
-# debug("PKG: Looking at view '${view_name}'\n");
my $create = '';
$create .= "--\n-- View: ${qt}${view_name}${qt}\n--\n"
# Default value
#
my $default = $field->default_value;
-
-# if ( defined $default ) {
-# SQL::Translator::Producer->_apply_default_value(
-# \$field_def,
-# $default,
-# [
-# 'NULL' => \'NULL',
-# 'now()' => 'now()',
-# 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP',
-# ],
-# );
-# }
+ $field_def .= $self->_default_value($default, [ 'NULL'=> \'NULL', 'now()' => 'now()', 'CURRENT_TIMESTAMP' => 'CURRENT_TIMESTAMP', ] ) if defined $default;
#
# Not null constraint