From 721b51d8076bd06b880526da5eb282dfd08c8d86 Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Mon, 27 May 2024 16:46:18 +0300 Subject: [PATCH 1/2] Added "nativeuuid" type for databases with native uuid support. This is to enable the use of the native uuid for mariadb 10.7+ users. For other database it's simply an alias to the uuid type. Sqlite is explicitly not supported because it doesnt have a native type. --- src/Phinx/Db/Adapter/AdapterInterface.php | 1 + src/Phinx/Db/Adapter/MysqlAdapter.php | 6 ++++++ src/Phinx/Db/Adapter/PostgresAdapter.php | 2 ++ src/Phinx/Db/Adapter/SqlServerAdapter.php | 1 + src/Phinx/Db/Table/Column.php | 1 + 5 files changed, 11 insertions(+) diff --git a/src/Phinx/Db/Adapter/AdapterInterface.php b/src/Phinx/Db/Adapter/AdapterInterface.php index ecce738af..6afd48167 100644 --- a/src/Phinx/Db/Adapter/AdapterInterface.php +++ b/src/Phinx/Db/Adapter/AdapterInterface.php @@ -53,6 +53,7 @@ interface AdapterInterface public const PHINX_TYPE_JSON = 'json'; public const PHINX_TYPE_JSONB = 'jsonb'; public const PHINX_TYPE_UUID = 'uuid'; + public const PHINX_TYPE_NATIVEUUID = 'nativeuuid'; public const PHINX_TYPE_FILESTREAM = 'filestream'; // Geospatial database types diff --git a/src/Phinx/Db/Adapter/MysqlAdapter.php b/src/Phinx/Db/Adapter/MysqlAdapter.php index e7791c655..76e816a35 100644 --- a/src/Phinx/Db/Adapter/MysqlAdapter.php +++ b/src/Phinx/Db/Adapter/MysqlAdapter.php @@ -1104,6 +1104,8 @@ public function getSqlType(Literal|string $type, ?int $limit = null): array return ['name' => 'tinyint', 'limit' => 1]; case static::PHINX_TYPE_UUID: return ['name' => 'char', 'limit' => 36]; + case static::PHINX_TYPE_NATIVEUUID: + return ['name' => 'uuid']; case static::PHINX_TYPE_YEAR: if (!$limit || in_array($limit, [2, 4])) { $limit = 4; @@ -1222,6 +1224,10 @@ public function getPhinxType(string $sqlTypeDef): array $type = static::PHINX_TYPE_BINARYUUID; } break; + case 'uuid': + $type = static::PHINX_TYPE_NATIVEUUID; + $limit = null; + break; } try { diff --git a/src/Phinx/Db/Adapter/PostgresAdapter.php b/src/Phinx/Db/Adapter/PostgresAdapter.php index 2c9e4567d..33d00b0b1 100644 --- a/src/Phinx/Db/Adapter/PostgresAdapter.php +++ b/src/Phinx/Db/Adapter/PostgresAdapter.php @@ -1090,6 +1090,8 @@ public function getSqlType(Literal|string $type, ?int $limit = null): array return ['name' => 'geography', 'type' => 'linestring', 'srid' => 4326]; case static::PHINX_TYPE_POLYGON: return ['name' => 'geography', 'type' => 'polygon', 'srid' => 4326]; + case static::PHINX_TYPE_NATIVEUUID: + return ['name' => 'uuid']; default: if ($this->isArrayType($type)) { return ['name' => $type]; diff --git a/src/Phinx/Db/Adapter/SqlServerAdapter.php b/src/Phinx/Db/Adapter/SqlServerAdapter.php index c6ed3a95f..93c82cdd2 100644 --- a/src/Phinx/Db/Adapter/SqlServerAdapter.php +++ b/src/Phinx/Db/Adapter/SqlServerAdapter.php @@ -1092,6 +1092,7 @@ public function getSqlType(Literal|string $type, ?int $limit = null): array return ['name' => 'bit']; case static::PHINX_TYPE_BINARYUUID: case static::PHINX_TYPE_UUID: + case static::PHINX_TYPE_NATIVEUUID: return ['name' => 'uniqueidentifier']; case static::PHINX_TYPE_FILESTREAM: return ['name' => 'varbinary', 'limit' => 'max']; diff --git a/src/Phinx/Db/Table/Column.php b/src/Phinx/Db/Table/Column.php index f677c7760..3941f037e 100644 --- a/src/Phinx/Db/Table/Column.php +++ b/src/Phinx/Db/Table/Column.php @@ -36,6 +36,7 @@ class Column public const TIMESTAMP = AdapterInterface::PHINX_TYPE_TIMESTAMP; public const UUID = AdapterInterface::PHINX_TYPE_UUID; public const BINARYUUID = AdapterInterface::PHINX_TYPE_BINARYUUID; + public const NATIVEUUID = AdapterInterface::PHINX_TYPE_NATIVEUUID; /** MySQL-only column type */ public const MEDIUMINTEGER = AdapterInterface::PHINX_TYPE_MEDIUM_INTEGER; /** MySQL-only column type */ From 51724fa69483659d6273aa15e11176f09413306d Mon Sep 17 00:00:00 2001 From: Nicos Panayides Date: Thu, 30 May 2024 10:04:03 +0300 Subject: [PATCH 2/2] Use the same case for nativeuuid for postgres --- src/Phinx/Db/Adapter/PostgresAdapter.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Phinx/Db/Adapter/PostgresAdapter.php b/src/Phinx/Db/Adapter/PostgresAdapter.php index 33d00b0b1..adbb3c49d 100644 --- a/src/Phinx/Db/Adapter/PostgresAdapter.php +++ b/src/Phinx/Db/Adapter/PostgresAdapter.php @@ -1072,6 +1072,7 @@ public function getSqlType(Literal|string $type, ?int $limit = null): array case static::PHINX_TYPE_DATETIME: return ['name' => 'timestamp']; case static::PHINX_TYPE_BINARYUUID: + case static::PHINX_TYPE_NATIVEUUID: return ['name' => 'uuid']; case static::PHINX_TYPE_BLOB: case static::PHINX_TYPE_BINARY: @@ -1090,8 +1091,6 @@ public function getSqlType(Literal|string $type, ?int $limit = null): array return ['name' => 'geography', 'type' => 'linestring', 'srid' => 4326]; case static::PHINX_TYPE_POLYGON: return ['name' => 'geography', 'type' => 'polygon', 'srid' => 4326]; - case static::PHINX_TYPE_NATIVEUUID: - return ['name' => 'uuid']; default: if ($this->isArrayType($type)) { return ['name' => $type];