Added vendor/ directory for Composer's installed files
This commit is contained in:
923
vendor/illuminate/database/Schema/Blueprint.php
vendored
Executable file
923
vendor/illuminate/database/Schema/Blueprint.php
vendored
Executable file
@ -0,0 +1,923 @@
|
||||
<?php namespace Illuminate\Database\Schema;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Schema\Grammars\Grammar;
|
||||
|
||||
class Blueprint {
|
||||
|
||||
/**
|
||||
* The table the blueprint describes.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* The columns that should be added to the table.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $columns = array();
|
||||
|
||||
/**
|
||||
* The commands that should be run for the table.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = array();
|
||||
|
||||
/**
|
||||
* The storage engine that should be used for the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $engine;
|
||||
|
||||
/**
|
||||
* Create a new schema blueprint.
|
||||
*
|
||||
* @param string $table
|
||||
* @param \Closure|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($table, Closure $callback = null)
|
||||
{
|
||||
$this->table = $table;
|
||||
|
||||
if ( ! is_null($callback)) $callback($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the blueprint against the database.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return void
|
||||
*/
|
||||
public function build(Connection $connection, Grammar $grammar)
|
||||
{
|
||||
foreach ($this->toSql($connection, $grammar) as $statement)
|
||||
{
|
||||
$connection->statement($statement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw SQL statements for the blueprint.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @param \Illuminate\Database\Schema\Grammars\Grammar $grammar
|
||||
* @return array
|
||||
*/
|
||||
public function toSql(Connection $connection, Grammar $grammar)
|
||||
{
|
||||
$this->addImpliedCommands();
|
||||
|
||||
$statements = array();
|
||||
|
||||
// Each type of command has a corresponding compiler function on the schema
|
||||
// grammar which is used to build the necessary SQL statements to build
|
||||
// the blueprint element, so we'll just call that compilers function.
|
||||
foreach ($this->commands as $command)
|
||||
{
|
||||
$method = 'compile'.ucfirst($command->name);
|
||||
|
||||
if (method_exists($grammar, $method))
|
||||
{
|
||||
if ( ! is_null($sql = $grammar->$method($this, $command, $connection)))
|
||||
{
|
||||
$statements = array_merge($statements, (array) $sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the commands that are implied by the blueprint.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addImpliedCommands()
|
||||
{
|
||||
if (count($this->getAddedColumns()) > 0 && ! $this->creating())
|
||||
{
|
||||
array_unshift($this->commands, $this->createCommand('add'));
|
||||
}
|
||||
|
||||
if (count($this->getChangedColumns()) > 0 && ! $this->creating())
|
||||
{
|
||||
array_unshift($this->commands, $this->createCommand('change'));
|
||||
}
|
||||
|
||||
$this->addFluentIndexes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the index commands fluently specified on columns.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function addFluentIndexes()
|
||||
{
|
||||
foreach ($this->columns as $column)
|
||||
{
|
||||
foreach (array('primary', 'unique', 'index') as $index)
|
||||
{
|
||||
// If the index has been specified on the given column, but is simply
|
||||
// equal to "true" (boolean), no name has been specified for this
|
||||
// index, so we will simply call the index methods without one.
|
||||
if ($column->$index === true)
|
||||
{
|
||||
$this->$index($column->name);
|
||||
|
||||
continue 2;
|
||||
}
|
||||
|
||||
// If the index has been specified on the column and it is something
|
||||
// other than boolean true, we will assume a name was provided on
|
||||
// the index specification, and pass in the name to the method.
|
||||
elseif (isset($column->$index))
|
||||
{
|
||||
$this->$index($column->name, $column->$index);
|
||||
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the blueprint has a create command.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function creating()
|
||||
{
|
||||
foreach ($this->commands as $command)
|
||||
{
|
||||
if ($command->name == 'create') return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the table needs to be created.
|
||||
*
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return $this->addCommand('create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the table should be dropped.
|
||||
*
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function drop()
|
||||
{
|
||||
return $this->addCommand('drop');
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the table should be dropped if it exists.
|
||||
*
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropIfExists()
|
||||
{
|
||||
return $this->addCommand('dropIfExists');
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given columns should be dropped.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropColumn($columns)
|
||||
{
|
||||
$columns = is_array($columns) ? $columns : (array) func_get_args();
|
||||
|
||||
return $this->addCommand('dropColumn', compact('columns'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given columns should be renamed.
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function renameColumn($from, $to)
|
||||
{
|
||||
return $this->addCommand('renameColumn', compact('from', 'to'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given primary key should be dropped.
|
||||
*
|
||||
* @param string|array $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropPrimary($index = null)
|
||||
{
|
||||
return $this->dropIndexCommand('dropPrimary', 'primary', $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given unique key should be dropped.
|
||||
*
|
||||
* @param string|array $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropUnique($index)
|
||||
{
|
||||
return $this->dropIndexCommand('dropUnique', 'unique', $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given index should be dropped.
|
||||
*
|
||||
* @param string|array $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropIndex($index)
|
||||
{
|
||||
return $this->dropIndexCommand('dropIndex', 'index', $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the given foreign key should be dropped.
|
||||
*
|
||||
* @param string $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dropForeign($index)
|
||||
{
|
||||
return $this->dropIndexCommand('dropForeign', 'foreign', $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the timestamp columns should be dropped.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropTimestamps()
|
||||
{
|
||||
$this->dropColumn('created_at', 'updated_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the soft delete column should be dropped.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function dropSoftDeletes()
|
||||
{
|
||||
$this->dropColumn('deleted_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename the table to a given name.
|
||||
*
|
||||
* @param string $to
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function rename($to)
|
||||
{
|
||||
return $this->addCommand('rename', compact('to'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the primary key(s) for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function primary($columns, $name = null)
|
||||
{
|
||||
return $this->indexCommand('primary', $columns, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a unique index for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function unique($columns, $name = null)
|
||||
{
|
||||
return $this->indexCommand('unique', $columns, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify an index for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function index($columns, $name = null)
|
||||
{
|
||||
return $this->indexCommand('index', $columns, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a foreign key for the table.
|
||||
*
|
||||
* @param string|array $columns
|
||||
* @param string $name
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function foreign($columns, $name = null)
|
||||
{
|
||||
return $this->indexCommand('foreign', $columns, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new auto-incrementing integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function increments($column)
|
||||
{
|
||||
return $this->unsignedInteger($column, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new auto-incrementing big integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function bigIncrements($column)
|
||||
{
|
||||
return $this->unsignedBigInteger($column, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new char column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $length
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function char($column, $length = 255)
|
||||
{
|
||||
return $this->addColumn('char', $column, compact('length'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new string column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $length
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function string($column, $length = 255)
|
||||
{
|
||||
return $this->addColumn('string', $column, compact('length'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new text column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function text($column)
|
||||
{
|
||||
return $this->addColumn('text', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new medium text column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function mediumText($column)
|
||||
{
|
||||
return $this->addColumn('mediumText', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new long text column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function longText($column)
|
||||
{
|
||||
return $this->addColumn('longText', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function integer($column, $autoIncrement = false, $unsigned = false)
|
||||
{
|
||||
return $this->addColumn('integer', $column, compact('autoIncrement', 'unsigned'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new big integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function bigInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
{
|
||||
return $this->addColumn('bigInteger', $column, compact('autoIncrement', 'unsigned'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new medium integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function mediumInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
{
|
||||
return $this->addColumn('mediumInteger', $column, compact('autoIncrement', 'unsigned'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new tiny integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function tinyInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
{
|
||||
return $this->addColumn('tinyInteger', $column, compact('autoIncrement', 'unsigned'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new small integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @param bool $unsigned
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function smallInteger($column, $autoIncrement = false, $unsigned = false)
|
||||
{
|
||||
return $this->addColumn('smallInteger', $column, compact('autoIncrement', 'unsigned'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new unsigned integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function unsignedInteger($column, $autoIncrement = false)
|
||||
{
|
||||
return $this->integer($column, $autoIncrement, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new unsigned big integer column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param bool $autoIncrement
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function unsignedBigInteger($column, $autoIncrement = false)
|
||||
{
|
||||
return $this->bigInteger($column, $autoIncrement, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new float column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $total
|
||||
* @param int $places
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function float($column, $total = 8, $places = 2)
|
||||
{
|
||||
return $this->addColumn('float', $column, compact('total', 'places'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new double column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int|null $total
|
||||
* @param int|null $places
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function double($column, $total = null, $places = null)
|
||||
{
|
||||
return $this->addColumn('double', $column, compact('total', 'places'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new decimal column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param int $total
|
||||
* @param int $places
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function decimal($column, $total = 8, $places = 2)
|
||||
{
|
||||
return $this->addColumn('decimal', $column, compact('total', 'places'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new boolean column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function boolean($column)
|
||||
{
|
||||
return $this->addColumn('boolean', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new enum column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @param array $allowed
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function enum($column, array $allowed)
|
||||
{
|
||||
return $this->addColumn('enum', $column, compact('allowed'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new json column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function json($column)
|
||||
{
|
||||
return $this->addColumn('json', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new jsonb column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function jsonb($column)
|
||||
{
|
||||
return $this->addColumn('jsonb', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new date column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function date($column)
|
||||
{
|
||||
return $this->addColumn('date', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new date-time column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dateTime($column)
|
||||
{
|
||||
return $this->addColumn('dateTime', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new date-time column (with time zone) on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function dateTimeTz($column)
|
||||
{
|
||||
return $this->addColumn('dateTimeTz', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new time column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function time($column)
|
||||
{
|
||||
return $this->addColumn('time', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new time column (with time zone) on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function timeTz($column)
|
||||
{
|
||||
return $this->addColumn('timeTz', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new timestamp column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function timestamp($column)
|
||||
{
|
||||
return $this->addColumn('timestamp', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new timestamp (with time zone) column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function timestampTz($column)
|
||||
{
|
||||
return $this->addColumn('timestampTz', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add nullable creation and update timestamps to the table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function nullableTimestamps()
|
||||
{
|
||||
$this->timestamp('created_at')->nullable();
|
||||
|
||||
$this->timestamp('updated_at')->nullable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add creation and update timestamps to the table.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function timestamps()
|
||||
{
|
||||
$this->timestamp('created_at');
|
||||
|
||||
$this->timestamp('updated_at');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a "deleted at" timestamp for the table.
|
||||
*
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function softDeletes()
|
||||
{
|
||||
return $this->timestamp('deleted_at')->nullable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new binary column on the table.
|
||||
*
|
||||
* @param string $column
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function binary($column)
|
||||
{
|
||||
return $this->addColumn('binary', $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the proper columns for a polymorphic table.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string|null $indexName
|
||||
* @return void
|
||||
*/
|
||||
public function morphs($name, $indexName = null)
|
||||
{
|
||||
$this->unsignedInteger("{$name}_id");
|
||||
|
||||
$this->string("{$name}_type");
|
||||
|
||||
$this->index(array("{$name}_id", "{$name}_type"), $indexName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the `remember_token` column to the table.
|
||||
*
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
public function rememberToken()
|
||||
{
|
||||
return $this->string('remember_token', 100)->nullable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new drop index command on the blueprint.
|
||||
*
|
||||
* @param string $command
|
||||
* @param string $type
|
||||
* @param string|array $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
protected function dropIndexCommand($command, $type, $index)
|
||||
{
|
||||
$columns = array();
|
||||
|
||||
// If the given "index" is actually an array of columns, the developer means
|
||||
// to drop an index merely by specifying the columns involved without the
|
||||
// conventional name, so we will build the index name from the columns.
|
||||
if (is_array($index))
|
||||
{
|
||||
$columns = $index;
|
||||
|
||||
$index = $this->createIndexName($type, $columns);
|
||||
}
|
||||
|
||||
return $this->indexCommand($command, $columns, $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new index command to the blueprint.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string|array $columns
|
||||
* @param string $index
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
protected function indexCommand($type, $columns, $index)
|
||||
{
|
||||
$columns = (array) $columns;
|
||||
|
||||
// If no name was specified for this index, we will create one using a basic
|
||||
// convention of the table name, followed by the columns, followed by an
|
||||
// index type, such as primary or index, which makes the index unique.
|
||||
if (is_null($index))
|
||||
{
|
||||
$index = $this->createIndexName($type, $columns);
|
||||
}
|
||||
|
||||
return $this->addCommand($type, compact('index', 'columns'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a default index name for the table.
|
||||
*
|
||||
* @param string $type
|
||||
* @param array $columns
|
||||
* @return string
|
||||
*/
|
||||
protected function createIndexName($type, array $columns)
|
||||
{
|
||||
$index = strtolower($this->table.'_'.implode('_', $columns).'_'.$type);
|
||||
|
||||
return str_replace(array('-', '.'), '_', $index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new column to the blueprint.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
protected function addColumn($type, $name, array $parameters = array())
|
||||
{
|
||||
$attributes = array_merge(compact('type', 'name'), $parameters);
|
||||
|
||||
$this->columns[] = $column = new Fluent($attributes);
|
||||
|
||||
return $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a column from the schema blueprint.
|
||||
*
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function removeColumn($name)
|
||||
{
|
||||
$this->columns = array_values(array_filter($this->columns, function($c) use ($name)
|
||||
{
|
||||
return $c['attributes']['name'] != $name;
|
||||
}));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new command to the blueprint.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
protected function addCommand($name, array $parameters = array())
|
||||
{
|
||||
$this->commands[] = $command = $this->createCommand($name, $parameters);
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Fluent command.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $parameters
|
||||
* @return \Illuminate\Support\Fluent
|
||||
*/
|
||||
protected function createCommand($name, array $parameters = array())
|
||||
{
|
||||
return new Fluent(array_merge(compact('name'), $parameters));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the table the blueprint describes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTable()
|
||||
{
|
||||
return $this->table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the columns on the blueprint.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getColumns()
|
||||
{
|
||||
return $this->columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the commands on the blueprint.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCommands()
|
||||
{
|
||||
return $this->commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the columns on the blueprint that should be added.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddedColumns()
|
||||
{
|
||||
return array_filter($this->columns, function($column)
|
||||
{
|
||||
return !$column->change;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the columns on the blueprint that should be changed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getChangedColumns()
|
||||
{
|
||||
return array_filter($this->columns, function($column)
|
||||
{
|
||||
return !!$column->change;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
242
vendor/illuminate/database/Schema/Builder.php
vendored
Executable file
242
vendor/illuminate/database/Schema/Builder.php
vendored
Executable file
@ -0,0 +1,242 @@
|
||||
<?php namespace Illuminate\Database\Schema;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Database\Connection;
|
||||
|
||||
class Builder {
|
||||
|
||||
/**
|
||||
* The database connection instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* The schema grammar instance.
|
||||
*
|
||||
* @var \Illuminate\Database\Schema\Grammars\Grammar
|
||||
*/
|
||||
protected $grammar;
|
||||
|
||||
/**
|
||||
* The Blueprint resolver callback.
|
||||
*
|
||||
* @var \Closure
|
||||
*/
|
||||
protected $resolver;
|
||||
|
||||
/**
|
||||
* Create a new database Schema manager.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->grammar = $connection->getSchemaGrammar();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given table exists.
|
||||
*
|
||||
* @param string $table
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTable($table)
|
||||
{
|
||||
$sql = $this->grammar->compileTableExists();
|
||||
|
||||
$table = $this->connection->getTablePrefix().$table;
|
||||
|
||||
return count($this->connection->select($sql, array($table))) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given table has a given column.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $column
|
||||
* @return bool
|
||||
*/
|
||||
public function hasColumn($table, $column)
|
||||
{
|
||||
$column = strtolower($column);
|
||||
|
||||
return in_array($column, array_map('strtolower', $this->getColumnListing($table)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given table has given columns.
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $columns
|
||||
* @return bool
|
||||
*/
|
||||
public function hasColumns($table, array $columns)
|
||||
{
|
||||
$tableColumns = array_map('strtolower', $this->getColumnListing($table));
|
||||
|
||||
foreach ($columns as $column)
|
||||
{
|
||||
if ( ! in_array(strtolower($column), $tableColumns)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column listing for a given table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function getColumnListing($table)
|
||||
{
|
||||
$table = $this->connection->getTablePrefix().$table;
|
||||
|
||||
$results = $this->connection->select($this->grammar->compileColumnExists($table));
|
||||
|
||||
return $this->connection->getPostProcessor()->processColumnListing($results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify a table on the schema.
|
||||
*
|
||||
* @param string $table
|
||||
* @param \Closure $callback
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
public function table($table, Closure $callback)
|
||||
{
|
||||
$this->build($this->createBlueprint($table, $callback));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new table on the schema.
|
||||
*
|
||||
* @param string $table
|
||||
* @param \Closure $callback
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
public function create($table, Closure $callback)
|
||||
{
|
||||
$blueprint = $this->createBlueprint($table);
|
||||
|
||||
$blueprint->create();
|
||||
|
||||
$callback($blueprint);
|
||||
|
||||
$this->build($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop a table from the schema.
|
||||
*
|
||||
* @param string $table
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
public function drop($table)
|
||||
{
|
||||
$blueprint = $this->createBlueprint($table);
|
||||
|
||||
$blueprint->drop();
|
||||
|
||||
$this->build($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop a table from the schema if it exists.
|
||||
*
|
||||
* @param string $table
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
public function dropIfExists($table)
|
||||
{
|
||||
$blueprint = $this->createBlueprint($table);
|
||||
|
||||
$blueprint->dropIfExists();
|
||||
|
||||
$this->build($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename a table on the schema.
|
||||
*
|
||||
* @param string $from
|
||||
* @param string $to
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
public function rename($from, $to)
|
||||
{
|
||||
$blueprint = $this->createBlueprint($from);
|
||||
|
||||
$blueprint->rename($to);
|
||||
|
||||
$this->build($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the blueprint to build / modify the table.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @return void
|
||||
*/
|
||||
protected function build(Blueprint $blueprint)
|
||||
{
|
||||
$blueprint->build($this->connection, $this->grammar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new command set with a Closure.
|
||||
*
|
||||
* @param string $table
|
||||
* @param \Closure|null $callback
|
||||
* @return \Illuminate\Database\Schema\Blueprint
|
||||
*/
|
||||
protected function createBlueprint($table, Closure $callback = null)
|
||||
{
|
||||
if (isset($this->resolver))
|
||||
{
|
||||
return call_user_func($this->resolver, $table, $callback);
|
||||
}
|
||||
|
||||
return new Blueprint($table, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the database connection instance.
|
||||
*
|
||||
* @return \Illuminate\Database\Connection
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the database connection instance.
|
||||
*
|
||||
* @param \Illuminate\Database\Connection
|
||||
* @return $this
|
||||
*/
|
||||
public function setConnection(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Schema Blueprint resolver callback.
|
||||
*
|
||||
* @param \Closure $resolver
|
||||
* @return void
|
||||
*/
|
||||
public function blueprintResolver(Closure $resolver)
|
||||
{
|
||||
$this->resolver = $resolver;
|
||||
}
|
||||
|
||||
}
|
458
vendor/illuminate/database/Schema/Grammars/Grammar.php
vendored
Executable file
458
vendor/illuminate/database/Schema/Grammars/Grammar.php
vendored
Executable file
@ -0,0 +1,458 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Illuminate\Support\Fluent;
|
||||
use Doctrine\DBAL\Schema\Table;
|
||||
use Doctrine\DBAL\Schema\Column;
|
||||
use Doctrine\DBAL\Schema\TableDiff;
|
||||
use Illuminate\Database\Connection;
|
||||
use Doctrine\DBAL\Schema\Comparator;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Grammar as BaseGrammar;
|
||||
use Doctrine\DBAL\Schema\AbstractSchemaManager as SchemaManager;
|
||||
|
||||
abstract class Grammar extends BaseGrammar {
|
||||
|
||||
/**
|
||||
* Compile a rename column command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return array
|
||||
*/
|
||||
public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
|
||||
{
|
||||
$schema = $connection->getDoctrineSchemaManager();
|
||||
|
||||
$table = $this->getTablePrefix().$blueprint->getTable();
|
||||
|
||||
$column = $connection->getDoctrineColumn($table, $command->from);
|
||||
|
||||
$tableDiff = $this->getRenamedDiff($blueprint, $command, $column, $schema);
|
||||
|
||||
return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new column instance with the new column name.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Doctrine\DBAL\Schema\Column $column
|
||||
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
*/
|
||||
protected function getRenamedDiff(Blueprint $blueprint, Fluent $command, Column $column, SchemaManager $schema)
|
||||
{
|
||||
$tableDiff = $this->getDoctrineTableDiff($blueprint, $schema);
|
||||
|
||||
return $this->setRenamedColumns($tableDiff, $command, $column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the renamed columns on the table diff.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\TableDiff $tableDiff
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Doctrine\DBAL\Schema\Column $column
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
*/
|
||||
protected function setRenamedColumns(TableDiff $tableDiff, Fluent $command, Column $column)
|
||||
{
|
||||
$newColumn = new Column($command->to, $column->getType(), $column->toArray());
|
||||
|
||||
$tableDiff->renamedColumns = array($command->from => $newColumn);
|
||||
|
||||
return $tableDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a foreign key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileForeign(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$on = $this->wrapTable($command->on);
|
||||
|
||||
// We need to prepare several of the elements of the foreign key definition
|
||||
// before we can create the SQL, such as wrapping the tables and convert
|
||||
// an array of columns to comma-delimited strings for the SQL queries.
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$onColumns = $this->columnize((array) $command->references);
|
||||
|
||||
$sql = "alter table {$table} add constraint {$command->index} ";
|
||||
|
||||
$sql .= "foreign key ({$columns}) references {$on} ({$onColumns})";
|
||||
|
||||
// Once we have the basic foreign key creation statement constructed we can
|
||||
// build out the syntax for what should happen on an update or delete of
|
||||
// the affected columns, which will get something like "cascade", etc.
|
||||
if ( ! is_null($command->onDelete))
|
||||
{
|
||||
$sql .= " on delete {$command->onDelete}";
|
||||
}
|
||||
|
||||
if ( ! is_null($command->onUpdate))
|
||||
{
|
||||
$sql .= " on update {$command->onUpdate}";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the blueprint's column definitions.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @return array
|
||||
*/
|
||||
protected function getColumns(Blueprint $blueprint)
|
||||
{
|
||||
$columns = array();
|
||||
|
||||
foreach ($blueprint->getAddedColumns() as $column)
|
||||
{
|
||||
// Each of the column types have their own compiler functions which are tasked
|
||||
// with turning the column definition into its SQL format for this platform
|
||||
// used by the connection. The column's modifiers are compiled and added.
|
||||
$sql = $this->wrap($column).' '.$this->getType($column);
|
||||
|
||||
$columns[] = $this->addModifiers($sql, $blueprint, $column);
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the column modifiers to the definition.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function addModifiers($sql, Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
foreach ($this->modifiers as $modifier)
|
||||
{
|
||||
if (method_exists($this, $method = "modify{$modifier}"))
|
||||
{
|
||||
$sql .= $this->{$method}($blueprint, $column);
|
||||
}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primary key command if it exists on the blueprint.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param string $name
|
||||
* @return \Illuminate\Support\Fluent|null
|
||||
*/
|
||||
protected function getCommandByName(Blueprint $blueprint, $name)
|
||||
{
|
||||
$commands = $this->getCommandsByName($blueprint, $name);
|
||||
|
||||
if (count($commands) > 0)
|
||||
{
|
||||
return reset($commands);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the commands with a given name.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
protected function getCommandsByName(Blueprint $blueprint, $name)
|
||||
{
|
||||
return array_filter($blueprint->getCommands(), function($value) use ($name)
|
||||
{
|
||||
return $value->name == $name;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for the column data type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function getType(Fluent $column)
|
||||
{
|
||||
return $this->{"type".ucfirst($column->type)}($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a prefix to an array of values.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @param array $values
|
||||
* @return array
|
||||
*/
|
||||
public function prefixArray($prefix, array $values)
|
||||
{
|
||||
return array_map(function($value) use ($prefix)
|
||||
{
|
||||
return $prefix.' '.$value;
|
||||
|
||||
}, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a table in keyword identifiers.
|
||||
*
|
||||
* @param mixed $table
|
||||
* @return string
|
||||
*/
|
||||
public function wrapTable($table)
|
||||
{
|
||||
if ($table instanceof Blueprint) $table = $table->getTable();
|
||||
|
||||
return parent::wrapTable($table);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function wrap($value, $prefixAlias = false)
|
||||
{
|
||||
if ($value instanceof Fluent) $value = $value->name;
|
||||
|
||||
return parent::wrap($value, $prefixAlias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a value so that it can be used in "default" clauses.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
protected function getDefaultValue($value)
|
||||
{
|
||||
if ($value instanceof Expression) return $value;
|
||||
|
||||
if (is_bool($value)) return "'".(int) $value."'";
|
||||
|
||||
return "'".strval($value)."'";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a change column command into a series of SQL statements.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return array
|
||||
*/
|
||||
public function compileChange(Blueprint $blueprint, Fluent $command, Connection $connection)
|
||||
{
|
||||
$schema = $connection->getDoctrineSchemaManager();
|
||||
|
||||
$tableDiff = $this->getChangedDiff($blueprint, $schema);
|
||||
|
||||
if ($tableDiff !== false)
|
||||
{
|
||||
return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 a copy of the given Doctrine table after making the column changes.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @return \Doctrine\DBAL\Schema\TableDiff
|
||||
*/
|
||||
protected function getTableWithColumnChanges(Blueprint $blueprint, Table $table)
|
||||
{
|
||||
$table = clone $table;
|
||||
|
||||
foreach($blueprint->getChangedColumns() as $fluent)
|
||||
{
|
||||
$column = $this->getDoctrineColumnForChange($table, $fluent);
|
||||
|
||||
// Here we will spin through each fluent column definition and map it to the proper
|
||||
// Doctrine column definitions, which is necessasry because Laravel and Doctrine
|
||||
// use some different terminology for various column attributes on the tables.
|
||||
foreach ($fluent->getAttributes() as $key => $value)
|
||||
{
|
||||
if ( ! is_null($option = $this->mapFluentOptionToDoctrine($key)))
|
||||
{
|
||||
if (method_exists($column, $method = 'set'.ucfirst($option)))
|
||||
{
|
||||
$column->{$method}($this->mapFluentValueToDoctrine($option, $value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine column instance for a column change.
|
||||
*
|
||||
* @param \Doctrine\DBAL\Schema\Table $table
|
||||
* @param \Illuminate\Support\Fluent $fluent
|
||||
* @return \Doctrine\DBAL\Schema\Column
|
||||
*/
|
||||
protected function getDoctrineColumnForChange(Table $table, Fluent $fluent)
|
||||
{
|
||||
return $table->changeColumn(
|
||||
$fluent['name'], $this->getDoctrineColumnChangeOptions($fluent)
|
||||
)->getColumn($fluent['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Doctrine column change options.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $fluent
|
||||
* @return array
|
||||
*/
|
||||
protected function getDoctrineColumnChangeOptions(Fluent $fluent)
|
||||
{
|
||||
$options = ['type' => $this->getDoctrineColumnType($fluent['type'])];
|
||||
|
||||
if (in_array($fluent['type'], ['text', 'mediumText', 'longText']))
|
||||
{
|
||||
$options['length'] = $this->calculateDoctrineTextLength($fluent['type']);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the doctrine column type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return \Doctrine\DBAL\Types\Type
|
||||
*/
|
||||
protected function getDoctrineColumnType($type)
|
||||
{
|
||||
$type = strtolower($type);
|
||||
|
||||
switch ($type) {
|
||||
case 'biginteger':
|
||||
$type = 'bigint';
|
||||
break;
|
||||
case 'smallinteger':
|
||||
$type = 'smallint';
|
||||
break;
|
||||
case 'mediumtext':
|
||||
case 'longtext':
|
||||
$type = 'text';
|
||||
break;
|
||||
}
|
||||
|
||||
return Type::getType($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the proper column length to force the Doctrine text type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return int
|
||||
*/
|
||||
protected function calculateDoctrineTextLength($type)
|
||||
{
|
||||
switch ($type)
|
||||
{
|
||||
case 'mediumText':
|
||||
return 65535 + 1;
|
||||
|
||||
case 'longText':
|
||||
return 16777215 + 1;
|
||||
|
||||
default:
|
||||
return 255 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the matching Doctrine option for a given Fluent attribute name.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @return string
|
||||
*/
|
||||
protected function mapFluentOptionToDoctrine($attribute)
|
||||
{
|
||||
switch($attribute)
|
||||
{
|
||||
case 'type':
|
||||
case 'name':
|
||||
return;
|
||||
|
||||
case 'nullable':
|
||||
return 'notnull';
|
||||
|
||||
case 'total':
|
||||
return 'precision';
|
||||
|
||||
case 'places':
|
||||
return 'scale';
|
||||
|
||||
default:
|
||||
return $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the matching Doctrine value for a given Fluent attribute.
|
||||
*
|
||||
* @param string $option
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
protected function mapFluentValueToDoctrine($option, $value)
|
||||
{
|
||||
return $option == 'notnull' ? ! $value : $value;
|
||||
}
|
||||
|
||||
}
|
652
vendor/illuminate/database/Schema/Grammars/MySqlGrammar.php
vendored
Executable file
652
vendor/illuminate/database/Schema/Grammars/MySqlGrammar.php
vendored
Executable file
@ -0,0 +1,652 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class MySqlGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The possible column modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modifiers = array('Unsigned', 'Nullable', 'Default', 'Increment', 'Comment', 'After');
|
||||
|
||||
/**
|
||||
* The possible column serials.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $serials = array('bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger');
|
||||
|
||||
/**
|
||||
* Compile the query to determine the list of tables.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileTableExists()
|
||||
{
|
||||
return 'select * from information_schema.tables where table_schema = ? and table_name = ?';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the query to determine the list of columns.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileColumnExists()
|
||||
{
|
||||
return "select column_name from information_schema.columns where table_schema = ? and table_name = ?";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return string
|
||||
*/
|
||||
public function compileCreate(Blueprint $blueprint, Fluent $command, Connection $connection)
|
||||
{
|
||||
$columns = implode(', ', $this->getColumns($blueprint));
|
||||
|
||||
$sql = 'create table '.$this->wrapTable($blueprint)." ($columns)";
|
||||
|
||||
// Once we have the primary SQL, we can add the encoding option to the SQL for
|
||||
// the table. Then, we can check if a storage engine has been supplied for
|
||||
// the table. If so, we will add the engine declaration to the SQL query.
|
||||
$sql = $this->compileCreateEncoding($sql, $connection);
|
||||
|
||||
if (isset($blueprint->engine))
|
||||
{
|
||||
$sql .= ' engine = '.$blueprint->engine;
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the character set specifications to a command.
|
||||
*
|
||||
* @param string $sql
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return string
|
||||
*/
|
||||
protected function compileCreateEncoding($sql, Connection $connection)
|
||||
{
|
||||
if ( ! is_null($charset = $connection->getConfig('charset')))
|
||||
{
|
||||
$sql .= ' default character set '.$charset;
|
||||
}
|
||||
|
||||
if ( ! is_null($collation = $connection->getConfig('collation')))
|
||||
{
|
||||
$sql .= ' collate '.$collation;
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an add column command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileAdd(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$columns = $this->prefixArray('add', $this->getColumns($blueprint));
|
||||
|
||||
return 'alter table '.$table.' '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a primary key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compilePrimary(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$command->name(null);
|
||||
|
||||
return $this->compileKey($blueprint, $command, 'primary key');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return $this->compileKey($blueprint, $command, 'unique');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a plain index key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return $this->compileKey($blueprint, $command, 'index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile an index creation command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} add {$type} {$command->index}($columns)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDrop(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'drop table '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 'drop table if exists '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop column command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->prefixArray('drop', $this->wrapArray($command->columns));
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return 'alter table '.$table.' '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
return 'alter table '.$this->wrapTable($blueprint).' drop primary key';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop index {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop index command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop index {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop foreign key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop foreign key {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a rename table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileRename(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$from = $this->wrapTable($blueprint);
|
||||
|
||||
return "rename table {$from} to ".$this->wrapTable($command->to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a char type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeChar(Fluent $column)
|
||||
{
|
||||
return "char({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a string type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeString(Fluent $column)
|
||||
{
|
||||
return "varchar({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumText(Fluent $column)
|
||||
{
|
||||
return 'mediumtext';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a long text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeLongText(Fluent $column)
|
||||
{
|
||||
return 'longtext';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a big integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBigInteger(Fluent $column)
|
||||
{
|
||||
return 'bigint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeInteger(Fluent $column)
|
||||
{
|
||||
return 'int';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumInteger(Fluent $column)
|
||||
{
|
||||
return 'mediumint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a tiny integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTinyInteger(Fluent $column)
|
||||
{
|
||||
return 'tinyint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a small integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeSmallInteger(Fluent $column)
|
||||
{
|
||||
return 'smallint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a float type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeFloat(Fluent $column)
|
||||
{
|
||||
return $this->typeDouble($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a double type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDouble(Fluent $column)
|
||||
{
|
||||
if ($column->total && $column->places)
|
||||
{
|
||||
return "double({$column->total}, {$column->places})";
|
||||
}
|
||||
|
||||
return 'double';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a decimal type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDecimal(Fluent $column)
|
||||
{
|
||||
return "decimal({$column->total}, {$column->places})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a boolean type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBoolean(Fluent $column)
|
||||
{
|
||||
return 'tinyint(1)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for an enum type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeEnum(Fluent $column)
|
||||
{
|
||||
return "enum('".implode("', '", $column->allowed)."')";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a json type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJson(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a jsonb type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJsonb(Fluent $column)
|
||||
{
|
||||
return "text";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDate(Fluent $column)
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTime(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTimeTz(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTime(Fluent $column)
|
||||
{
|
||||
return 'time';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimeTz(Fluent $column)
|
||||
{
|
||||
return 'time';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestamp(Fluent $column)
|
||||
{
|
||||
if ( ! $column->nullable) return 'timestamp default 0';
|
||||
|
||||
return 'timestamp';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestampTz(Fluent $column)
|
||||
{
|
||||
if ( ! $column->nullable) return 'timestamp default 0';
|
||||
|
||||
return 'timestamp';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a binary type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBinary(Fluent $column)
|
||||
{
|
||||
return 'blob';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for an unsigned column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyUnsigned(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ($column->unsigned) return ' unsigned';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a nullable column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
return $column->nullable ? ' null' : ' not null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a default column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->default))
|
||||
{
|
||||
return " default ".$this->getDefaultValue($column->default);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ' auto_increment primary key';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for an "after" column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyAfter(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->after))
|
||||
{
|
||||
return ' after '.$this->wrap($column->after);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for an "comment" column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyComment(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->comment))
|
||||
{
|
||||
return ' comment "'.$column->comment.'"';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap a single string in keyword identifiers.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
protected function wrapValue($value)
|
||||
{
|
||||
if ($value === '*') return $value;
|
||||
|
||||
return '`'.str_replace('`', '``', $value).'`';
|
||||
}
|
||||
|
||||
}
|
544
vendor/illuminate/database/Schema/Grammars/PostgresGrammar.php
vendored
Executable file
544
vendor/illuminate/database/Schema/Grammars/PostgresGrammar.php
vendored
Executable file
@ -0,0 +1,544 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class PostgresGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The possible column modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modifiers = array('Increment', 'Nullable', 'Default');
|
||||
|
||||
/**
|
||||
* The columns available as serials.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $serials = array('bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger');
|
||||
|
||||
/**
|
||||
* Compile the query to determine if a table exists.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileTableExists()
|
||||
{
|
||||
return 'select * from information_schema.tables where table_name = ?';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the query to determine the list of columns.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function compileColumnExists($table)
|
||||
{
|
||||
return "select column_name from information_schema.columns where table_name = '$table'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileCreate(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = implode(', ', $this->getColumns($blueprint));
|
||||
|
||||
return 'create table '.$this->wrapTable($blueprint)." ($columns)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileAdd(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$columns = $this->prefixArray('add column', $this->getColumns($blueprint));
|
||||
|
||||
return 'alter table '.$table.' '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a primary key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compilePrimary(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
return 'alter table '.$this->wrapTable($blueprint)." add primary key ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
return "alter table $table add constraint {$command->index} unique ($columns)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a plain index key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
return "create index {$command->index} on ".$this->wrapTable($blueprint)." ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDrop(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'drop table '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 'drop table if exists '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop column command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->prefixArray('drop column', $this->wrapArray($command->columns));
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return 'alter table '.$table.' '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
return 'alter table '.$this->wrapTable($blueprint)." drop constraint {$table}_pkey";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop constraint {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop index command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return "drop index {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop foreign key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop constraint {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a rename table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileRename(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$from = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$from} rename to ".$this->wrapTable($command->to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a char type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeChar(Fluent $column)
|
||||
{
|
||||
return "char({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a string type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeString(Fluent $column)
|
||||
{
|
||||
return "varchar({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a long text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeLongText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeInteger(Fluent $column)
|
||||
{
|
||||
return $column->autoIncrement ? 'serial' : 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a big integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBigInteger(Fluent $column)
|
||||
{
|
||||
return $column->autoIncrement ? 'bigserial' : 'bigint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumInteger(Fluent $column)
|
||||
{
|
||||
return $column->autoIncrement ? 'serial' : 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a tiny integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTinyInteger(Fluent $column)
|
||||
{
|
||||
return $column->autoIncrement ? 'smallserial' : 'smallint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a small integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeSmallInteger(Fluent $column)
|
||||
{
|
||||
return $column->autoIncrement ? 'smallserial' : 'smallint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a float type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeFloat(Fluent $column)
|
||||
{
|
||||
return $this->typeDouble($column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a double type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDouble(Fluent $column)
|
||||
{
|
||||
return 'double precision';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a decimal type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDecimal(Fluent $column)
|
||||
{
|
||||
return "decimal({$column->total}, {$column->places})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a boolean type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBoolean(Fluent $column)
|
||||
{
|
||||
return 'boolean';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for an enum type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeEnum(Fluent $column)
|
||||
{
|
||||
$allowed = array_map(function($a) { return "'".$a."'"; }, $column->allowed);
|
||||
|
||||
return "varchar(255) check (\"{$column->name}\" in (".implode(', ', $allowed)."))";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a json type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJson(Fluent $column)
|
||||
{
|
||||
return "json";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a jsonb type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJsonb(Fluent $column)
|
||||
{
|
||||
return "jsonb";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDate(Fluent $column)
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTime(Fluent $column)
|
||||
{
|
||||
return 'timestamp(0) without time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTimeTz(Fluent $column)
|
||||
{
|
||||
return 'timestamp(0) with time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTime(Fluent $column)
|
||||
{
|
||||
return 'time(0) without time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimeTz(Fluent $column)
|
||||
{
|
||||
return 'time(0) with time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestamp(Fluent $column)
|
||||
{
|
||||
return 'timestamp(0) without time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestampTz(Fluent $column)
|
||||
{
|
||||
return 'timestamp(0) with time zone';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a binary type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBinary(Fluent $column)
|
||||
{
|
||||
return 'bytea';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a nullable column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
return $column->nullable ? ' null' : ' not null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a default column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->default))
|
||||
{
|
||||
return " default ".$this->getDefaultValue($column->default);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ' primary key';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
611
vendor/illuminate/database/Schema/Grammars/SQLiteGrammar.php
vendored
Executable file
611
vendor/illuminate/database/Schema/Grammars/SQLiteGrammar.php
vendored
Executable file
@ -0,0 +1,611 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class SQLiteGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The possible column modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modifiers = array('Nullable', 'Default', 'Increment');
|
||||
|
||||
/**
|
||||
* The columns available as serials.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $serials = array('bigInteger', 'integer');
|
||||
|
||||
/**
|
||||
* Compile the query to determine if a table exists.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileTableExists()
|
||||
{
|
||||
return "select * from sqlite_master where type = 'table' and name = ?";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the query to determine the list of columns.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function compileColumnExists($table)
|
||||
{
|
||||
return 'pragma table_info('.str_replace('.', '__', $table).')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileCreate(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = implode(', ', $this->getColumns($blueprint));
|
||||
|
||||
$sql = 'create table '.$this->wrapTable($blueprint)." ($columns";
|
||||
|
||||
// SQLite forces primary keys to be added when the table is initially created
|
||||
// so we will need to check for a primary key commands and add the columns
|
||||
// to the table's declaration here so they can be created on the tables.
|
||||
$sql .= (string) $this->addForeignKeys($blueprint);
|
||||
|
||||
$sql .= (string) $this->addPrimaryKeys($blueprint);
|
||||
|
||||
return $sql.')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the foreign key syntax for a table creation statement.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @return string|null
|
||||
*/
|
||||
protected function addForeignKeys(Blueprint $blueprint)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
$foreigns = $this->getCommandsByName($blueprint, 'foreign');
|
||||
|
||||
// Once we have all the foreign key commands for the table creation statement
|
||||
// we'll loop through each of them and add them to the create table SQL we
|
||||
// are building, since SQLite needs foreign keys on the tables creation.
|
||||
foreach ($foreigns as $foreign)
|
||||
{
|
||||
$sql .= $this->getForeignKey($foreign);
|
||||
|
||||
if ( ! is_null($foreign->onDelete))
|
||||
{
|
||||
$sql .= " on delete {$foreign->onDelete}";
|
||||
}
|
||||
|
||||
if ( ! is_null($foreign->onUpdate))
|
||||
{
|
||||
$sql .= " on update {$foreign->onUpdate}";
|
||||
}
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for the foreign key.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $foreign
|
||||
* @return string
|
||||
*/
|
||||
protected function getForeignKey($foreign)
|
||||
{
|
||||
$on = $this->wrapTable($foreign->on);
|
||||
|
||||
// We need to columnize the columns that the foreign key is being defined for
|
||||
// so that it is a properly formatted list. Once we have done this, we can
|
||||
// return the foreign key SQL declaration to the calling method for use.
|
||||
$columns = $this->columnize($foreign->columns);
|
||||
|
||||
$onColumns = $this->columnize((array) $foreign->references);
|
||||
|
||||
return ", foreign key($columns) references $on($onColumns)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primary key syntax for a table creation statement.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @return string|null
|
||||
*/
|
||||
protected function addPrimaryKeys(Blueprint $blueprint)
|
||||
{
|
||||
$primary = $this->getCommandByName($blueprint, 'primary');
|
||||
|
||||
if ( ! is_null($primary))
|
||||
{
|
||||
$columns = $this->columnize($primary->columns);
|
||||
|
||||
return ", primary key ({$columns})";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile alter table commands for adding columns.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return array
|
||||
*/
|
||||
public function compileAdd(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$columns = $this->prefixArray('add column', $this->getColumns($blueprint));
|
||||
|
||||
$statements = array();
|
||||
|
||||
foreach ($columns as $column)
|
||||
{
|
||||
$statements[] = 'alter table '.$table.' '.$column;
|
||||
}
|
||||
|
||||
return $statements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "create unique index {$command->index} on {$table} ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a plain index key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "create index {$command->index} on {$table} ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a foreign key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileForeign(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
// Handled on table creation...
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDrop(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'drop table '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 'drop table if exists '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop column command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @param \Illuminate\Database\Connection $connection
|
||||
* @return array
|
||||
*/
|
||||
public function compileDropColumn(Blueprint $blueprint, Fluent $command, Connection $connection)
|
||||
{
|
||||
$schema = $connection->getDoctrineSchemaManager();
|
||||
|
||||
$tableDiff = $this->getDoctrineTableDiff($blueprint, $schema);
|
||||
|
||||
foreach ($command->columns as $name)
|
||||
{
|
||||
$column = $connection->getDoctrineColumn($blueprint->getTable(), $name);
|
||||
|
||||
$tableDiff->removedColumns[$name] = $column;
|
||||
}
|
||||
|
||||
return (array) $schema->getDatabasePlatform()->getAlterTableSQL($tableDiff);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return "drop index {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop index command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return "drop index {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a rename table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileRename(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$from = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$from} rename to ".$this->wrapTable($command->to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a char type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeChar(Fluent $column)
|
||||
{
|
||||
return 'varchar';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a string type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeString(Fluent $column)
|
||||
{
|
||||
return 'varchar';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a long text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeLongText(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeInteger(Fluent $column)
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a big integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBigInteger(Fluent $column)
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumInteger(Fluent $column)
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a tiny integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTinyInteger(Fluent $column)
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a small integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeSmallInteger(Fluent $column)
|
||||
{
|
||||
return 'integer';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a float type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeFloat(Fluent $column)
|
||||
{
|
||||
return 'float';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a double type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDouble(Fluent $column)
|
||||
{
|
||||
return 'float';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a decimal type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDecimal(Fluent $column)
|
||||
{
|
||||
return 'numeric';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a boolean type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBoolean(Fluent $column)
|
||||
{
|
||||
return 'tinyint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for an enum type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeEnum(Fluent $column)
|
||||
{
|
||||
return 'varchar';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a json type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJson(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a jsonb type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJsonb(Fluent $column)
|
||||
{
|
||||
return 'text';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDate(Fluent $column)
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTime(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* Note: "SQLite does not have a storage class set aside for storing dates and/or times."
|
||||
* @link https://www.sqlite.org/datatype3.html
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTimeTz(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTime(Fluent $column)
|
||||
{
|
||||
return 'time';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimeTz(Fluent $column)
|
||||
{
|
||||
return 'time';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestamp(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestampTz(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a binary type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBinary(Fluent $column)
|
||||
{
|
||||
return 'blob';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a nullable column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
return $column->nullable ? ' null' : ' not null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a default column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->default))
|
||||
{
|
||||
return " default ".$this->getDefaultValue($column->default);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ' primary key autoincrement';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
552
vendor/illuminate/database/Schema/Grammars/SqlServerGrammar.php
vendored
Executable file
552
vendor/illuminate/database/Schema/Grammars/SqlServerGrammar.php
vendored
Executable file
@ -0,0 +1,552 @@
|
||||
<?php namespace Illuminate\Database\Schema\Grammars;
|
||||
|
||||
use Illuminate\Support\Fluent;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class SqlServerGrammar extends Grammar {
|
||||
|
||||
/**
|
||||
* The possible column modifiers.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $modifiers = array('Increment', 'Nullable', 'Default');
|
||||
|
||||
/**
|
||||
* The columns available as serials.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $serials = array('bigInteger', 'integer');
|
||||
|
||||
/**
|
||||
* Compile the query to determine if a table exists.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function compileTableExists()
|
||||
{
|
||||
return "select * from sysobjects where type = 'U' and name = ?";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the query to determine the list of columns.
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
public function compileColumnExists($table)
|
||||
{
|
||||
return "select col.name from sys.columns as col
|
||||
join sys.objects as obj on col.object_id = obj.object_id
|
||||
where obj.type = 'U' and obj.name = '$table'";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileCreate(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = implode(', ', $this->getColumns($blueprint));
|
||||
|
||||
return 'create table '.$this->wrapTable($blueprint)." ($columns)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a create table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileAdd(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
$columns = $this->getColumns($blueprint);
|
||||
|
||||
return 'alter table '.$table.' add '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a primary key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compilePrimary(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} add constraint {$command->index} primary key ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "create unique index {$command->index} on {$table} ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a plain index key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->columnize($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "create index {$command->index} on {$table} ({$columns})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDrop(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
return 'drop table '.$this->wrapTable($blueprint);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop column command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$columns = $this->wrapArray($command->columns);
|
||||
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return 'alter table '.$table.' drop column '.implode(', ', $columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop constraint {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop unique key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "drop index {$command->index} on {$table}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop index command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "drop index {$command->index} on {$table}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a drop foreign key command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$table = $this->wrapTable($blueprint);
|
||||
|
||||
return "alter table {$table} drop constraint {$command->index}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile a rename table command.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $command
|
||||
* @return string
|
||||
*/
|
||||
public function compileRename(Blueprint $blueprint, Fluent $command)
|
||||
{
|
||||
$from = $this->wrapTable($blueprint);
|
||||
|
||||
return "sp_rename {$from}, ".$this->wrapTable($command->to);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a char type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeChar(Fluent $column)
|
||||
{
|
||||
return "nchar({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a string type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeString(Fluent $column)
|
||||
{
|
||||
return "nvarchar({$column->length})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeText(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumText(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a long text type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeLongText(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeInteger(Fluent $column)
|
||||
{
|
||||
return 'int';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a big integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBigInteger(Fluent $column)
|
||||
{
|
||||
return 'bigint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a medium integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeMediumInteger(Fluent $column)
|
||||
{
|
||||
return 'int';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a tiny integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTinyInteger(Fluent $column)
|
||||
{
|
||||
return 'tinyint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a small integer type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeSmallInteger(Fluent $column)
|
||||
{
|
||||
return 'smallint';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a float type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeFloat(Fluent $column)
|
||||
{
|
||||
return 'float';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a double type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDouble(Fluent $column)
|
||||
{
|
||||
return 'float';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a decimal type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDecimal(Fluent $column)
|
||||
{
|
||||
return "decimal({$column->total}, {$column->places})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a boolean type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBoolean(Fluent $column)
|
||||
{
|
||||
return 'bit';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for an enum type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeEnum(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(255)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a json type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJson(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a jsonb type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeJsonb(Fluent $column)
|
||||
{
|
||||
return 'nvarchar(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDate(Fluent $column)
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTime(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a date-time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeDateTimeTz(Fluent $column)
|
||||
{
|
||||
return 'datetimeoffset(0)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTime(Fluent $column)
|
||||
{
|
||||
return 'time';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a time type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimeTz(Fluent $column)
|
||||
{
|
||||
return 'time';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestamp(Fluent $column)
|
||||
{
|
||||
return 'datetime';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a timestamp type.
|
||||
*
|
||||
* @link https://msdn.microsoft.com/en-us/library/bb630289(v=sql.120).aspx
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeTimestampTz(Fluent $column)
|
||||
{
|
||||
return 'datetimeoffset(0)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the column definition for a binary type.
|
||||
*
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string
|
||||
*/
|
||||
protected function typeBinary(Fluent $column)
|
||||
{
|
||||
return 'varbinary(max)';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a nullable column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
return $column->nullable ? ' null' : ' not null';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL for a default column modifier.
|
||||
*
|
||||
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||
* @param \Illuminate\Support\Fluent $column
|
||||
* @return string|null
|
||||
*/
|
||||
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
|
||||
{
|
||||
if ( ! is_null($column->default))
|
||||
{
|
||||
return " default ".$this->getDefaultValue($column->default);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ' identity primary key';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
41
vendor/illuminate/database/Schema/MySqlBuilder.php
vendored
Executable file
41
vendor/illuminate/database/Schema/MySqlBuilder.php
vendored
Executable file
@ -0,0 +1,41 @@
|
||||
<?php namespace Illuminate\Database\Schema;
|
||||
|
||||
class MySqlBuilder extends Builder {
|
||||
|
||||
/**
|
||||
* Determine if the given table exists.
|
||||
*
|
||||
* @param string $table
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTable($table)
|
||||
{
|
||||
$sql = $this->grammar->compileTableExists();
|
||||
|
||||
$database = $this->connection->getDatabaseName();
|
||||
|
||||
$table = $this->connection->getTablePrefix().$table;
|
||||
|
||||
return count($this->connection->select($sql, array($database, $table))) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column listing for a given table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function getColumnListing($table)
|
||||
{
|
||||
$sql = $this->grammar->compileColumnExists();
|
||||
|
||||
$database = $this->connection->getDatabaseName();
|
||||
|
||||
$table = $this->connection->getTablePrefix().$table;
|
||||
|
||||
$results = $this->connection->select($sql, array($database, $table));
|
||||
|
||||
return $this->connection->getPostProcessor()->processColumnListing($results);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user