Diff
checker
Texto
Texto
Imagens
Documentos
Excel
Pastas
Legal
Enterprise
Aplicativo para desktop
Preços
Fazer login
Baixar o Diffchecker Desktop
Comparar texto
Encontre a diferença entre dois arquivos de texto
Ferramentas
Histórico
Editor live
Recolher inalteradas
Sem quebra de linha
Layout
Dividido
Unificado
Nível de detalhe
Inteligente
Palavra
Caractere
Realce de sintaxe
Escolher sintaxe
Ignorar
Transformar texto
Ir à primeira mudança
Editar entrada
Diffchecker Desktop
A maneira mais segura de usar o Diffchecker. Obtenha o aplicativo Diffchecker Desktop: seus diffs nunca saem do seu computador!
Obter Desktop
Untitled diff
Criado
há 10 anos
O diff nunca expira
Limpar
Exportar
Compartilhar
Explicar
10 remoções
Linhas
Total
Removido
Caracteres
Total
Removido
Para continuar usando este recurso, atualize para
Diff
checker
Pro
Ver preços
721 linhas
Copiar tudo
2 adições
Linhas
Total
Adicionado
Caracteres
Total
Adicionado
Para continuar usando este recurso, atualize para
Diff
checker
Pro
Ver preços
713 linhas
Copiar tudo
<?php
<?php
namespace Illuminate\Database\Schema\Grammars;
namespace Illuminate\Database\Schema\Grammars;
use Illuminate\Support\Fluent;
use Illuminate\Support\Fluent;
use Illuminate\Database\Connection;
use Illuminate\Database\Connection;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Blueprint;
class MySqlGrammar extends Grammar
class MySqlGrammar extends Grammar
{
{
/**
/**
* The possible column modifiers.
* The possible column modifiers.
*
*
* @var array
* @var array
*/
*/
protected $modifiers = ['Unsigned', 'Charset', 'Collate', 'Nullable', 'Default', 'Increment', 'Comment', 'After', 'First'];
protected $modifiers = ['Unsigned', 'Charset', 'Collate', 'Nullable', 'Default', 'Increment', 'Comment', 'After', 'First'];
/**
/**
* The possible column serials.
* The possible column serials.
*
*
* @var array
* @var array
*/
*/
protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'];
protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'];
/**
/**
* Compile the query to determine the list of tables.
* Compile the query to determine the list of tables.
*
*
* @return string
* @return string
*/
*/
public function compileTableExists()
public function compileTableExists()
{
{
return 'select * from information_schema.tables where table_schema = ? and table_name = ?';
return 'select * from information_schema.tables where table_schema = ? and table_name = ?';
}
}
/**
/**
* Compile the query to determine the list of columns.
* Compile the query to determine the list of columns.
*
*
* @return string
* @return string
*/
*/
public function compileColumnExists()
public function compileColumnExists()
{
{
return 'select column_name from information_schema.columns where table_schema = ? and table_name = ?';
return 'select column_name from information_schema.columns where table_schema = ? and table_name = ?';
}
}
/**
/**
* Compile a create table command.
* Compile a create table command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection
* @param \Illuminate\Database\Connection $connection
* @return string
* @return string
*/
*/
public function compileCreate(Blueprint $blueprint, Fluent $command, Connection $connection)
public function compileCreate(Blueprint $blueprint, Fluent $command, Connection $connection)
{
{
$columns = implode(', ', $this->getColumns($blueprint));
$columns = implode(', ', $this->getColumns($blueprint));
$sql = $blueprint->temporary ? 'create temporary' : 'create';
$sql = $blueprint->temporary ? 'create temporary' : 'create';
$sql .= ' table '.$this->wrapTable($blueprint)." ($columns)";
$sql .= ' table '.$this->wrapTable($blueprint)." ($columns)";
// Once we have the primary SQL, we can add the encoding option to the SQL for
// 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. 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.
// the table. If so, we will add the engine declaration to the SQL query.
$sql = $this->compileCreateEncoding($sql, $connection, $blueprint);
$sql = $this->compileCreateEncoding($sql, $connection, $blueprint);
if (isset($blueprint->engine)) {
if (isset($blueprint->engine)) {
$sql .= ' engine = '.$blueprint->engine;
$sql .= ' engine = '.$blueprint->engine;
}
}
return $sql;
return $sql;
}
}
/**
/**
* Append the character set specifications to a command.
* Append the character set specifications to a command.
*
*
* @param string $sql
* @param string $sql
* @param \Illuminate\Database\Connection $connection
* @param \Illuminate\Database\Connection $connection
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @return string
* @return string
*/
*/
protected function compileCreateEncoding($sql, Connection $connection, Blueprint $blueprint)
protected function compileCreateEncoding($sql, Connection $connection, Blueprint $blueprint)
{
{
if (isset($blueprint->charset)) {
if (isset($blueprint->charset)) {
$sql .= ' default character set '.$blueprint->charset;
$sql .= ' default character set '.$blueprint->charset;
} elseif (! is_null($charset = $connection->getConfig('charset'))) {
} elseif (! is_null($charset = $connection->getConfig('charset'))) {
$sql .= ' default character set '.$charset;
$sql .= ' default character set '.$charset;
}
}
if (isset($blueprint->collation)) {
if (isset($blueprint->collation)) {
$sql .= ' collate '.$blueprint->collation;
$sql .= ' collate '.$blueprint->collation;
} elseif (! is_null($collation = $connection->getConfig('collation'))) {
} elseif (! is_null($collation = $connection->getConfig('collation'))) {
$sql .= ' collate '.$collation;
$sql .= ' collate '.$collation;
}
}
return $sql;
return $sql;
}
}
/**
/**
* Compile an add column command.
* Compile an add column command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compileAdd(Blueprint $blueprint, Fluent $command)
public function compileAdd(Blueprint $blueprint, Fluent $command)
{
{
$table = $this->wrapTable($blueprint);
$table = $this->wrapTable($blueprint);
$columns = $this->prefixArray('add', $this->getColumns($blueprint));
$columns = $this->prefixArray('add', $this->getColumns($blueprint));
return 'alter table '.$table.' '.implode(', ', $columns);
return 'alter table '.$table.' '.implode(', ', $columns);
}
}
/**
/**
* Compile a primary key command.
* Compile a primary key command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compilePrimary(Blueprint $blueprint, Fluent $command)
public function compilePrimary(Blueprint $blueprint, Fluent $command)
{
{
$command->name(null);
$command->name(null);
return $this->compileKey($blueprint, $command, 'primary key');
return $this->compileKey($blueprint, $command, 'primary key');
}
}
/**
/**
* Compile a unique key command.
* Compile a unique key command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compileUnique(Blueprint $blueprint, Fluent $command)
public function compileUnique(Blueprint $blueprint, Fluent $command)
{
{
return $this->compileKey($blueprint, $command, 'unique');
return $this->compileKey($blueprint, $command, 'unique');
}
}
/**
/**
* Compile a plain index key command.
* Compile a plain index key command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compileIndex(Blueprint $blueprint, Fluent $command)
public function compileIndex(Blueprint $blueprint, Fluent $command)
{
{
return $this->compileKey($blueprint, $command, 'index');
return $this->compileKey($blueprint, $command, 'index');
}
}
/**
/**
* Compile an index creation command.
* Compile an index creation command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @param string $type
* @param string $type
* @return string
* @return string
*/
*/
protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
{
{
$columns = $this->columnize($command->columns);
$columns = $this->columnize($command->columns);
$table = $this->wrapTable($blueprint);
$table = $this->wrapTable($blueprint);
return "alter table {$table} add {$type} `{$command->index}`($columns)";
return "alter table {$table} add {$type} `{$command->index}`($columns)";
}
}
/**
/**
* Compile a drop table command.
* Compile a drop table command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compileDrop(Blueprint $blueprint, Fluent $command)
public function compileDrop(Blueprint $blueprint, Fluent $command)
{
{
return 'drop table '.$this->wrapTable($blueprint);
return 'drop table '.$this->wrapTable($blueprint);
}
}
/**
/**
* Compile a drop table (if exists) command.
* Compile a drop table (if exists) command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
{
{
return 'drop table if exists '.$this->wrapTable($blueprint);
return 'drop table if exists '.$this->wrapTable($blueprint);
}
}
/**
/**
* Compile a drop column command.
* Compile a drop column command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
public function compileDropColumn(Blueprint $blueprint, Fluent $command)
{
{
$columns = $this->prefixArray('drop', $this->wrapArray($command->columns));
$columns = $this->prefixArray('drop', $this->wrapArray($command->columns));
$table = $this->wrapTable($blueprint);
$table = $this->wrapTable($blueprint);
return 'alter table '.$table.' '.implode(', ', $columns);
return 'alter table '.$table.' '.implode(', ', $columns);
}
}
/**
/**
* Compile a drop primary key command.
* Compile a drop primary key command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
{
{
return 'alter table '.$this->wrapTable($blueprint).' drop primary key';
return 'alter table '.$this->wrapTable($blueprint).' drop primary key';
}
}
/**
/**
* Compile a drop unique key command.
* Compile a drop unique key command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
public function compileDropUnique(Blueprint $blueprint, Fluent $command)
{
{
$table = $this->wrapTable($blueprint);
$table = $this->wrapTable($blueprint);
return "alter table {$table} drop index `{$command->index}`";
return "alter table {$table} drop index `{$command->index}`";
}
}
/**
/**
* Compile a drop index command.
* Compile a drop index command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
public function compileDropIndex(Blueprint $blueprint, Fluent $command)
{
{
$table = $this->wrapTable($blueprint);
$table = $this->wrapTable($blueprint);
return "alter table {$table} drop index `{$command->index}`";
return "alter table {$table} drop index `{$command->index}`";
}
}
/**
/**
* Compile a drop foreign key command.
* Compile a drop foreign key command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
public function compileDropForeign(Blueprint $blueprint, Fluent $command)
{
{
$table = $this->wrapTable($blueprint);
$table = $this->wrapTable($blueprint);
return "alter table {$table} drop foreign key `{$command->index}`";
return "alter table {$table} drop foreign key `{$command->index}`";
}
}
/**
/**
* Compile a rename table command.
* Compile a rename table command.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Support\Fluent $command
* @return string
* @return string
*/
*/
public function compileRename(Blueprint $blueprint, Fluent $command)
public function compileRename(Blueprint $blueprint, Fluent $command)
{
{
$from = $this->wrapTable($blueprint);
$from = $this->wrapTable($blueprint);
return "rename table {$from} to ".$this->wrapTable($command->to);
return "rename table {$from} to ".$this->wrapTable($command->to);
}
}
/**
/**
* Create the column definition for a char type.
* Create the column definition for a char type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeChar(Fluent $column)
protected function typeChar(Fluent $column)
{
{
return "char({$column->length})";
return "char({$column->length})";
}
}
/**
/**
* Create the column definition for a string type.
* Create the column definition for a string type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeString(Fluent $column)
protected function typeString(Fluent $column)
{
{
return "varchar({$column->length})";
return "varchar({$column->length})";
}
}
/**
/**
* Create the column definition for a text type.
* Create the column definition for a text type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeText(Fluent $column)
protected function typeText(Fluent $column)
{
{
return 'text';
return 'text';
}
}
/**
/**
* Create the column definition for a medium text type.
* Create the column definition for a medium text type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeMediumText(Fluent $column)
protected function typeMediumText(Fluent $column)
{
{
return 'mediumtext';
return 'mediumtext';
}
}
/**
/**
* Create the column definition for a long text type.
* Create the column definition for a long text type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeLongText(Fluent $column)
protected function typeLongText(Fluent $column)
{
{
return 'longtext';
return 'longtext';
}
}
/**
/**
* Create the column definition for a big integer type.
* Create the column definition for a big integer type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeBigInteger(Fluent $column)
protected function typeBigInteger(Fluent $column)
{
{
return 'bigint';
return 'bigint';
}
}
/**
/**
* Create the column definition for a integer type.
* Create the column definition for a integer type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeInteger(Fluent $column)
protected function typeInteger(Fluent $column)
{
{
return 'int';
return 'int';
}
}
/**
/**
* Create the column definition for a medium integer type.
* Create the column definition for a medium integer type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeMediumInteger(Fluent $column)
protected function typeMediumInteger(Fluent $column)
{
{
return 'mediumint';
return 'mediumint';
}
}
/**
/**
* Create the column definition for a tiny integer type.
* Create the column definition for a tiny integer type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeTinyInteger(Fluent $column)
protected function typeTinyInteger(Fluent $column)
{
{
return 'tinyint';
return 'tinyint';
}
}
/**
/**
* Create the column definition for a small integer type.
* Create the column definition for a small integer type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeSmallInteger(Fluent $column)
protected function typeSmallInteger(Fluent $column)
{
{
return 'smallint';
return 'smallint';
}
}
/**
/**
* Create the column definition for a float type.
* Create the column definition for a float type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeFloat(Fluent $column)
protected function typeFloat(Fluent $column)
{
{
return $this->typeDouble($column);
return $this->typeDouble($column);
}
}
/**
/**
* Create the column definition for a double type.
* Create the column definition for a double type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeDouble(Fluent $column)
protected function typeDouble(Fluent $column)
{
{
if ($column->total && $column->places) {
if ($column->total && $column->places) {
return "double({$column->total}, {$column->places})";
return "double({$column->total}, {$column->places})";
}
}
return 'double';
return 'double';
}
}
/**
/**
* Create the column definition for a decimal type.
* Create the column definition for a decimal type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeDecimal(Fluent $column)
protected function typeDecimal(Fluent $column)
{
{
return "decimal({$column->total}, {$column->places})";
return "decimal({$column->total}, {$column->places})";
}
}
/**
/**
* Create the column definition for a boolean type.
* Create the column definition for a boolean type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeBoolean(Fluent $column)
protected function typeBoolean(Fluent $column)
{
{
return 'tinyint(1)';
return 'tinyint(1)';
}
}
/**
/**
* Create the column definition for an enum type.
* Create the column definition for an enum type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeEnum(Fluent $column)
protected function typeEnum(Fluent $column)
{
{
return "enum('".implode("', '", $column->allowed)."')";
return "enum('".implode("', '", $column->allowed)."')";
}
}
/**
/**
* Create the column definition for a json type.
* Create the column definition for a json type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeJson(Fluent $column)
protected function typeJson(Fluent $column)
{
{
Copiar
Copiado
Copiar
Copiado
return '
text
';
return '
json
';
}
}
/**
/**
* Create the column definition for a jsonb type.
* Create the column definition for a jsonb type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeJsonb(Fluent $column)
protected function typeJsonb(Fluent $column)
{
{
Copiar
Copiado
Copiar
Copiado
return '
text
';
return '
json
';
}
}
/**
/**
* Create the column definition for a date type.
* Create the column definition for a date type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeDate(Fluent $column)
protected function typeDate(Fluent $column)
{
{
return 'date';
return 'date';
}
}
/**
/**
* Create the column definition for a date-time type.
* Create the column definition for a date-time type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeDateTime(Fluent $column)
protected function typeDateTime(Fluent $column)
{
{
return 'datetime';
return 'datetime';
}
}
/**
/**
* Create the column definition for a date-time type.
* Create the column definition for a date-time type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeDateTimeTz(Fluent $column)
protected function typeDateTimeTz(Fluent $column)
{
{
return 'datetime';
return 'datetime';
}
}
/**
/**
* Create the column definition for a time type.
* Create the column definition for a time type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeTime(Fluent $column)
protected function typeTime(Fluent $column)
{
{
return 'time';
return 'time';
}
}
/**
/**
* Create the column definition for a time type.
* Create the column definition for a time type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeTimeTz(Fluent $column)
protected function typeTimeTz(Fluent $column)
{
{
return 'time';
return 'time';
}
}
/**
/**
* Create the column definition for a timestamp type.
* Create the column definition for a timestamp type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeTimestamp(Fluent $column)
protected function typeTimestamp(Fluent $column)
{
{
if ($column->useCurrent) {
if ($column->useCurrent) {
return 'timestamp default CURRENT_TIMESTAMP';
return 'timestamp default CURRENT_TIMESTAMP';
}
}
Copiar
Copiado
Copiar
Copiado
if (! $column->nullable && $column->default === null) {
return 'timestamp default 0';
}
return 'timestamp';
return 'timestamp';
}
}
/**
/**
* Create the column definition for a timestamp type.
* Create the column definition for a timestamp type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeTimestampTz(Fluent $column)
protected function typeTimestampTz(Fluent $column)
{
{
if ($column->useCurrent) {
if ($column->useCurrent) {
return 'timestamp default CURRENT_TIMESTAMP';
return 'timestamp default CURRENT_TIMESTAMP';
}
}
Copiar
Copiado
Copiar
Copiado
if (! $column->nullable && $column->default === null) {
return 'timestamp default 0';
}
return 'timestamp';
return 'timestamp';
}
}
/**
/**
* Create the column definition for a binary type.
* Create the column definition for a binary type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeBinary(Fluent $column)
protected function typeBinary(Fluent $column)
{
{
return 'blob';
return 'blob';
}
}
/**
/**
* Create the column definition for a uuid type.
* Create the column definition for a uuid type.
*
*
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string
* @return string
*/
*/
protected function typeUuid(Fluent $column)
protected function typeUuid(Fluent $column)
{
{
return 'char(36)';
return 'char(36)';
}
}
/**
/**
* Get the SQL for an unsigned column modifier.
* Get the SQL for an unsigned column modifier.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string|null
* @return string|null
*/
*/
protected function modifyUnsigned(Blueprint $blueprint, Fluent $column)
protected function modifyUnsigned(Blueprint $blueprint, Fluent $column)
{
{
if ($column->unsigned) {
if ($column->unsigned) {
return ' unsigned';
return ' unsigned';
}
}
}
}
/**
/**
* Get the SQL for a character set column modifier.
* Get the SQL for a character set column modifier.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string|null
* @return string|null
*/
*/
protected function modifyCharset(Blueprint $blueprint, Fluent $column)
protected function modifyCharset(Blueprint $blueprint, Fluent $column)
{
{
if (! is_null($column->charset)) {
if (! is_null($column->charset)) {
return ' character set '.$column->charset;
return ' character set '.$column->charset;
}
}
}
}
/**
/**
* Get the SQL for a collation column modifier.
* Get the SQL for a collation column modifier.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string|null
* @return string|null
*/
*/
protected function modifyCollate(Blueprint $blueprint, Fluent $column)
protected function modifyCollate(Blueprint $blueprint, Fluent $column)
{
{
if (! is_null($column->collation)) {
if (! is_null($column->collation)) {
return ' collate '.$column->collation;
return ' collate '.$column->collation;
}
}
}
}
/**
/**
* Get the SQL for a nullable column modifier.
* Get the SQL for a nullable column modifier.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string|null
* @return string|null
*/
*/
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
protected function modifyNullable(Blueprint $blueprint, Fluent $column)
{
{
return $column->nullable ? ' null' : ' not null';
return $column->nullable ? ' null' : ' not null';
}
}
/**
/**
* Get the SQL for a default column modifier.
* Get the SQL for a default column modifier.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string|null
* @return string|null
*/
*/
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
protected function modifyDefault(Blueprint $blueprint, Fluent $column)
{
{
if (! is_null($column->default)) {
if (! is_null($column->default)) {
return ' default '.$this->getDefaultValue($column->default);
return ' default '.$this->getDefaultValue($column->default);
}
}
}
}
/**
/**
* Get the SQL for an auto-increment column modifier.
* Get the SQL for an auto-increment column modifier.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string|null
* @return string|null
*/
*/
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
{
{
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
if (in_array($column->type, $this->serials) && $column->autoIncrement) {
return ' auto_increment primary key';
return ' auto_increment primary key';
}
}
}
}
/**
/**
* Get the SQL for a "first" column modifier.
* Get the SQL for a "first" column modifier.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string|null
* @return string|null
*/
*/
protected function modifyFirst(Blueprint $blueprint, Fluent $column)
protected function modifyFirst(Blueprint $blueprint, Fluent $column)
{
{
if (! is_null($column->first)) {
if (! is_null($column->first)) {
return ' first';
return ' first';
}
}
}
}
/**
/**
* Get the SQL for an "after" column modifier.
* Get the SQL for an "after" column modifier.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string|null
* @return string|null
*/
*/
protected function modifyAfter(Blueprint $blueprint, Fluent $column)
protected function modifyAfter(Blueprint $blueprint, Fluent $column)
{
{
if (! is_null($column->after)) {
if (! is_null($column->after)) {
return ' after '.$this->wrap($column->after);
return ' after '.$this->wrap($column->after);
}
}
}
}
/**
/**
* Get the SQL for a "comment" column modifier.
* Get the SQL for a "comment" column modifier.
*
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @param \Illuminate\Support\Fluent $column
* @return string|null
* @return string|null
*/
*/
protected function modifyComment(Blueprint $blueprint, Fluent $column)
protected function modifyComment(Blueprint $blueprint, Fluent $column)
{
{
if (! is_null($column->comment)) {
if (! is_null($column->comment)) {
return ' comment "'.$column->comment.'"';
return ' comment "'.$column->comment.'"';
}
}
}
}
/**
/**
* Wrap a single string in keyword identifiers.
* Wrap a single string in keyword identifiers.
*
*
* @param string $value
* @param string $value
* @return string
* @return string
*/
*/
protected function wrapValue($value)
protected function wrapValue($value)
{
{
if ($value === '*') {
if ($value === '*') {
return $value;
return $value;
}
}
return '`'.str_replace('`', '``', $value).'`';
return '`'.str_replace('`', '``', $value).'`';
}
}
}
}
Diferenças salvas
Texto original
Abrir arquivo
<?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 = ['Unsigned', 'Charset', 'Collate', 'Nullable', 'Default', 'Increment', 'Comment', 'After', 'First']; /** * The possible column serials. * * @var array */ protected $serials = ['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 = $blueprint->temporary ? 'create temporary' : 'create'; $sql .= ' 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, $blueprint); 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 * @param \Illuminate\Database\Schema\Blueprint $blueprint * @return string */ protected function compileCreateEncoding($sql, Connection $connection, Blueprint $blueprint) { if (isset($blueprint->charset)) { $sql .= ' default character set '.$blueprint->charset; } elseif (! is_null($charset = $connection->getConfig('charset'))) { $sql .= ' default character set '.$charset; } if (isset($blueprint->collation)) { $sql .= ' collate '.$blueprint->collation; } elseif (! 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->useCurrent) { return 'timestamp default CURRENT_TIMESTAMP'; } if (! $column->nullable && $column->default === null) { 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->useCurrent) { return 'timestamp default CURRENT_TIMESTAMP'; } if (! $column->nullable && $column->default === null) { 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'; } /** * Create the column definition for a uuid type. * * @param \Illuminate\Support\Fluent $column * @return string */ protected function typeUuid(Fluent $column) { return 'char(36)'; } /** * 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 character set column modifier. * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Support\Fluent $column * @return string|null */ protected function modifyCharset(Blueprint $blueprint, Fluent $column) { if (! is_null($column->charset)) { return ' character set '.$column->charset; } } /** * Get the SQL for a collation column modifier. * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Support\Fluent $column * @return string|null */ protected function modifyCollate(Blueprint $blueprint, Fluent $column) { if (! is_null($column->collation)) { return ' collate '.$column->collation; } } /** * 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 a "first" column modifier. * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Support\Fluent $column * @return string|null */ protected function modifyFirst(Blueprint $blueprint, Fluent $column) { if (! is_null($column->first)) { return ' first'; } } /** * 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 a "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).'`'; } }
Texto alterado
Abrir arquivo
<?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 = ['Unsigned', 'Charset', 'Collate', 'Nullable', 'Default', 'Increment', 'Comment', 'After', 'First']; /** * The possible column serials. * * @var array */ protected $serials = ['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 = $blueprint->temporary ? 'create temporary' : 'create'; $sql .= ' 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, $blueprint); 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 * @param \Illuminate\Database\Schema\Blueprint $blueprint * @return string */ protected function compileCreateEncoding($sql, Connection $connection, Blueprint $blueprint) { if (isset($blueprint->charset)) { $sql .= ' default character set '.$blueprint->charset; } elseif (! is_null($charset = $connection->getConfig('charset'))) { $sql .= ' default character set '.$charset; } if (isset($blueprint->collation)) { $sql .= ' collate '.$blueprint->collation; } elseif (! 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 'json'; } /** * Create the column definition for a jsonb type. * * @param \Illuminate\Support\Fluent $column * @return string */ protected function typeJsonb(Fluent $column) { return 'json'; } /** * 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->useCurrent) { return 'timestamp default CURRENT_TIMESTAMP'; } return 'timestamp'; } /** * Create the column definition for a timestamp type. * * @param \Illuminate\Support\Fluent $column * @return string */ protected function typeTimestampTz(Fluent $column) { if ($column->useCurrent) { return 'timestamp default CURRENT_TIMESTAMP'; } return 'timestamp'; } /** * Create the column definition for a binary type. * * @param \Illuminate\Support\Fluent $column * @return string */ protected function typeBinary(Fluent $column) { return 'blob'; } /** * Create the column definition for a uuid type. * * @param \Illuminate\Support\Fluent $column * @return string */ protected function typeUuid(Fluent $column) { return 'char(36)'; } /** * 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 character set column modifier. * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Support\Fluent $column * @return string|null */ protected function modifyCharset(Blueprint $blueprint, Fluent $column) { if (! is_null($column->charset)) { return ' character set '.$column->charset; } } /** * Get the SQL for a collation column modifier. * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Support\Fluent $column * @return string|null */ protected function modifyCollate(Blueprint $blueprint, Fluent $column) { if (! is_null($column->collation)) { return ' collate '.$column->collation; } } /** * 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 a "first" column modifier. * * @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Support\Fluent $column * @return string|null */ protected function modifyFirst(Blueprint $blueprint, Fluent $column) { if (! is_null($column->first)) { return ' first'; } } /** * 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 a "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).'`'; } }
Encontrar Diferença