Added vendor/ directory for Composer's installed files
This commit is contained in:
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';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user