Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add dropConstrainedForeignId to Blueprint #34806

Merged
merged 1 commit into from
Oct 12, 2020
Merged
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
13 changes: 13 additions & 0 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
@@ -383,6 +383,19 @@ public function dropForeign($index)
return $this->dropIndexCommand('dropForeign', 'foreign', $index);
}

/**
* Indicate that the given column and foreign key should be dropped.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function dropConstrainedForeignId($column)
{
$this->dropForeign([$column]);

return $this->dropColumn($column);
}

/**
* Indicate that the given indexes should be renamed.
*
11 changes: 11 additions & 0 deletions tests/Database/DatabaseSqlServerSchemaGrammarTest.php
Original file line number Diff line number Diff line change
@@ -176,6 +176,17 @@ public function testDropForeign()
$this->assertSame('alter table "users" drop constraint "foo"', $statements[0]);
}

public function testdropConstrainedForeignId()
{
$blueprint = new Blueprint('users');
$blueprint->dropConstrainedForeignId('foo');
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(2, $statements);
$this->assertSame('alter table "users" drop constraint "users_foo_foreign"', $statements[0]);
$this->assertSame('DECLARE @sql NVARCHAR(MAX) = \'\';SELECT @sql += \'ALTER TABLE [dbo].[users] DROP CONSTRAINT \' + OBJECT_NAME([default_object_id]) + \';\' FROM SYS.COLUMNS WHERE [object_id] = OBJECT_ID(\'[dbo].[users]\') AND [name] in (\'foo\') AND [default_object_id] <> 0;EXEC(@sql);alter table "users" drop column "foo"', $statements[1]);
}

public function testDropTimestamps()
{
$blueprint = new Blueprint('users');