6 use SQL::Translator::Constants qw(:sqlt_types :sqlt_constants);
8 my $file = "$Bin/data/sqlite/create.sql";
12 open my $fh, "<$file" or die "Can't read file '$file': $!\n";
14 my $t = SQL::Translator->new({ from => 'SQLite' });
17 my $schema = $t->schema;
19 my @tables = $schema->get_tables;
20 is( scalar @tables, 2, 'Parsed two tables' );
22 my $t1 = shift @tables;
23 is( $t1->name, 'person', "'Person' table" );
25 my @fields = $t1->get_fields;
26 is( scalar @fields, 6, 'Six fields in "person" table');
27 my $fld1 = shift @fields;
28 is( $fld1->name, 'person_id', 'First field is "person_id"');
29 is( $fld1->is_auto_increment, 1, 'Is an autoincrement field');
31 my $t2 = shift @tables;
32 is( $t2->name, 'pet', "'Pet' table" );
34 my @constraints = $t2->get_constraints;
35 is( scalar @constraints, 3, '3 constraints on pet' );
37 my $c1 = pop @constraints;
38 is( $c1->type, 'FOREIGN KEY', 'FK constraint' );
39 is( $c1->reference_table, 'person', 'References person table' );
40 is( join(',', $c1->reference_fields), 'person_id',
41 'References person_id field' );
43 my @views = $schema->get_views;
44 is( scalar @views, 1, 'Parsed one views' );
46 my @triggers = $schema->get_triggers;
47 is( scalar @triggers, 1, 'Parsed one triggers' );