Example #1
0
 public function test()
 {
     $constraint = new Index('foo', 'column');
     $this->assertSame('foo', $constraint->getName());
     $this->assertSame('KEY `foo` (`column`)', $constraint->buildCreate());
     $this->assertSame('ADD INDEX `foo` (`column`)', $constraint->buildAdd());
     $this->assertSame('DROP INDEX `foo`', $constraint->buildDrop());
     $constraint = new Index('foo', 'column', 'column2');
     $this->assertSame('foo', $constraint->getName());
     $this->assertSame('KEY `foo` (`column`, `column2`)', $constraint->buildCreate());
     $this->assertSame('ADD INDEX `foo` (`column`, `column2`)', $constraint->buildAdd());
     $this->assertSame('DROP INDEX `foo`', $constraint->buildDrop());
 }
Example #2
0
 public final function setIndexObject(Index $index) : TableInterface
 {
     if ($this->isImmutable()) {
         throw SchemaException::immutable(static::class);
     }
     if ($this->hasIndex($index->getName())) {
         throw SchemaException::indexAlreadySet(static::class, $index->getName());
     }
     $missing = array_diff($index->getColumns(), array_keys($this->getColumns()));
     if ($missing !== []) {
         throw TableException::columnNotSet(static::class, implode(', ', $missing));
     }
     $this->indexes[$index->getName()] = $index;
     return $this;
 }