root/veekun/trunk/lib/Vee/Schema.pm

Revision 404, 1.2 kB (checked in by eevee, 11 months ago)

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~

Line 
1package Vee::Schema;
2
3use strict;
4use warnings;
5use base 'DBIx::Class::Schema';
6
7__PACKAGE__->load_classes;
8
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
451;
Note: See TracBrowser for help on using the browser.