Provide default index names for SQLite
[dbsrgits/SQL-Translator.git] / t / 56-sqlite-producer.t
index 2129c29..66bb8bb 100644 (file)
@@ -165,39 +165,31 @@ $SQL::Translator::Producer::SQLite::NO_QUOTES = 0;
 }
 
 {
-   my $table = SQL::Translator::Schema::Table->new(
-       name => 'foo_auto_increment',
-   );
-   $table->add_field(
-       name => 'id',
-       data_type => 'integer',
-       is_nullable => 0,
-       is_auto_increment => 1,
-   );
-   $table->primary_key('id');
-   my $expected = [ qq<CREATE TABLE "foo_auto_increment" (
-  "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
-)>];
-   my $result =  [SQL::Translator::Producer::SQLite::create_table($table, { no_comments => 1 })];
-   is_deeply($result, $expected, 'correctly built table with autoincrement on primary key');
-}
+    my $table = SQL::Translator::Schema::Table->new( name => 'foobar', fields => ['foo'] );
 
-{
-   my $table = SQL::Translator::Schema::Table->new(
-       name => 'foo_no_auto_increment',
-   );
-   $table->add_field(
-       name => 'id',
-       data_type => 'integer',
-       is_nullable => 0,
-       is_auto_increment => 0,
-   );
-   $table->primary_key('id');
-   my $expected = [ qq<CREATE TABLE "foo_no_auto_increment" (
-  "id" INTEGER PRIMARY KEY NOT NULL
-)>];
-   my $result =  [SQL::Translator::Producer::SQLite::create_table($table, { no_comments => 1 })];
-   is_deeply($result, $expected, 'correctly built table without autoincrement on primary key');
+    {
+        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');
+    }
 }
 
 done_testing;