DBIC note to self...

|
There's an interesting interaction between PostgreSQL, DBIx::Class::Schema::Loader and DBIx::Class:InflateColumn::DateTime.

When you define a column to be of type TIMESTAMP, it actually becomes a TIMESTAMP WITHOUT TIME ZONE. DBIx::Class::Schema::Loader just copies this into the DBIC data_type field without translation, and so when DBIx::Class::InflateColumn::DateTime comes along, it doesn't realise it's a time value and doesn't bother to add the inflater.

This awful kludge hooks register_column and changes the data_type field to "timestamp", thus making it all work as expected.

(code after the cut)
package DBIx::Class::InflateColumn::PgDateTimeTZKludge;
use Moose;
extends qw/DBIx::Class/;

# This DBIC component is added to the DBIC loader_options *just after*
# InflateColumn::DateTime - it's chained so it's actually run *first* - and
# it will change "timestamp without time zone" columns to "timestamp" so
# that InflateColumn realises they are timestamp types and adds its
# inflater/deflater.

sub register_column {
  my ($self, $column, $info, @rest) = @_;
  $self->next::method($column, $info, @rest);
  return unless defined($info->{data_type});

  my $type = lc $info->{data_type};
  if($type eq 'timestamp without time zone') {
    $info->{data_type} = 'timestamp';
  } # elsif etc
}

About this Entry

This page contains a single entry by Peter Corlett published on July 4, 2009 9:45 PM.

Geekcycle, part 3 was the previous entry in this blog.

Find recent content on the main index or look in the archives to find all content.