Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function execute(ContextInterface $context)
 {
     $schema = $context->getSchema($this->getDatabase(), $this->getTable());
     if (!$schema->hasForeign($this->column)) {
         throw new ReferenceException("Unable to drop foreign key '{$schema->getName()}'.'{$this->column}', " . "foreign key does not exists");
     }
     $schema->dropForeign($this->column);
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function execute(ContextInterface $context)
 {
     $schema = $context->getSchema($this->getDatabase(), $this->getTable());
     $database = !empty($this->database) ? $this->database : '[default]';
     if (!$schema->exists()) {
         throw new TableException("Unable to update table '{$database}'.'{$this->getTable()}', no table exists");
     }
     $schema->save(true, true, true);
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function execute(ContextInterface $context)
 {
     $schema = $context->getSchema($this->getDatabase(), $this->getTable());
     if ($schema->hasColumn($this->name)) {
         throw new ColumnException("Unable to create column '{$schema->getName()}'.'{$this->name}', column already exists");
     }
     //Declaring column
     $this->declareColumn($schema);
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function execute(ContextInterface $context)
 {
     $schema = $context->getSchema($this->getDatabase(), $this->getTable());
     if (!$schema->hasIndex($this->columns)) {
         $columns = join(',', $this->columns);
         throw new IndexException("Unable to drop index '{$schema->getName()}'.({$columns}), index does not exists");
     }
     $schema->dropIndex($this->columns);
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function execute(ContextInterface $context)
 {
     $schema = $context->getSchema($this->getDatabase(), $this->getTable());
     if (!$schema->hasColumn($this->name)) {
         throw new ColumnException("Unable to drop column '{$schema->getName()}'.'{$this->name}', column does not exists");
     }
     //Declaring column
     $schema->dropColumn($this->name);
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  */
 public function execute(ContextInterface $context)
 {
     $schema = $context->getSchema($this->getDatabase(), $this->getTable());
     if ($schema->hasIndex($this->columns)) {
         $columns = join(',', $this->columns);
         throw new IndexException("Unable to create index '{$schema->getName()}'.({$columns}), index already exists");
     }
     $schema->index($this->columns)->unique($this->getOption('unique', false));
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  */
 public function execute(ContextInterface $context)
 {
     $schema = $context->getSchema($this->getDatabase(), $this->getTable());
     $database = !empty($this->database) ? $this->database : '[default]';
     if ($schema->exists()) {
         throw new TableException("Unable to set primary keys for table '{$database}'.'{$this->getTable()}', table already exists");
     }
     $schema->setPrimaryKeys($this->columns);
 }
Exemple #8
0
 /**
  * {@inheritdoc}
  */
 public function execute(ContextInterface $context)
 {
     $schema = $context->getSchema($this->getDatabase(), $this->getTable());
     $database = !empty($this->database) ? $this->database : '[default]';
     if ($schema->exists()) {
         throw new TableException("Unable to create table '{$database}'.'{$this->getTable()}', table already exists");
     }
     if (empty($schema->getColumns())) {
         throw new TableException("Unable to create table '{$database}'.'{$this->getTable()}', no columns were added");
     }
     $schema->save(true, true, true);
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  */
 public function execute(ContextInterface $context)
 {
     $schema = $context->getSchema($this->getDatabase(), $this->getTable());
     $database = !empty($this->database) ? $this->database : '[default]';
     if (!$schema->exists()) {
         throw new TableException("Unable to rename table '{$database}'.'{$this->getTable()}', table does not exists");
     }
     if ($context->getDatabase($this->getDatabase())->hasTable($this->newName)) {
         throw new TableException("Unable to rename table '{$database}'.'{$this->getTable()}', table '{$this->newName}' already exists");
     }
     $schema->setName($this->newName);
     $schema->save();
 }
Exemple #10
0
 /**
  * {@inheritdoc}
  */
 public function execute(ContextInterface $context)
 {
     $schema = $context->getSchema($this->getDatabase(), $this->getTable());
     if (!$schema->hasForeign($this->column)) {
         throw new ReferenceException("Unable to alter foreign key '{$schema->getName()}'.({$this->column}), " . "foreign does not exists");
     }
     $outerSchema = $context->getSchema($this->database, $this->foreignTable);
     if ($this->foreignTable != $this->table && !$outerSchema->exists()) {
         throw new ReferenceException("Unable to alter foreign key '{$schema->getName()}'.'{$this->column}', " . "foreign table '{$this->foreignTable}' does not exists");
     }
     if ($this->foreignTable != $this->table && !$outerSchema->hasColumn($this->foreignKey)) {
         throw new ReferenceException("Unable to alter foreign key '{$schema->getName()}'.'{$this->column}'," . " foreign column '{$this->foreignTable}'.'{$this->foreignKey}' does not exists");
     }
     $foreignKey = $schema->foreign($this->column)->references($this->foreignTable, $this->foreignKey);
     /*
      * We are allowing both formats "NO_ACTION" and "NO ACTION".
      */
     $foreignKey->onDelete(str_replace('_', ' ', $this->getOption('delete', AbstractReference::NO_ACTION)));
     $foreignKey->onUpdate(str_replace('_', ' ', $this->getOption('update', AbstractReference::NO_ACTION)));
 }
Exemple #11
0
 /**
  * Execute blueprint operations.
  */
 private function execute()
 {
     $this->context->execute($this->operations);
 }