Skip to content

Commit 49a90c7

Browse files
feat: add snowflake column type alias (#235)
1 parent 876fbc2 commit 49a90c7

File tree

8 files changed

+102
-0
lines changed

8 files changed

+102
-0
lines changed

psalm-baseline.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,9 @@
884884
<DocblockTypeContradiction>
885885
<code><![CDATA[$size < 0]]></code>
886886
</DocblockTypeContradiction>
887+
<InvalidArgument>
888+
<code><![CDATA[[parent::class, 'compare']]]></code>
889+
</InvalidArgument>
887890
<InvalidClassConstantType>
888891
<code><![CDATA[EXCLUDE_FROM_COMPARE]]></code>
889892
</InvalidClassConstantType>
@@ -900,7 +903,14 @@
900903
<code><![CDATA[$column->comment]]></code>
901904
<code><![CDATA[$column->type]]></code>
902905
<code><![CDATA[$defaultValue]]></code>
906+
<code><![CDATA[$result]]></code>
903907
</MixedAssignment>
908+
<MixedReturnStatement>
909+
<code><![CDATA[$result]]></code>
910+
</MixedReturnStatement>
911+
<PossiblyNullFunctionCall>
912+
<code><![CDATA[\Closure::fromCallable([parent::class, 'compare'])->bindTo($self)($initial)]]></code>
913+
</PossiblyNullFunctionCall>
904914
<PossiblyUndefinedStringArrayOffset>
905915
<code><![CDATA[$matches['type']]]></code>
906916
<code><![CDATA[$schema['Comment']]]></code>

src/Driver/MySQL/Schema/MySQLColumn.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class MySQLColumn extends AbstractColumn
112112

113113
//Additional types
114114
'json' => 'json',
115+
'snowflake' => ['type' => 'bigint', 'size' => 20],
115116
'ulid' => ['type' => 'varchar', 'size' => 26],
116117
'uuid' => ['type' => 'varchar', 'size' => 36],
117118
];

src/Driver/Postgres/Schema/PostgresColumn.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class PostgresColumn extends AbstractColumn
181181
//Additional types
182182
'json' => 'json',
183183
'jsonb' => 'jsonb',
184+
'snowflake' => 'bigint',
184185
'ulid' => ['type' => 'character varying', 'size' => 26],
185186
'uuid' => 'uuid',
186187
'point' => 'point',

src/Driver/SQLServer/Schema/SQLServerColumn.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class SQLServerColumn extends AbstractColumn
9898

9999
//Additional types
100100
'json' => ['type' => 'varchar', 'size' => 0],
101+
'snowflake' => 'bigint',
101102
'ulid' => ['type' => 'varchar', 'size' => 26],
102103
'uuid' => ['type' => 'varchar', 'size' => 36],
103104
];

src/Driver/SQLite/Schema/SQLiteColumn.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class SQLiteColumn extends AbstractColumn
8787

8888
//Additional types
8989
'json' => 'text',
90+
'snowflake' => 'bigint',
9091
'ulid' => ['type' => 'varchar', 'size' => 26],
9192
'uuid' => ['type' => 'varchar', 'size' => 36],
9293
];

src/Schema/AbstractColumn.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
* @method $this|AbstractColumn tinyBinary()
5151
* @method $this|AbstractColumn longBinary()
5252
* @method $this|AbstractColumn json()
53+
* @method $this|AbstractColumn snowflake()
5354
* @method $this|AbstractColumn ulid()
5455
* @method $this|AbstractColumn uuid()
5556
*/

src/Schema/AbstractTable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
* @method AbstractColumn binary($column)
5252
* @method AbstractColumn tinyBinary($column)
5353
* @method AbstractColumn longBinary($column)
54+
* @method AbstractColumn snowflake($column)
5455
* @method AbstractColumn ulid($column)
5556
* @method AbstractColumn uuid($column)
5657
*/

tests/Database/Functional/Driver/Common/Schema/ConsistencyTest.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,92 @@ public function testTime(): void
360360
$this->assertTrue($schema->column('target')->compare($column));
361361
}
362362

363+
public function testSnowflake(): void
364+
{
365+
$schema = $this->schema('table');
366+
$this->assertFalse($schema->exists());
367+
368+
$column = $schema->snowflake('target');
369+
370+
$schema->save();
371+
372+
$schema = $this->schema('table');
373+
$this->assertTrue($schema->exists());
374+
$this->assertTrue($schema->column('target')->compare($column));
375+
$this->assertSame('int', $schema->column('target')->getType());
376+
377+
$this->database->table('table')->insertOne(
378+
[
379+
'target' => 7340580095540599922,
380+
],
381+
);
382+
383+
$this->assertEquals(
384+
[
385+
'target' => 7340580095540599922,
386+
],
387+
$this->database->table('table')->select()->fetchAll()[0],
388+
);
389+
}
390+
391+
public function testSnowflakeCallingColumnMethod(): void
392+
{
393+
$schema = $this->schema('table');
394+
$this->assertFalse($schema->exists());
395+
396+
$column = $schema->column('target')->snowflake();
397+
398+
$schema->save();
399+
400+
$schema = $this->schema('table');
401+
$this->assertTrue($schema->exists());
402+
$this->assertTrue($schema->column('target')->compare($column));
403+
$this->assertSame('int', $schema->column('target')->getType());
404+
405+
$this->database->table('table')->insertOne(
406+
[
407+
'target' => 7340580095540599922,
408+
],
409+
);
410+
411+
$this->assertEquals(
412+
[
413+
'target' => 7340580095540599922,
414+
],
415+
$this->database->table('table')->select()->fetchAll()[0],
416+
);
417+
}
418+
419+
public function testSnowflakePrimary(): void
420+
{
421+
$schema = $this->schema('table');
422+
$this->assertFalse($schema->exists());
423+
424+
$column = $schema->snowflake('target')->nullable(false);
425+
$schema->setPrimaryKeys(['target']);
426+
$schema->save();
427+
428+
$schema = $this->schema('table');
429+
$this->assertTrue($schema->exists());
430+
431+
$this->assertTrue($schema->column('target')->compare($column));
432+
$this->assertSame('int', $schema->column('target')->getType());
433+
$this->assertSame(['target'], $schema->getPrimaryKeys());
434+
435+
$this->database->table('table')->insertOne(
436+
[
437+
'target' => 7340580095540599922,
438+
],
439+
);
440+
441+
$this->assertEquals(
442+
[
443+
'target' => 7340580095540599922,
444+
],
445+
$this->database->table('table')->select()->fetchAll()[0],
446+
);
447+
}
448+
363449
public function testUlid(): void
364450
{
365451
$schema = $this->schema('table');

0 commit comments

Comments
 (0)