|
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 | |
|---|
| 1 | package Vee::Schema; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use base 'DBIx::Class::Schema'; |
|---|
| 6 | |
|---|
| 7 | __PACKAGE__->load_classes; |
|---|
| 8 | |
|---|
| 9 | =head1 METHODS |
|---|
| 10 | |
|---|
| 11 | =head2 add_simple_column_types |
|---|
| 12 | |
|---|
| 13 | Iterates over every column in every table in the schema. Primary key columns |
|---|
| 14 | named C<id> are given a C<data_type> of C<integer>; all other columns are set |
|---|
| 15 | C<is_nullable>. |
|---|
| 16 | |
|---|
| 17 | This method is really a hack for deploying the schema to SQLite and testing with |
|---|
| 18 | dummy data; autoincrement will only work on single-column integral primary keys, |
|---|
| 19 | and defaults for every column would be a pain to mark just for tests. |
|---|
| 20 | |
|---|
| 21 | =cut |
|---|
| 22 | |
|---|
| 23 | sub 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 | |
|---|
| 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 | |
|---|
| 45 | 1; |
|---|