Skip to content

Commit c3ea0d6

Browse files
feat: add BigInt column type support and update related classes
1 parent 7a86aea commit c3ea0d6

8 files changed

Lines changed: 168 additions & 81 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"ext-curl": "*",
2727
"ext-openssl": "*",
2828
"appwrite/appwrite": "19.*",
29-
"utopia-php/database": "5.*",
29+
"utopia-php/database": "dev-big-init as 5.4",
3030
"utopia-php/storage": "1.0.*",
3131
"utopia-php/dsn": "0.2.*",
3232
"halaxa/json-machine": "^1.2"

composer.lock

Lines changed: 40 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Migration/Destinations/Appwrite.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ protected function createField(Column|Attribute $resource): bool
542542
Column::TYPE_DATETIME => UtopiaDatabase::VAR_DATETIME,
543543
Column::TYPE_BOOLEAN => UtopiaDatabase::VAR_BOOLEAN,
544544
Column::TYPE_INTEGER => UtopiaDatabase::VAR_INTEGER,
545+
Column::TYPE_BIG_INT => UtopiaDatabase::VAR_BIGINT,
545546
Column::TYPE_FLOAT => UtopiaDatabase::VAR_FLOAT,
546547
Column::TYPE_RELATIONSHIP => UtopiaDatabase::VAR_RELATIONSHIP,
547548

src/Migration/Resources/Database/Column.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ abstract class Column extends Resource
1414
public const TYPE_LONGTEXT = 'longtext';
1515

1616
public const TYPE_INTEGER = 'integer';
17+
public const TYPE_BIG_INT = 'bigint';
1718
public const TYPE_FLOAT = 'double';
1819
public const TYPE_BOOLEAN = 'boolean';
1920
public const TYPE_DATETIME = 'datetime';
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace Utopia\Migration\Resources\Database\Columns;
4+
5+
use Utopia\Migration\Resources\Database\Column;
6+
use Utopia\Migration\Resources\Database\Table;
7+
8+
class BigInt extends Column
9+
{
10+
public function __construct(
11+
string $key,
12+
Table $table,
13+
bool $required = false,
14+
?int $default = null,
15+
bool $array = false,
16+
?int $min = null,
17+
?int $max = null,
18+
bool $signed = true,
19+
string $createdAt = '',
20+
string $updatedAt = ''
21+
) {
22+
$min ??= PHP_INT_MIN;
23+
$max ??= PHP_INT_MAX;
24+
$size = 8;
25+
26+
parent::__construct(
27+
$key,
28+
$table,
29+
size: $size,
30+
required: $required,
31+
default: $default,
32+
array: $array,
33+
signed: $signed,
34+
formatOptions: [
35+
'min' => $min,
36+
'max' => $max,
37+
],
38+
createdAt: $createdAt,
39+
updatedAt: $updatedAt
40+
);
41+
}
42+
43+
/**
44+
* @param array{
45+
* key: string,
46+
* collection?: array{
47+
* database: array{
48+
* id: string,
49+
* name: string,
50+
* },
51+
* name: string,
52+
* id: string,
53+
* documentSecurity: bool,
54+
* permissions: ?array<string>
55+
* },
56+
* table?: array{
57+
* database: array{
58+
* id: string,
59+
* name: string,
60+
* },
61+
* name: string,
62+
* id: string,
63+
* rowSecurity: bool,
64+
* permissions: ?array<string>
65+
* },
66+
* required: bool,
67+
* array: bool,
68+
* default: ?int,
69+
* formatOptions: array{
70+
* min: ?int,
71+
* max: ?int
72+
* },
73+
* createdAt: string,
74+
* updatedAt: string,
75+
* } $array
76+
* @return self
77+
*/
78+
public static function fromArray(array $array): self
79+
{
80+
return new self(
81+
$array['key'],
82+
Table::fromArray($array['table'] ?? $array['collection']),
83+
required: $array['required'],
84+
default: $array['default'],
85+
array: $array['array'],
86+
min: $array['formatOptions']['min'] ?? null,
87+
max: $array['formatOptions']['max'] ?? null,
88+
createdAt: $array['createdAt'] ?? '',
89+
updatedAt: $array['updatedAt'] ?? '',
90+
);
91+
}
92+
93+
public function getType(): string
94+
{
95+
return Column::TYPE_BIG_INT;
96+
}
97+
98+
public function getMin(): ?int
99+
{
100+
return (int)$this->formatOptions['min'];
101+
}
102+
103+
public function getMax(): ?int
104+
{
105+
return (int)$this->formatOptions['max'];
106+
}
107+
}

src/Migration/Sources/Appwrite.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Utopia\Migration\Resources\Database\Attribute;
2525
use Utopia\Migration\Resources\Database\Collection;
2626
use Utopia\Migration\Resources\Database\Column;
27+
use Utopia\Migration\Resources\Database\Columns\BigInt;
2728
use Utopia\Migration\Resources\Database\Columns\Boolean;
2829
use Utopia\Migration\Resources\Database\Columns\DateTime;
2930
use Utopia\Migration\Resources\Database\Columns\Decimal;
@@ -2368,6 +2369,18 @@ public static function getColumn(Table $table, mixed $column): Column
23682369
updatedAt: $column['$updatedAt'] ?? '',
23692370
),
23702371

2372+
Column::TYPE_BIG_INT => new BigInt(
2373+
$column['key'],
2374+
$table,
2375+
required: $column['required'],
2376+
default: $column['default'],
2377+
array: $column['array'],
2378+
min: $column['min'] ?? null,
2379+
max: $column['max'] ?? null,
2380+
createdAt: $column['$createdAt'] ?? '',
2381+
updatedAt: $column['$updatedAt'] ?? '',
2382+
),
2383+
23712384
Column::TYPE_FLOAT => new Decimal(
23722385
$column['key'],
23732386
$table,

src/Migration/Sources/CSV.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private function exportRows(int $batchSize): void
301301

302302
$parsedData[$key] = array_map(function ($item) use ($type) {
303303
return match ($type) {
304-
Column::TYPE_INTEGER => is_numeric($item) ? (int)$item : null,
304+
Column::TYPE_INTEGER,Column::TYPE_BIG_INT => is_numeric($item) ? (int)$item : null,
305305
Column::TYPE_FLOAT => is_numeric($item) ? (float)$item : null,
306306
Column::TYPE_BOOLEAN => filter_var($item, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
307307
default => $item,
@@ -323,14 +323,15 @@ private function exportRows(int $batchSize): void
323323
'null' => null, // 'null' string is converted to null
324324
'' => match ($type) {
325325
Column::TYPE_INTEGER,
326+
Column::TYPE_BIG_INT,
326327
Column::TYPE_FLOAT,
327328
Column::TYPE_BOOLEAN,
328329
Column::TYPE_DATETIME,
329330
Column::TYPE_RELATIONSHIP => null, // primitive types default to null
330331
default => '', // but empty string stays empty string for compatibility
331332
},
332333
default => match ($type) {
333-
Column::TYPE_INTEGER => \is_numeric($parsedValue) ? (int)$parsedValue : null,
334+
Column::TYPE_INTEGER, Column::TYPE_BIG_INT => \is_numeric($parsedValue) ? (int)$parsedValue : null,
334335
Column::TYPE_FLOAT => \is_numeric($parsedValue) ? (float)$parsedValue : null,
335336
Column::TYPE_BOOLEAN => \filter_var(
336337
$parsedValue,

0 commit comments

Comments
 (0)