Skip to content

Commit

Permalink
Merge pull request #1826 from MasterOdin/sqlserver_binary_uuid
Browse files Browse the repository at this point in the history
Add support for BinaryUUID to SqlServer
  • Loading branch information
dereuromark committed Jun 25, 2020
2 parents 1b88860 + 4af7c57 commit c63dcec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Phinx/Db/Adapter/SqlServerAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class SqlServerAdapter extends PdoAdapter
*/
protected static $specificColumnTypes = [
self::PHINX_TYPE_FILESTREAM,
self::PHINX_TYPE_BINARYUUID,
];

/**
Expand Down Expand Up @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions tests/Phinx/Db/Adapter/SqlServerAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c63dcec

Please sign in to comment.