6 use Test::SQL::Translator qw(maybe_plan);
9 use SQL::Translator::Constants qw(:sqlt_types :sqlt_constants);
12 maybe_plan(12, 'SQL::Translator::Parser::DDL::SQLite');
15 my $file = "$Bin/data/sqlite/create.sql";
19 open my $fh, "<$file" or die "Can't read file '$file': $!\n";
21 my $t = SQL::Translator->new({ from => 'SQLite' });
24 my $schema = $t->schema;
26 my @tables = $schema->get_tables;
27 is( scalar @tables, 2, 'Parsed two tables' );
29 my $t1 = shift @tables;
30 is( $t1->name, 'person', "'Person' table" );
32 my @fields = $t1->get_fields;
33 is( scalar @fields, 6, 'Six fields in "person" table');
34 my $fld1 = shift @fields;
35 is( $fld1->name, 'person_id', 'First field is "person_id"');
36 is( $fld1->is_auto_increment, 1, 'Is an autoincrement field');
38 my $t2 = shift @tables;
39 is( $t2->name, 'pet', "'Pet' table" );
41 my @constraints = $t2->get_constraints;
42 is( scalar @constraints, 3, '3 constraints on pet' );
44 my $c1 = pop @constraints;
45 is( $c1->type, 'FOREIGN KEY', 'FK constraint' );
46 is( $c1->reference_table, 'person', 'References person table' );
47 is( join(',', $c1->reference_fields), 'person_id',
48 'References person_id field' );
50 my @views = $schema->get_views;
51 is( scalar @views, 1, 'Parsed one views' );
53 my @triggers = $schema->get_triggers;
54 is( scalar @triggers, 1, 'Parsed one triggers' );