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

Fix setting sqlsrv PK name with qualified table name #2306

Merged
Merged
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
2 changes: 1 addition & 1 deletion src/Phinx/Db/Adapter/SqlServerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@

// set the primary key(s)
if (isset($options['primary_key'])) {
$pkSql = sprintf('CONSTRAINT PK_%s PRIMARY KEY (', $table->getName());
$pkSql = sprintf('CONSTRAINT PK_%s PRIMARY KEY (', str_replace('.', '_', $table->getName()));

Check warning on line 273 in src/Phinx/Db/Adapter/SqlServerAdapter.php

View check run for this annotation

Codecov / codecov/patch

src/Phinx/Db/Adapter/SqlServerAdapter.php#L273

Added line #L273 was not covered by tests
if (is_string($options['primary_key'])) { // handle primary_key => 'id'
$pkSql .= $this->quoteColumnName($options['primary_key']);
} elseif (is_array($options['primary_key'])) { // handle primary_key => array('tag_id', 'resource_id')
Expand Down
7 changes: 7 additions & 0 deletions tests/Phinx/Db/Adapter/SqlServerAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ public function testCreateTableWithNoPrimaryKey()
$this->assertFalse($this->adapter->hasColumn('atable', 'id'));
}

public function testCreateFullyQualifiedTable()
{
(new Table('dbo.qualified_table', [], $this->adapter))->create();
$this->assertTrue($this->adapter->hasTable('dbo.qualified_table'));
$this->assertTrue($this->adapter->hasPrimaryKey('qualified_table', 'id'));
}

public function testCreateTableWithConflictingPrimaryKeys()
{
$options = [
Expand Down
Loading