X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F56-sqlite-producer.t;h=d0d2cfeb267f661c305227d9ed2d007641e04ae1;hb=HEAD;hp=5d56adf082fbd275c27b14d00822a33a92e82fec;hpb=7313cecbe6f1660e72486d0d6cf41437632d6223;p=dbsrgits%2FSQL-Translator.git diff --git a/t/56-sqlite-producer.t b/t/56-sqlite-producer.t index 5d56adf..d0d2cfe 100644 --- a/t/56-sqlite-producer.t +++ b/t/56-sqlite-producer.t @@ -5,6 +5,7 @@ use strict; use Test::More; use Test::SQL::Translator qw(maybe_plan); +use SQL::Translator::Schema; use SQL::Translator::Schema::View; use SQL::Translator::Schema::Table; use SQL::Translator::Producer::SQLite; @@ -164,4 +165,90 @@ $SQL::Translator::Producer::SQLite::NO_QUOTES = 0; is_deeply($result, $expected, 'correctly unquoted excempted DEFAULTs'); } +{ + my $table = SQL::Translator::Schema::Table->new( + name => 'some_table', + ); + $table->add_field( + name => 'id', + data_type => 'integer', + is_auto_increment => 1, + is_nullable => 0, + extra => { + auto_increment_type => 'monotonic', + }, + ); + $table->primary_key('id'); + my $expected = [ qq]; + my $result = [SQL::Translator::Producer::SQLite::create_table($table, { no_comments => 1 })]; + is_deeply($result, $expected, 'correctly built monotonicly autoincremened PK'); +} + +{ + my $table = SQL::Translator::Schema::Table->new( name => 'foobar', fields => ['foo'] ); + + { + my $index = $table->add_index(name => 'myindex', fields => ['foo']); + my ($def) = SQL::Translator::Producer::SQLite::create_index($index); + is($def, 'CREATE INDEX "myindex" ON "foobar" ("foo")', 'index created'); + } + + { + my $index = $table->add_index(fields => ['foo']); + my ($def) = SQL::Translator::Producer::SQLite::create_index($index); + is($def, 'CREATE INDEX "foobar_idx" ON "foobar" ("foo")', 'index created'); + } + + { + my $constr = $table->add_constraint(name => 'constr', fields => ['foo']); + my ($def) = SQL::Translator::Producer::SQLite::create_constraint($constr); + is($def, 'CREATE UNIQUE INDEX "constr" ON "foobar" ("foo")', 'constraint created'); + } + + { + my $constr = $table->add_constraint(fields => ['foo']); + my ($def) = SQL::Translator::Producer::SQLite::create_constraint($constr); + is($def, 'CREATE UNIQUE INDEX "foobar_idx02" ON "foobar" ("foo")', 'constraint created'); + } +} + +{ + my $schema = SQL::Translator::Schema->new(); + my $table = $schema->add_table( name => 'foo', fields => ['bar'] ); + + { + my $trigger = $schema->add_trigger( + name => 'mytrigger', + perform_action_when => 'before', + database_events => 'update', + on_table => 'foo', + fields => ['bar'], + action => 'BEGIN baz() END' + ); + my ($def) = SQL::Translator::Producer::SQLite::create_trigger($trigger); + is($def, 'CREATE TRIGGER "mytrigger" before update on "foo" BEGIN baz() END', 'trigger created'); + } + + { + my $trigger = $schema->add_trigger( + name => 'mytrigger2', + perform_action_when => 'after', + database_events => ['insert'], + on_table => 'foo', + fields => ['bar'], + action => 'baz()' + ); + my ($def) = SQL::Translator::Producer::SQLite::create_trigger($trigger); + is($def, 'CREATE TRIGGER "mytrigger2" after insert on "foo" BEGIN baz() END', 'trigger created'); + } +} + +{ + my $table = SQL::Translator::Schema::Table->new( name => 'foobar', fields => ['foo'] ); + my $constr = $table->add_constraint(name => 'constr', expression => "foo != 'baz'"); + my ($def) = SQL::Translator::Producer::SQLite::create_check_constraint($constr); + + is($def, q{CONSTRAINT "constr" CHECK(foo != 'baz')}, 'check constraint created'); +} + done_testing;