Fix index issue in Parser::DBI::PostgreSQL
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / SQLite.pm
index 55f6e8d..1024330 100644 (file)
@@ -433,6 +433,17 @@ table_constraint : PRIMARY_KEY parens_field_list conflict_clause(?)
             on_conflict => $item[5][0],
         }
     }
+    |
+    FOREIGN_KEY parens_field_list REFERENCES ref_def
+    {
+      $return = {
+        supertype        => 'constraint',
+        type             => 'foreign_key',
+        fields           => $item[2],
+        reference_table  => $item[4]{'reference_table'},
+        reference_fields => $item[4]{'reference_fields'},
+      }
+    }
 
 ref_def : /(\w+)\s*\((\w+)\)/
     { $return = { reference_table => $1, reference_fields => $2 } }
@@ -573,6 +584,8 @@ NOT_NULL : /not null/i
 
 PRIMARY_KEY : /primary key/i
 
+FOREIGN_KEY : /foreign key/i
+
 CHECK_C : /check/i
 
 DEFAULT : /default/i
@@ -674,7 +687,7 @@ sub parse {
         for my $idata ( @{ $tdata->{'indices'} || [] } ) {
             my $index  =  $table->add_index(
                 name   => $idata->{'name'},
-                type   => uc $idata->{'type'},
+                type   => uc ($idata->{'type'}||''),
                 fields => $idata->{'fields'},
             ) or die $table->error;
         }