Пример #1
0
 /**
  * Add a foreign key to table and defer its foreign key creation.
  *
  * @param string $fk
  * @param string $column
  * @param string $keyName
  * @param string $onDelete
  * @param string $onUpdate
  * @return \Illuminate\Support\Fluent
  */
 public function add($fk, $column = null, $keyName = null, $onDelete = null, $onUpdate = null)
 {
     $baseFk = $this->baseFk($fk);
     $column = $column ?: $baseFk->defaultColumn();
     static::$foreignKeys[] = ['column' => $column ?: $this->column, 'key_name' => $keyName ?: $this->keyName, 'table' => $this->table->getTable(), 'reference_table' => $baseFk->referenceTable(), 'primary_key' => $baseFk->primaryKey, 'on_delete' => $onDelete ?: $this->onDelete ?: $baseFk->onDelete, 'on_update' => $onUpdate ?: $this->onUpdate ?: $baseFk->onUpdate];
     return $baseFk->createFkColumn($column);
 }
 /**
  * Execute the blueprint to build / modify the table.
  *
  * @param  \Cooperl\Database\DB2\Schema\Blueprint  $blueprint
  * @return void
  */
 protected function build(Blueprint $blueprint)
 {
     $schemaTable = explode(".", $blueprint->getTable());
     if (count($schemaTable) > 1) {
         $this->connection->setCurrentSchema($schemaTable[0]);
     }
     $blueprint->build($this->connection, $this->grammar);
     $this->connection->resetCurrentSchema();
 }
 /**
  * Add the field type column.
  *
  * @param Blueprint           $table
  * @param AssignmentInterface $assignment
  */
 public function addColumn(Blueprint $table, AssignmentInterface $assignment)
 {
     // Skip if the column already exists.
     if ($this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName() . '_id')) {
         return;
     }
     $table->string($this->fieldType->getColumnName() . '_type')->nullable(!$assignment->isRequired());
     $table->integer($this->fieldType->getColumnName() . '_id')->nullable(!$assignment->isRequired());
     if ($assignment->isUnique() && $assignment->isTranslatable()) {
         $table->unique([$this->fieldType->getColumnName() . '_type', $this->fieldType->getColumnName() . '_id']);
     }
 }
 /**
  * @param Blueprint           $table
  * @param AssignmentInterface $assignment
  */
 public function addColumn(Blueprint $table, AssignmentInterface $assignment)
 {
     // Skip if the column already exists.
     if ($this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
         return;
     }
     /**
      * Add the column to the table.
      *
      * @var Blueprint|Fluent $column
      */
     $column = $table->{$this->fieldType->getColumnType()}($this->fieldType->getColumnName(), 11, array_get($this->fieldType->getConfig(), 'decimals', 2))->nullable(!$assignment->isTranslatable() ? !$assignment->isRequired() : true);
     if (!str_contains($this->fieldType->getColumnType(), ['text', 'blob'])) {
         $column->default(array_get($this->fieldType->getConfig(), 'default_value'));
     }
     // Mark the column unique if desired and not translatable.
     if ($assignment->isUnique() && !$assignment->isTranslatable()) {
         $table->unique($this->fieldType->getColumnName());
     }
 }
Пример #5
0
 /**
  * Create an empty Doctrine DBAL TableDiff from the Blueprint.
  *
  * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
  * @param  \Doctrine\DBAL\Schema\AbstractSchemaManager  $schema
  * @return \Doctrine\DBAL\Schema\TableDiff
  */
 protected function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema)
 {
     $table = $this->getTablePrefix() . $blueprint->getTable();
     $tableDiff = new TableDiff($table);
     $tableDiff->fromTable = $schema->listTableDetails($table);
     return $tableDiff;
 }
Пример #6
0
 /**
  * Compile a drop primary key command.
  *
  * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
  * @param  \Illuminate\Support\Fluent  $command
  * @return string
  */
 public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
 {
     $table = $blueprint->getTable();
     $index = $this->wrap("{$table}_pkey");
     return 'alter table ' . $this->wrapTable($blueprint) . " drop constraint {$index}";
 }
Пример #7
0
 /**
  * Compile a drop primary key command.
  *
  * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
  * @param  \Illuminate\Support\Fluent  $command
  * @return string
  */
 public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
 {
     $table = $blueprint->getTable();
     $table = $this->wrapTable($blueprint);
     return "alter table {$table} drop constraint {$command->index}";
 }
Пример #8
0
 /**
  * Compile a drop table (if exists) command.
  *
  * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
  * @param  \Illuminate\Support\Fluent  $command
  * @return string
  */
 public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
 {
     return 'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = \'' . $blueprint->getTable() . '\') drop table [' . $blueprint->getTable() . ']';
 }
 /**
  * Get the Doctrine table difference for the given changes.
  *
  * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
  * @param  \Doctrine\DBAL\Schema\AbstractSchemaManager  $schema
  * @return \Doctrine\DBAL\Schema\TableDiff|bool
  */
 protected function getChangedDiff(Blueprint $blueprint, SchemaManager $schema)
 {
     $table = $schema->listTableDetails($this->getTablePrefix() . $blueprint->getTable());
     return (new Comparator())->diffTable($table, $this->getTableWithColumnChanges($blueprint, $table));
 }
 /**
  * Get the SQL for an auto-increment column modifier.
  *
  * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
  * @param  \Illuminate\Support\Fluent  $column
  * @return string|null
  */
 protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
 {
     if (in_array($column->type, $this->serials) && $column->autoIncrement) {
         return ' as identity constraint ' . $blueprint->getTable() . '_' . $column->name . '_primary primary key';
     }
 }
 /**
  * Drop the field type column from the table.
  *
  * @param Blueprint $table
  */
 public function dropColumn(Blueprint $table)
 {
     // Skip if no column type.
     if (!$this->fieldType->getColumnType()) {
         return;
     }
     // Skip if the column doesn't exist.
     if (!$this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
         return;
     }
     // Drop dat 'ole column.
     $table->dropColumn($this->fieldType->getColumnName());
 }
Пример #12
0
 /**
  * Compile a drop table (if exists) command.
  *
  * @param  \Illuminate\Database\Schema\Blueprint  $blueprint
  * @param  \Illuminate\Support\Fluent  $command
  * @return string
  */
 public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
 {
     $table = "'" . str_replace("'", "''", $this->getTablePrefix() . $blueprint->getTable()) . "'";
     return 'if exists (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = ' . $table . ') drop table ' . $this->wrapTable($blueprint);
 }
Пример #13
0
 /**
  * Restore the field type column to cache.
  *
  * @param Blueprint $table
  */
 public function restoreColumn(Blueprint $table)
 {
     // Skip if no column type.
     if (!$this->fieldType->getColumnType()) {
         return;
     }
     // Skip if the column doesn't exist.
     if (!$this->schema->hasColumn($table->getTable(), $this->fieldType->getColumnName())) {
         return;
     }
     // Translatable or no?
     $translatable = ends_with($table->getTable(), '_translations');
     // Restore the data.
     $results = $this->cache->get(__CLASS__ . $this->fieldType->getColumnName());
     foreach ($results as $result) {
         $result = (array) $result;
         $this->connection->table($table->getTable())->where($translatable ? 'entry_id' : 'id', array_pull($result, 'id'))->update($result);
     }
     $this->cache->forget(__CLASS__ . $this->fieldType->getColumnName());
 }
 /**
  * Drop the pivot table.
  *
  * @param Blueprint $table
  */
 public function dropColumn(Blueprint $table)
 {
     $this->schema->dropIfExists($table->getTable() . '_' . $this->fieldType->getField());
 }