Fix silent failures on autoinc PK without an is_auto_increment attribute
[dbsrgits/DBIx-Class.git] / t / cdbi / testlib / Log.pm
1 package # hide from PAUSE
2     Log;
3
4 use warnings;
5 use strict;
6
7 use base 'MyBase';
8
9 use Time::Piece::MySQL;
10 use POSIX ();
11
12 __PACKAGE__->set_table();
13 __PACKAGE__->columns(All => qw/id message datetime_stamp/);
14 __PACKAGE__->has_a(
15   datetime_stamp => 'Time::Piece',
16   inflate        => 'from_mysql_datetime',
17   deflate        => 'mysql_datetime'
18 );
19
20 # Disables the implicit autoinc-on-non-supplied-pk behavior
21 # (and the warning that goes with it)
22 # This is the same behavior as it was pre 0.082900
23 __PACKAGE__->column_info('id')->{is_auto_increment} = 0;
24
25 __PACKAGE__->add_trigger(before_create => \&set_dts);
26 __PACKAGE__->add_trigger(before_update => \&set_dts);
27
28 sub set_dts {
29   shift->datetime_stamp(
30     POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime(time)));
31 }
32
33 sub create_sql {
34   return qq{
35     id             INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
36     message        VARCHAR(255),
37     datetime_stamp DATETIME
38   };
39 }
40
41 1;
42