Exemplo n.º 1
0
 /**
  * @covers ::isPrimaryKey
  */
 public function testIsPrimaryKey()
 {
     $columns = new ColumnCollection();
     $this->assertSame(0, $columns->isPrimaryKey()->count());
     $columns->add(new Column(['Field' => null, 'Type' => null, 'Collation' => null, 'Null' => null, 'Key' => null, 'Default' => null, 'Extra' => null]));
     $this->assertSame(0, $columns->isPrimaryKey()->count());
     $columns->add(new Column(['Field' => 'foo', 'Type' => null, 'Collation' => null, 'Null' => null, 'Key' => 'PRI', 'Default' => null, 'Extra' => null]));
     $this->assertSame(1, $columns->isPrimaryKey()->count());
 }
Exemplo n.º 2
0
 /**
  * Check for redundant indices on primary key column
  *
  * @param ColumnCollection $columns Table columns
  * @param IndexCollection  $indices Table indices
  *
  * @return array Result
  */
 public function checkRedundantIndicesOnPrimaryKey(ColumnCollection $columns, IndexCollection $indices)
 {
     $result = [];
     /**
      * Check primary key columns
      */
     foreach ($columns->isPrimaryKey() as $column) {
         $colums = [$column->getField()];
         /**
          * Check non primary key indices
          */
         foreach ($indices->isNotPrimaryKey() as $index) {
             /**
              * Check indices with just our primary key column
              */
             if ($index->isColumnsEqual($colums) === true) {
                 $indexType = $index->isUnique() === true ? 'unique' : 'key';
                 /**
                  * Check if index is unique
                  */
                 $result[] = ['type' => 'index', 'key' => $index->getKeyName(), 'description' => sprintf('An %s index on the primary key column is redundant', $indexType)];
             }
         }
     }
     return $result;
 }