.

On Fri, Jun 1, 2012 at 9:14 AM, Bob MacCallum <[email protected]> wrote:

> On Fri, Jun 1, 2012 at 2:43 PM, Bill Moseley <[email protected]> wrote:
>
>> I have a time_zone column, but sadly it allows nulls.  Fixing the
>> database would be the correct approach, but for now I'm looking at
>> defaulting the column.  But, the default value depends on which database we
>> are connected to.
>>
>> The result class is used in both a Catalyst app and in cron jobs.  Both
>> the Catalyst app and the cron jobs pull the connect_info from a single
>> config config, so the only thing I really have in common for all uses is
>> connect_info.
>>
>> So, in the result class I can use "around time_zone => sub {}" to set the
>> default
>>
>> One option is to just do a match on the database name in the dsn:
>>
>>  $self->result_source->storage->connect_info->[0]->{dsn}.
>>
>>
>> but I can't be sure someone won't change that later.
>>
>> Now I'm looking at just adding a "default_time_zone" to connect_info and
>> then inspecting:
>>
>> $self->result_source->storage->connect_info->[0]->{default_time_zone}.
>>
>> And then do:
>>
>> around time_zone => sub {
>>     my $orig = shift;
>>     my $self = shift;
>>     return $self->$orig( @_ )
>> || $self->result_source->storage->connect_info->[0]->{default_time_zone};
>> };
>>
>> Is there a more elegant solution to this?
>>
>> I don't like stuffing non-database args into connect_info, of course, but
>> it seems like the only thing I have available in all my environments.
>>
>
> couldn't/shouldn't the default timezone be stored in the db, in a simple
> key/value table called "meta" or similar?
>

Why not just add a database level default?  That would be easy, clean, and
correct.  Plus if do that to remove the actual nulls from the DB


-- 
fREW Schmidt
http://blog.afoolishmanifesto.com
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to