diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 4440ea0a..2681f1e4 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -296,6 +296,7 @@ + @@ -379,6 +380,7 @@ + @@ -901,12 +903,12 @@ + - @@ -914,6 +916,7 @@ + @@ -1303,10 +1306,10 @@ + - @@ -1321,6 +1324,7 @@ + @@ -1330,7 +1334,6 @@ - + + + + + + getParameters()]]> + + prefix]]> diff --git a/src/Driver/Jsoner.php b/src/Driver/Jsoner.php index 7bc50eaa..fe08c02c 100644 --- a/src/Driver/Jsoner.php +++ b/src/Driver/Jsoner.php @@ -32,7 +32,7 @@ public static function toJson(mixed $value, bool $encode = true, bool $validate $result = (string) $value; - if ($validate && !json_validate($result)) { + if ($validate && !\json_validate($result)) { throw new BuilderException('Invalid JSON value.'); } diff --git a/src/Driver/MySQL/Schema/MySQLColumn.php b/src/Driver/MySQL/Schema/MySQLColumn.php index c8cf6464..ad823afa 100644 --- a/src/Driver/MySQL/Schema/MySQLColumn.php +++ b/src/Driver/MySQL/Schema/MySQLColumn.php @@ -112,6 +112,7 @@ class MySQLColumn extends AbstractColumn //Additional types 'json' => 'json', + 'ulid' => ['type' => 'varchar', 'size' => 26], 'uuid' => ['type' => 'varchar', 'size' => 36], ]; protected array $reverseMapping = [ diff --git a/src/Driver/Postgres/Schema/PostgresColumn.php b/src/Driver/Postgres/Schema/PostgresColumn.php index 49bc1cc1..f726c203 100644 --- a/src/Driver/Postgres/Schema/PostgresColumn.php +++ b/src/Driver/Postgres/Schema/PostgresColumn.php @@ -181,6 +181,7 @@ class PostgresColumn extends AbstractColumn //Additional types 'json' => 'json', 'jsonb' => 'jsonb', + 'ulid' => ['type' => 'character varying', 'size' => 26], 'uuid' => 'uuid', 'point' => 'point', 'line' => 'line', diff --git a/src/Driver/SQLServer/Schema/SQLServerColumn.php b/src/Driver/SQLServer/Schema/SQLServerColumn.php index d8b47681..9e960698 100644 --- a/src/Driver/SQLServer/Schema/SQLServerColumn.php +++ b/src/Driver/SQLServer/Schema/SQLServerColumn.php @@ -98,6 +98,7 @@ class SQLServerColumn extends AbstractColumn //Additional types 'json' => ['type' => 'varchar', 'size' => 0], + 'ulid' => ['type' => 'varchar', 'size' => 26], 'uuid' => ['type' => 'varchar', 'size' => 36], ]; protected array $reverseMapping = [ diff --git a/src/Driver/SQLite/Schema/SQLiteColumn.php b/src/Driver/SQLite/Schema/SQLiteColumn.php index 25eec9e5..cef671e0 100644 --- a/src/Driver/SQLite/Schema/SQLiteColumn.php +++ b/src/Driver/SQLite/Schema/SQLiteColumn.php @@ -87,6 +87,7 @@ class SQLiteColumn extends AbstractColumn //Additional types 'json' => 'text', + 'ulid' => ['type' => 'varchar', 'size' => 26], 'uuid' => ['type' => 'varchar', 'size' => 36], ]; protected array $reverseMapping = [ diff --git a/src/Schema/AbstractColumn.php b/src/Schema/AbstractColumn.php index f83ceb79..283d29ad 100644 --- a/src/Schema/AbstractColumn.php +++ b/src/Schema/AbstractColumn.php @@ -50,6 +50,7 @@ * @method $this|AbstractColumn tinyBinary() * @method $this|AbstractColumn longBinary() * @method $this|AbstractColumn json() + * @method $this|AbstractColumn ulid() * @method $this|AbstractColumn uuid() */ abstract class AbstractColumn implements ColumnInterface, ElementInterface diff --git a/src/Schema/AbstractTable.php b/src/Schema/AbstractTable.php index 5e495d94..a0eb97ac 100644 --- a/src/Schema/AbstractTable.php +++ b/src/Schema/AbstractTable.php @@ -51,6 +51,7 @@ * @method AbstractColumn binary($column) * @method AbstractColumn tinyBinary($column) * @method AbstractColumn longBinary($column) + * @method AbstractColumn ulid($column) * @method AbstractColumn uuid($column) */ abstract class AbstractTable implements TableInterface, ElementInterface diff --git a/tests/Database/Functional/Driver/Common/Schema/ConsistencyTest.php b/tests/Database/Functional/Driver/Common/Schema/ConsistencyTest.php index 5074c9b5..d060575b 100644 --- a/tests/Database/Functional/Driver/Common/Schema/ConsistencyTest.php +++ b/tests/Database/Functional/Driver/Common/Schema/ConsistencyTest.php @@ -360,6 +360,92 @@ public function testTime(): void $this->assertTrue($schema->column('target')->compare($column)); } + public function testUlid(): void + { + $schema = $this->schema('table'); + $this->assertFalse($schema->exists()); + + $column = $schema->ulid('target'); + + $schema->save(); + + $schema = $this->schema('table'); + $this->assertTrue($schema->exists()); + $this->assertTrue($schema->column('target')->compare($column)); + $this->assertSame('string', $schema->column('target')->getType()); + + $this->database->table('table')->insertOne( + [ + 'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC', + ], + ); + + $this->assertEquals( + [ + 'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC', + ], + $this->database->table('table')->select()->fetchAll()[0], + ); + } + + public function testUlidCallingColumnMethod(): void + { + $schema = $this->schema('table'); + $this->assertFalse($schema->exists()); + + $column = $schema->column('target')->ulid(); + + $schema->save(); + + $schema = $this->schema('table'); + $this->assertTrue($schema->exists()); + $this->assertTrue($schema->column('target')->compare($column)); + $this->assertSame('string', $schema->column('target')->getType()); + + $this->database->table('table')->insertOne( + [ + 'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC', + ], + ); + + $this->assertEquals( + [ + 'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC', + ], + $this->database->table('table')->select()->fetchAll()[0], + ); + } + + public function testUlidPrimary(): void + { + $schema = $this->schema('table'); + $this->assertFalse($schema->exists()); + + $column = $schema->ulid('target')->nullable(false); + $schema->setPrimaryKeys(['target']); + $schema->save(); + + $schema = $this->schema('table'); + $this->assertTrue($schema->exists()); + + $this->assertTrue($schema->column('target')->compare($column)); + $this->assertSame('string', $schema->column('target')->getType()); + $this->assertSame(['target'], $schema->getPrimaryKeys()); + + $this->database->table('table')->insertOne( + [ + 'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC', + ], + ); + + $this->assertEquals( + [ + 'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC', + ], + $this->database->table('table')->select()->fetchAll()[0], + ); + } + public function testUuid(): void { $schema = $this->schema('table'); @@ -388,6 +474,34 @@ public function testUuid(): void ); } + public function testUuidCallingColumnMethod(): void + { + $schema = $this->schema('table'); + $this->assertFalse($schema->exists()); + + $column = $schema->column('target')->uuid(); + + $schema->save(); + + $schema = $this->schema('table'); + $this->assertTrue($schema->exists()); + $this->assertTrue($schema->column('target')->compare($column)); + $this->assertSame('string', $schema->column('target')->getType()); + + $this->database->table('table')->insertOne( + [ + 'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', + ], + ); + + $this->assertEquals( + [ + 'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', + ], + $this->database->table('table')->select()->fetchAll()[0], + ); + } + public function testUuidPrimary(): void { $schema = $this->schema('table');