From 9a3c961bd754ab2b6681292c0045928d1394713d Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Thu, 25 Jun 2020 18:38:39 -0400 Subject: [PATCH 1/2] Add support for BinaryUUID to SqlServer Signed-off-by: Matthew Peveler --- src/Phinx/Db/Adapter/SqlServerAdapter.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Phinx/Db/Adapter/SqlServerAdapter.php b/src/Phinx/Db/Adapter/SqlServerAdapter.php index cac8e5aff..ebede8bf3 100644 --- a/src/Phinx/Db/Adapter/SqlServerAdapter.php +++ b/src/Phinx/Db/Adapter/SqlServerAdapter.php @@ -34,6 +34,7 @@ class SqlServerAdapter extends PdoAdapter */ protected static $specificColumnTypes = [ self::PHINX_TYPE_FILESTREAM, + self::PHINX_TYPE_BINARYUUID, ]; /** @@ -1078,6 +1079,7 @@ public function getSqlType($type, $limit = null) return ['name' => 'varbinary']; case static::PHINX_TYPE_BOOLEAN: return ['name' => 'bit']; + case static::PHINX_TYPE_BINARYUUID: case static::PHINX_TYPE_UUID: return ['name' => 'uniqueidentifier']; case static::PHINX_TYPE_FILESTREAM: From 4af7c579341191c435360cf60d552794b6f30b15 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Thu, 25 Jun 2020 18:40:57 -0400 Subject: [PATCH 2/2] add testcase Signed-off-by: Matthew Peveler --- .../Phinx/Db/Adapter/SqlServerAdapterTest.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php index 4463e5558..c33601569 100644 --- a/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php +++ b/tests/Phinx/Db/Adapter/SqlServerAdapterTest.php @@ -234,6 +234,34 @@ public function testCreateTableWithMultiplePrimaryKeys() $this->assertFalse($this->adapter->hasIndex('table1', ['tag_id', 'user_email'])); } + public function testCreateTableWithPrimaryKeyAsUuid() + { + $options = [ + 'id' => false, + 'primary_key' => 'id', + ]; + $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table->addColumn('id', 'uuid')->save(); + $table->addColumn('user_id', 'integer')->save(); + $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); + $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); + $this->assertTrue($this->adapter->hasColumn('ztable', 'user_id')); + } + + public function testCreateTableWithPrimaryKeyAsBinaryUuid() + { + $options = [ + 'id' => false, + 'primary_key' => 'id', + ]; + $table = new \Phinx\Db\Table('ztable', $options, $this->adapter); + $table->addColumn('id', 'binaryuuid')->save(); + $table->addColumn('user_id', 'integer')->save(); + $this->assertTrue($this->adapter->hasColumn('ztable', 'id')); + $this->assertTrue($this->adapter->hasIndex('ztable', 'id')); + $this->assertTrue($this->adapter->hasColumn('ztable', 'user_id')); + } + public function testCreateTableWithMultipleIndexes() { $table = new \Phinx\Db\Table('table1', [], $this->adapter);