Changeset 404

Show
Ignore:
Timestamp:
02/04/08 22:09:56 (10 months ago)
Author:
eevee
Message:

Bit of a shoutbox test. Not particularly amazing. For the life of me I can't figure out how to log in and stay that way. (#152)
Tossing in my schema cleanup script, too. Ugh dirty mixed commits~

Location:
veekun/trunk
Files:
2 added
1 removed
4 modified

Legend:

Unmodified
Added
Removed
  • veekun/trunk/lib/Vee/Model/DBIC.pm

    r186 r404  
    88 
    99sub new { 
     10    # For testing purposes, allow use of a temporary SQLite db 
     11    if ($ENV{VEEKUN_USE_TEMP_DB}) { 
     12        # Use Catalyst's global config override and an in-memory db 
     13        $_[-1]->{connect_info} = ["dbi:SQLite:dbname=:memory:"]; 
     14    } 
     15 
    1016    my $self = shift->NEXT::new(@_); 
    1117 
     18    if ($ENV{VEEKUN_USE_TEMP_DB}) { 
     19        $self->schema->add_simple_column_types; 
     20        $self->schema->deploy({ producer => 'SQLite' }); 
     21    } 
     22 
     23    # TODO: What to do here?  Temp db won't have any data! 
    1224    Vee::Dex::initialize( $self ); 
    1325 
  • veekun/trunk/lib/Vee/Schema.pm

    r31 r404  
    11package Vee::Schema; 
    2  
    3 # Created by DBIx::Class::Schema::Loader v0.03003 @ 2006-07-09 12:56:13 
    42 
    53use strict; 
    64use warnings; 
    7  
    85use base 'DBIx::Class::Schema'; 
    96 
    107__PACKAGE__->load_classes; 
    118 
     9=head1 METHODS 
     10 
     11=head2 add_simple_column_types 
     12 
     13Iterates over every column in every table in the schema.  Primary key columns 
     14named C<id> are given a C<data_type> of C<integer>; all other columns are set 
     15C<is_nullable>. 
     16 
     17This method is really a hack for deploying the schema to SQLite and testing with 
     18dummy data; autoincrement will only work on single-column integral primary keys, 
     19and defaults for every column would be a pain to mark just for tests. 
     20 
     21=cut 
     22 
     23sub add_simple_column_types { 
     24    my ($self) = @_; 
     25 
     26    for my $table_name ($self->sources) { 
     27        my $table = $self->source($table_name); 
     28 
     29        for my $column_name ($table->columns) { 
     30            my $column_info = $table->column_info($column_name); 
     31 
     32            # sessions table uses a string, as dictated by Session plugin 
     33            if ($table_name ne 'Sessions' and 
     34                $column_name eq 'id' and 
     35                join("\0", $table->primary_columns) eq 'id') 
     36            { 
     37                $column_info->{data_type} = 'integer'; 
     38            } else { 
     39                $column_info->{is_nullable} = 1; 
     40            } 
     41        } 
     42    } 
     43} 
     44 
    12451; 
  • veekun/trunk/lib/Vee/Schema/Sessions.pm

    r350 r404  
    1313__PACKAGE__->load_components('Core'); 
    1414__PACKAGE__->table('sessions'); 
    15 __PACKAGE__->add_columns(qw/ id userid expires data /); 
     15# All these columns need to be NULLable for deployment, as Catalyst's session 
     16# handling is dumb and insists on shoving useless undef values into this table. 
     17__PACKAGE__->add_columns( 
     18    'id', 
     19    userid  => { is_nullable => 1 }, 
     20    expires => { is_nullable => 1 }, 
     21    data    => { is_nullable => 1 }, 
     22); 
    1623__PACKAGE__->set_primary_key('id'); 
    1724 
  • veekun/trunk/lib/Vee/Schema/Shoutbox.pm

    r350 r404  
    1313__PACKAGE__->load_components('Core'); 
    1414__PACKAGE__->table('shoutbox'); 
    15 __PACKAGE__->add_columns(qw/ id name userid ip time message /); 
     15__PACKAGE__->add_columns( 
     16    qw/ id name /, 
     17    userid => { is_nullable => 1 }, 
     18    qw/ ip time message / 
     19); 
    1620__PACKAGE__->set_primary_key('id'); 
    1721