X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F10sqlite_common.t;h=6fe4b63dd0cb826d5bc55acc44a5e5ded2924ced;hb=128f61d834839db22612bcca96e1014ed9f7e8df;hp=299673826042a8b734fbc33f63a3a13f2c25e81a;hpb=0fa48bf53a50a2aac4a74b9ddab65d3ab5d1406c;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/t/10sqlite_common.t b/t/10sqlite_common.t index 2996738..6fe4b63 100644 --- a/t/10sqlite_common.t +++ b/t/10sqlite_common.t @@ -12,13 +12,60 @@ my $tester = dbixcsl_common_tests->new( dsn => "dbi:$class:dbname=./t/sqlite_test", user => '', password => '', + connect_info_opts => { + on_connect_do => 'PRAGMA foreign_keys = ON', + }, + loader_options => { preserve_case => 1 }, + data_types => { + # SQLite ignores data types aside from INTEGER pks. + # We just test that they roundtrip sanely. + # + # Numeric types + 'smallint' => { data_type => 'smallint' }, + 'int' => { data_type => 'int' }, + 'integer' => { data_type => 'integer' }, + + # test that type name is lowercased + 'INTEGER' => { data_type => 'integer' }, + + 'bigint' => { data_type => 'bigint' }, + 'float' => { data_type => 'float' }, + 'double precision' => + { data_type => 'double precision' }, + 'real' => { data_type => 'real' }, + + 'float(2)' => { data_type => 'float', size => 2 }, + 'float(7)' => { data_type => 'float', size => 7 }, + + 'decimal' => { data_type => 'decimal' }, + 'dec' => { data_type => 'dec' }, + 'numeric' => { data_type => 'numeric' }, + + 'decimal(3)' => { data_type => 'decimal', size => 3 }, + 'numeric(3)' => { data_type => 'numeric', size => 3 }, + + 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] }, + 'dec(3,3)' => { data_type => 'dec', size => [3,3] }, + 'numeric(3,3)' => { data_type => 'numeric', size => [3,3] }, + + # Date and Time Types + 'date' => { data_type => 'date' }, + 'timestamp DEFAULT CURRENT_TIMESTAMP' + => { data_type => 'timestamp', default_value => \'current_timestamp' }, + 'time' => { data_type => 'time' }, + + # String Types + 'char' => { data_type => 'char' }, + 'char(11)' => { data_type => 'char', size => 11 }, + 'varchar(20)' => { data_type => 'varchar', size => 20 }, + }, extra => { create => [ # 'sqlite_' is reserved, so we use 'extra_' q{ CREATE TABLE "extra_loader_test1" ( "id" NOT NULL PRIMARY KEY, - "value" VARCHAR(100) NOT NULL + "value" TEXT UNIQUE NOT NULL ) }, q{ @@ -31,7 +78,7 @@ my $tester = dbixcsl_common_tests->new( person_id INTEGER PRIMARY KEY ) }, - # Wordy, newline-heavy SQL to stress the regexes + # Wordy, newline-heavy SQL q{ CREATE TABLE extra_loader_test4 ( event_id INTEGER NOT NULL @@ -43,9 +90,32 @@ my $tester = dbixcsl_common_tests->new( PRIMARY KEY (event_id, person_id) ) }, + # make sure views are picked up + q{ + CREATE VIEW extra_loader_test5 AS SELECT * FROM extra_loader_test4 + }, + # Compound primary keys can't be autoinc in the DBIC sense + q{ + CREATE TABLE extra_loader_test6 ( + id1 INTEGER, + id2 INTEGER, + value INTEGER, + PRIMARY KEY (id1, id2) + ) + }, + q{ + CREATE TABLE extra_loader_test7 ( + id1 INTEGER, + id2 TEXT, + value DECIMAL, + PRIMARY KEY (id1, id2) + ) + }, ], - drop => [ qw/extra_loader_test1 extra_loader_test2 extra_loader_test3 extra_loader_test4 / ], - count => 7, + pre_drop_ddl => [ 'DROP VIEW extra_loader_test5' ], + drop => [ qw/extra_loader_test1 extra_loader_test2 extra_loader_test3 + extra_loader_test4 extra_loader_test6 extra_loader_test7/ ], + count => 11, run => sub { my ($schema, $monikers, $classes) = @_; @@ -57,8 +127,11 @@ my $tester = dbixcsl_common_tests->new( is_deeply [ $source->columns ], [ qw/id value/ ], 'retrieved quoted column names from quoted table'; + ok ((exists $source->column_info('value')->{is_nullable}), + 'is_nullable exists'); + is $source->column_info('value')->{is_nullable}, 0, - 'is_nullable detection'; + 'is_nullable is set correctly'; ok (($source = $schema->source($monikers->{extra_loader_test4})), 'verbose table'); @@ -69,6 +142,15 @@ my $tester = dbixcsl_common_tests->new( is ($source->relationships, 2, '2 foreign key constraints found'); + # test that columns for views are picked up + is $schema->resultset($monikers->{extra_loader_test5})->result_source->column_info('person_id')->{data_type}, 'integer', + 'columns for views are introspected'; + + isnt $schema->resultset($monikers->{extra_loader_test6})->result_source->column_info('id1')->{is_auto_increment}, 1, + q{two integer PKs don't get marked autoinc}; + + isnt $schema->resultset($monikers->{extra_loader_test7})->result_source->column_info('id1')->{is_auto_increment}, 1, + q{composite integer PK with non-integer PK doesn't get marked autoinc}; }, }, );