Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ext-curl": "*",
"ext-openssl": "*",
"appwrite/appwrite": "19.*",
"utopia-php/database": "5.*",
"utopia-php/database": "dev-big-init as 5.4",
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
"utopia-php/storage": "1.0.*",
"utopia-php/dsn": "0.2.*",
"halaxa/json-machine": "^1.2"
Expand Down
117 changes: 40 additions & 77 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ protected function createField(Column|Attribute $resource): bool
Column::TYPE_DATETIME => UtopiaDatabase::VAR_DATETIME,
Column::TYPE_BOOLEAN => UtopiaDatabase::VAR_BOOLEAN,
Column::TYPE_INTEGER => UtopiaDatabase::VAR_INTEGER,
Column::TYPE_BIG_INT => UtopiaDatabase::VAR_BIGINT,
Column::TYPE_FLOAT => UtopiaDatabase::VAR_FLOAT,
Column::TYPE_RELATIONSHIP => UtopiaDatabase::VAR_RELATIONSHIP,

Expand Down
1 change: 1 addition & 0 deletions src/Migration/Resources/Database/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract class Column extends Resource
public const TYPE_LONGTEXT = 'longtext';

public const TYPE_INTEGER = 'integer';
public const TYPE_BIG_INT = 'bigint';
public const TYPE_FLOAT = 'double';
public const TYPE_BOOLEAN = 'boolean';
public const TYPE_DATETIME = 'datetime';
Expand Down
107 changes: 107 additions & 0 deletions src/Migration/Resources/Database/Columns/BigInt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace Utopia\Migration\Resources\Database\Columns;

use Utopia\Migration\Resources\Database\Column;
use Utopia\Migration\Resources\Database\Table;

class BigInt extends Column
{
public function __construct(
string $key,
Table $table,
bool $required = false,
?int $default = null,
bool $array = false,
?int $min = null,
?int $max = null,
bool $signed = true,
string $createdAt = '',
string $updatedAt = ''
) {
$min ??= PHP_INT_MIN;
$max ??= PHP_INT_MAX;
$size = 8;
Comment thread
abnegate marked this conversation as resolved.

parent::__construct(
$key,
$table,
size: $size,
required: $required,
default: $default,
array: $array,
signed: $signed,
formatOptions: [
'min' => $min,
'max' => $max,
],
createdAt: $createdAt,
updatedAt: $updatedAt
);
}

/**
* @param array{
* key: string,
* collection?: array{
* database: array{
* id: string,
* name: string,
* },
* name: string,
* id: string,
* documentSecurity: bool,
* permissions: ?array<string>
* },
* table?: array{
* database: array{
* id: string,
* name: string,
* },
* name: string,
* id: string,
* rowSecurity: bool,
* permissions: ?array<string>
* },
* required: bool,
* array: bool,
* default: ?int,
* formatOptions: array{
* min: ?int,
* max: ?int
* },
* createdAt: string,
* updatedAt: string,
* } $array
* @return self
*/
public static function fromArray(array $array): self
{
return new self(
$array['key'],
Table::fromArray($array['table'] ?? $array['collection']),
required: $array['required'],
default: $array['default'],
array: $array['array'],
min: $array['formatOptions']['min'] ?? null,
max: $array['formatOptions']['max'] ?? null,
createdAt: $array['createdAt'] ?? '',
updatedAt: $array['updatedAt'] ?? '',
);
Comment thread
ArnabChatterjee20k marked this conversation as resolved.
}

public function getType(): string
{
return Column::TYPE_BIG_INT;
}

public function getMin(): ?int
{
return (int)$this->formatOptions['min'];
}

public function getMax(): ?int
{
return (int)$this->formatOptions['max'];
}
}
13 changes: 13 additions & 0 deletions src/Migration/Sources/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Utopia\Migration\Resources\Database\Attribute;
use Utopia\Migration\Resources\Database\Collection;
use Utopia\Migration\Resources\Database\Column;
use Utopia\Migration\Resources\Database\Columns\BigInt;
use Utopia\Migration\Resources\Database\Columns\Boolean;
use Utopia\Migration\Resources\Database\Columns\DateTime;
use Utopia\Migration\Resources\Database\Columns\Decimal;
Expand Down Expand Up @@ -2368,6 +2369,18 @@ public static function getColumn(Table $table, mixed $column): Column
updatedAt: $column['$updatedAt'] ?? '',
),

Column::TYPE_BIG_INT => new BigInt(
$column['key'],
$table,
required: $column['required'],
default: $column['default'],
array: $column['array'],
min: $column['min'] ?? null,
max: $column['max'] ?? null,
createdAt: $column['$createdAt'] ?? '',
updatedAt: $column['$updatedAt'] ?? '',
),
Comment thread
greptile-apps[bot] marked this conversation as resolved.

Column::TYPE_FLOAT => new Decimal(
$column['key'],
$table,
Expand Down
5 changes: 3 additions & 2 deletions src/Migration/Sources/CSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private function exportRows(int $batchSize): void

$parsedData[$key] = array_map(function ($item) use ($type) {
return match ($type) {
Column::TYPE_INTEGER => is_numeric($item) ? (int)$item : null,
Column::TYPE_INTEGER,Column::TYPE_BIG_INT => is_numeric($item) ? (int)$item : null,
Column::TYPE_FLOAT => is_numeric($item) ? (float)$item : null,
Column::TYPE_BOOLEAN => filter_var($item, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE),
default => $item,
Expand All @@ -323,14 +323,15 @@ private function exportRows(int $batchSize): void
'null' => null, // 'null' string is converted to null
'' => match ($type) {
Column::TYPE_INTEGER,
Column::TYPE_BIG_INT,
Column::TYPE_FLOAT,
Column::TYPE_BOOLEAN,
Column::TYPE_DATETIME,
Column::TYPE_RELATIONSHIP => null, // primitive types default to null
default => '', // but empty string stays empty string for compatibility
},
default => match ($type) {
Column::TYPE_INTEGER => \is_numeric($parsedValue) ? (int)$parsedValue : null,
Column::TYPE_INTEGER, Column::TYPE_BIG_INT => \is_numeric($parsedValue) ? (int)$parsedValue : null,
Column::TYPE_FLOAT => \is_numeric($parsedValue) ? (float)$parsedValue : null,
Column::TYPE_BOOLEAN => \filter_var(
$parsedValue,
Expand Down
Loading
Loading