remove is_deferrable from default rel options to maintain principle of least surprise...
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10sqlite_common.t
CommitLineData
a78e3fed 1use strict;
8763ffda 2use Test::More;
c2849787 3use lib qw(t/lib);
fbd83464 4use dbixcsl_common_tests;
a78e3fed 5
6eval { require DBD::SQLite };
7my $class = $@ ? 'SQLite2' : 'SQLite';
8
8763ffda 9my $tester = dbixcsl_common_tests->new(
10 vendor => 'SQLite',
11 auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT',
12 dsn => "dbi:$class:dbname=./t/sqlite_test",
13 user => '',
14 password => '',
b308dcca 15 connect_info_opts => {
16 on_connect_do => 'PRAGMA foreign_keys = ON',
17 },
62bc1e5d 18 data_types => {
19 # SQLite ignores data types aside from INTEGER pks.
20 # We just test that they roundtrip sanely.
21 #
22 # Numeric types
23 'smallint' => { data_type => 'smallint' },
24 'int' => { data_type => 'int' },
25 'integer' => { data_type => 'integer' },
26 'bigint' => { data_type => 'bigint' },
27 'float' => { data_type => 'float' },
28 'double precision' =>
29 { data_type => 'double precision' },
30 'real' => { data_type => 'real' },
31
32 'float(2)' => { data_type => 'float', size => 2 },
33 'float(7)' => { data_type => 'float', size => 7 },
34
35 'decimal' => { data_type => 'decimal' },
36 'dec' => { data_type => 'dec' },
37 'numeric' => { data_type => 'numeric' },
38
39 'decimal(3)' => { data_type => 'decimal', size => 3 },
40 'numeric(3)' => { data_type => 'numeric', size => 3 },
41
42 'decimal(3,3)' => { data_type => 'decimal', size => [3,3] },
43 'dec(3,3)' => { data_type => 'dec', size => [3,3] },
44 'numeric(3,3)' => { data_type => 'numeric', size => [3,3] },
45
46 # Date and Time Types
47 'date' => { data_type => 'date' },
48 'timestamp DEFAULT CURRENT_TIMESTAMP'
49 => { data_type => 'timestamp', default_value => \'CURRENT_TIMESTAMP' },
50 'time' => { data_type => 'time' },
51
52 # String Types
53 'char' => { data_type => 'char' },
54 'char(11)' => { data_type => 'char', size => 11 },
55 'varchar(20)' => { data_type => 'varchar', size => 20 },
56 },
8763ffda 57 extra => {
58 create => [
59 # 'sqlite_' is reserved, so we use 'extra_'
60 q{
61 CREATE TABLE "extra_loader_test1" (
62 "id" NOT NULL PRIMARY KEY,
2a6dfbc9 63 "value" TEXT UNIQUE NOT NULL
8763ffda 64 )
68d650df 65 },
66 q{
67 CREATE TABLE extra_loader_test2 (
68 event_id INTEGER PRIMARY KEY
69 )
70 },
71 q{
72 CREATE TABLE extra_loader_test3 (
73 person_id INTEGER PRIMARY KEY
74 )
75 },
26da4cc3 76 # Wordy, newline-heavy SQL
68d650df 77 q{
78 CREATE TABLE extra_loader_test4 (
79 event_id INTEGER NOT NULL
80 CONSTRAINT fk_event_id
81 REFERENCES extra_loader_test2(event_id),
82 person_id INTEGER NOT NULL
83 CONSTRAINT fk_person_id
84 REFERENCES extra_loader_test3 (person_id),
85 PRIMARY KEY (event_id, person_id)
86 )
87 },
26da4cc3 88 # make sure views are picked up
89 q{
90 CREATE VIEW extra_loader_test5 AS SELECT * FROM extra_loader_test4
91 }
8763ffda 92 ],
26da4cc3 93 pre_drop_ddl => [ 'DROP VIEW extra_loader_test5' ],
68d650df 94 drop => [ qw/extra_loader_test1 extra_loader_test2 extra_loader_test3 extra_loader_test4 / ],
bf558f72 95 count => 9,
8763ffda 96 run => sub {
97 my ($schema, $monikers, $classes) = @_;
a78e3fed 98
8763ffda 99 ok ((my $rs = $schema->resultset($monikers->{extra_loader_test1})),
100 'resultset for quoted table');
101
0fa48bf5 102 ok ((my $source = $rs->result_source), 'source');
103
104 is_deeply [ $source->columns ], [ qw/id value/ ],
8763ffda 105 'retrieved quoted column names from quoted table';
68d650df 106
3b134b29 107 ok ((exists $source->column_info('value')->{is_nullable}),
108 'is_nullable exists');
109
0fa48bf5 110 is $source->column_info('value')->{is_nullable}, 0,
3b134b29 111 'is_nullable is set correctly';
0fa48bf5 112
113 ok (($source = $schema->source($monikers->{extra_loader_test4})),
68d650df 114 'verbose table');
115
116 is_deeply [ $source->primary_columns ], [ qw/event_id person_id/ ],
117 'composite primary key';
118
68d650df 119 is ($source->relationships, 2,
120 '2 foreign key constraints found');
121
bf558f72 122 # test that columns for views are picked up
00805149 123 is $schema->resultset($monikers->{extra_loader_test5})->result_source->column_info('person_id')->{data_type}, 'integer',
bf558f72 124 'columns for views are introspected';
8763ffda 125 },
126 },
127);
128
129$tester->run_tests();
a78e3fed 130
131END {
132 unlink './t/sqlite_test';
133}