Skip to content

Commit

Permalink
Fix setting sqlsrv PK name with qualified table name (#2306)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthew Peveler <[email protected]>
  • Loading branch information
MichaelDesignamite and MasterOdin authored Sep 7, 2024
1 parent d55d705 commit b5dab99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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 @@ public function createTable(Table $table, array $columns = [], array $indexes =

// 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()));
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

0 comments on commit b5dab99

Please sign in to comment.