Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,23 @@ protected function createIndexName($type, array $columns)
return str_replace(['-', '.'], '_', $index);
}

/**
* Add a check constraint to the table.
*
* @param $checkName
* @param $constraint
* @return Fluent
*/
public function check($checkName, $constraint)
{
return $this->addCommand('check', compact('checkName', 'constraint'));
}

public function dropCheck($checkName)
{
return $this->addCommand('dropCheck', compact('checkName'));
}

/**
* Add a new column to the blueprint.
*
Expand Down
28 changes: 28 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,34 @@ public function compileTableComment(Blueprint $blueprint, Fluent $command)
);
}

/**
* Compile a table level check command.
*
* @param Blueprint $blueprint
* @param Fluent $command
* @return string
*/
public function compileCheck(Blueprint $blueprint, Fluent $command)
{
$table = $this->wrapTable($blueprint);

return sprintf('alter table %s add constraint %s check (%s)',
$table,
$this->wrap($command->checkName),
$command->constraint
);
}

public function compileDropCheck(Blueprint $blueprint, Fluent $command)
{
$table = $this->wrapTable($blueprint);

return sprintf('alter table %s drop constraint %s',
$table,
$this->wrap($command->checkName)
);
}

/**
* Quote-escape the given tables, views, or types.
*
Expand Down