Alzabo
view release on metacpan or search on metacpan
lib/Alzabo/RDBMSRules/PostgreSQL.pm view on Meta::CPAN
FLOAT
FLOAT4
FLOAT8
INET
SMALLINT
INT
INTEGER
INT2
INT4
INT8
INTERVAL
MACADDR
MONEY
NUMERIC
OID
RELTIME
SERIAL
SERIAL4
SERIAL8
TEXT
TIME
TIMESTAMP
TIMESTAMPTZ
TIMETZ
VARBIT
VARCHAR );
return 'INTEGER' if $type eq 'INT' || $type eq 'INT4';
return 'SERIAL' if $type eq 'SERIAL4';
return 'INT8' if $type eq 'BIGINT';
return $type if $simple_types{$type};
return $type if $type =~ /BIT\s+VARYING/;
return $type if $type =~ /CHARACTER\s+VARYING/;
return $type if $type =~ /\ABOX|CIRCLE|LINE|LSEG|PATH|POINT|POLYGON/;
Alzabo::Exception::RDBMSRules->throw( error => "Invalid column type: $type" );
}
sub validate_column_length
{
my $self = shift;
my $column = shift;
if ( defined $column->length )
{
Alzabo::Exception::RDBMSRules->throw( error => "Length is not supported except for char, varchar, decimal, float, and numeric columns (" . $column->name . " column)" )
unless $column->type =~ /\A(?:(?:VAR)?CHAR|CHARACTER|DECIMAL|FLOAT|NUMERIC|(?:VAR)?BIT|BIT VARYING)\z/i;
}
if ( defined $column->precision )
{
Alzabo::Exception::RDBMSRules->throw( error => "Precision is not supported except for decimal, float, and numeric columns" )
unless $column->type =~ /\A(?:DECIMAL|FLOAT|NUMERIC)\z/i;
}
}
# placeholder in case we decide to try to do something better later
sub validate_table_attribute { 1 }
sub validate_column_attribute
{
my $self = shift;
my %p = @_;
my $column = $p{column};
my $type = $column->type;
my $a = uc $p{attribute};
$a =~ s/\A\s//;
$a =~ s/\s\z//;
return if $a =~ /\A(?:UNIQUE\z|CHECK|CONSTRAINT|REFERENCES)/i;
Alzabo::Exception::RDBMSRules->throw( error => "Only column constraints are supported as column attributes" )
}
sub validate_primary_key
{
my $self = shift;
my $col = shift;
my $serial_col = (grep { $_->type =~ /^(?:SERIAL(?:4|8)?|BIGSERIAL)$/ } $col->table->primary_key)[0];
if ( defined $serial_col &&
$serial_col->name ne $col->name )
{
$serial_col->set_type( $serial_col->type =~ /^SERIAL4?$/
? 'INT4'
: 'INT8' );
}
}
sub validate_sequenced_attribute
{
my $self = shift;
my $col = shift;
Alzabo::Exception::RDBMSRules->throw( error => 'Non-number columns cannot be sequenced' )
unless $col->is_integer || $col->is_floating_point;
}
sub validate_index
{
my $self = shift;
my $index = shift;
foreach my $c ( $index->columns )
{
Alzabo::Exception::RDBMSRules->throw( error => "PostgreSQL does not support index prefixes" )
if defined $index->prefix($c)
}
Alzabo::Exception::RDBMSRules->throw( error => "PostgreSQL does not support fulltext indexes" )
if $index->fulltext;
}
sub type_is_integer
{
my $self = shift;
( run in 0.705 second using v1.01-cache-2.11-cpan-ceb78f64989 )