use strict;
-use Test::More tests => 177;
+use Test::More;
use SQL::Translator;
-use SQL::Translator::Parser::MySQL qw(parse);
use SQL::Translator::Schema::Constants;
+eval {
+ require SQL::Translator::Parser::MySQL;
+ SQL::Translator::Parser::MySQL->import('parse');
+};
+if ($@) {
+ plan skip_all => "$@";
+}
+else {
+ plan tests => 180;
+}
+
{
my $tr = SQL::Translator->new;
my $data = q|create table sessions (
my $val = parse($tr, $data);
my $schema = $tr->schema;
+ is( $schema->is_valid, 1, 'Schema is valid' );
my @tables = $schema->get_tables;
is( scalar @tables, 1, 'Right number of tables (1)' );
my $table = shift @tables;
is( $f2->name, 'a_session', 'Second field name is "a_session"' );
is( $f2->data_type, 'text', 'Type is "text"' );
- is( $f2->size, 0, 'Size is "0"' );
+ is( $f2->size, 65_535, 'Size is "65,535"' );
is( $f2->is_nullable, 1, 'Field can be null' );
is( $f2->default_value, undef, 'Default value is undefined' );
is( $f2->is_primary_key, 0, 'Field is not PK' );
);
my $schema = $tr->schema;
+ is( $schema->is_valid, 1, 'Schema is valid' );
my @tables = $schema->get_tables;
is( scalar @tables, 1, 'Right number of tables (1)' );
my $table = shift @tables;
KEY (billing_address_id),
KEY (shipping_address_id),
KEY (member_id, store_id),
- FOREIGN KEY (status) REFERENCES order_status(id),
+ FOREIGN KEY (status) REFERENCES order_status(id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (billing_address_id) REFERENCES address(address_id),
FOREIGN KEY (shipping_address_id) REFERENCES address(address_id)
) TYPE=INNODB;
) or die $tr->error;
my $schema = $tr->schema;
+ is( $schema->is_valid, 1, 'Schema is valid' );
my @tables = $schema->get_tables;
is( scalar @tables, 2, 'Right number of tables (2)' );
is( $c5->type, FOREIGN_KEY, 'Constraint is a FK' );
is( join(',', $c5->fields), 'store_id', 'Constraint is on "store_id"' );
is( $c5->reference_table, 'store', 'To table "store"' );
- is( join(',', $c5->reference_fields), '', 'No reference fields defined' );
+ is( join(',', map { $_ || '' } $c5->reference_fields), '',
+ 'No reference fields defined' );
my $t2 = shift @tables;
is( $t2->name, 'address', 'Found "address" table' );