Skip to content

Commit b5dab99

Browse files
Fix setting sqlsrv PK name with qualified table name (#2306)
Co-authored-by: Matthew Peveler <matt.peveler@gmail.com>
1 parent d55d705 commit b5dab99

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Phinx/Db/Adapter/SqlServerAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public function createTable(Table $table, array $columns = [], array $indexes =
270270

271271
// set the primary key(s)
272272
if (isset($options['primary_key'])) {
273-
$pkSql = sprintf('CONSTRAINT PK_%s PRIMARY KEY (', $table->getName());
273+
$pkSql = sprintf('CONSTRAINT PK_%s PRIMARY KEY (', str_replace('.', '_', $table->getName()));
274274
if (is_string($options['primary_key'])) { // handle primary_key => 'id'
275275
$pkSql .= $this->quoteColumnName($options['primary_key']);
276276
} elseif (is_array($options['primary_key'])) { // handle primary_key => array('tag_id', 'resource_id')

tests/Phinx/Db/Adapter/SqlServerAdapterTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ public function testCreateTableWithNoPrimaryKey()
199199
$this->assertFalse($this->adapter->hasColumn('atable', 'id'));
200200
}
201201

202+
public function testCreateFullyQualifiedTable()
203+
{
204+
(new Table('dbo.qualified_table', [], $this->adapter))->create();
205+
$this->assertTrue($this->adapter->hasTable('dbo.qualified_table'));
206+
$this->assertTrue($this->adapter->hasPrimaryKey('qualified_table', 'id'));
207+
}
208+
202209
public function testCreateTableWithConflictingPrimaryKeys()
203210
{
204211
$options = [

0 commit comments

Comments
 (0)