]> git.nbdom.net Git - nb.git/commitdiff
indexes
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Mon, 4 Jul 2016 14:31:09 +0000 (15:31 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Mon, 4 Jul 2016 14:31:09 +0000 (15:31 +0100)
lib/php/db/table.php

index 97cddc1f1422a1da637ab28e14cb30737722c130..72aab783b72323e8942cf8a0178de4289f3b608e 100644 (file)
@@ -163,8 +163,12 @@ Class Table extends nb {
       ;
     }
 
-    $sql_index = '';#$this->db()->type('table.sql.index',false);
-    return $sql_replace($sql.')'.($sql_index ? ';'.$this->db()->row($sql_index) : ''));
+    $indexes = [];#$this->db()->type('table.sql.index',false);
+    foreach ($this->indexes() as $i) {
+      if (!empty($i['unique']) or !empty($i['key'])) continue;
+      $indexes[] = 'CREATE INDEX '.$i['name'].' ON '.$this->sql_name().' ('.$i['field'].')';
+    }
+    return $sql_replace($sql.')'.($indexes ? ';'.join(';',$indexes) : ''));
   }
 
   /*
@@ -252,7 +256,7 @@ Class Table extends nb {
       // Get other indexes
       $indexes = [];
       foreach ($this->indexes() as $i) {
-        if (empty($i['unique'])) $indexes[$i['field']] = 1;
+        if (empty($i['unique']) and empty($i['key'])) $indexes[$i['field']] = 1;
       }
 
       foreach ($rows as $row) {