From 25acfadd5416a8b2b2b231c81407c0771127508a Mon Sep 17 00:00:00 2001 From: Michael Rushton Date: Thu, 5 Sep 2024 09:37:44 +0100 Subject: [PATCH 1/2] Replace dot in sqlsrv primary key name with underscore --- src/Phinx/Db/Adapter/SqlServerAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Phinx/Db/Adapter/SqlServerAdapter.php b/src/Phinx/Db/Adapter/SqlServerAdapter.php index cd9e104ee..8ac894398 100644 --- a/src/Phinx/Db/Adapter/SqlServerAdapter.php +++ b/src/Phinx/Db/Adapter/SqlServerAdapter.php @@ -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') From 575d035fe6af4b2cfdf7d91ceaab29289706b582 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Sat, 7 Sep 2024 01:23:32 -0600 Subject: [PATCH 2/2] add sqlsrv test --- tests/Phinx/Db/Adapter/SqlServerAdapterTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php index 20c88c0c3..cdc0e3088 100644 --- a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php @@ -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 = [