Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -27,7 +27,7 @@
"ext-openssl": "*",
"appwrite/appwrite": "19.*",
"utopia-php/database": "5.*",
"utopia-php/storage": "0.18.*",
"utopia-php/storage": "1.0.*",
"utopia-php/dsn": "0.2.*",
"halaxa/json-machine": "^1.2"
},
Expand Down
189 changes: 100 additions & 89 deletions composer.lock

Large diffs are not rendered by default.

42 changes: 25 additions & 17 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,24 +491,32 @@ protected function createField(Column|Attribute $resource): bool
$resource->setStatus(Resource::STATUS_SKIPPED, 'Columns not supported for DocumentsDB');
return false;
}

// column will be matching attribute as well
// column type will be matching attribute type as well
$type = match ($resource->getType()) {
Column::TYPE_DATETIME, Attribute::TYPE_DATETIME => UtopiaDatabase::VAR_DATETIME,
Column::TYPE_BOOLEAN, Attribute::TYPE_BOOLEAN => UtopiaDatabase::VAR_BOOLEAN,
Column::TYPE_INTEGER, Attribute::TYPE_INTEGER => UtopiaDatabase::VAR_INTEGER,
Column::TYPE_FLOAT, Attribute::TYPE_FLOAT => UtopiaDatabase::VAR_FLOAT,
Column::TYPE_RELATIONSHIP, Attribute::TYPE_RELATIONSHIP => UtopiaDatabase::VAR_RELATIONSHIP,
Column::TYPE_STRING, Attribute::TYPE_STRING,
Column::TYPE_IP, Attribute::TYPE_IP,
Column::TYPE_EMAIL, Attribute::TYPE_EMAIL,
Column::TYPE_URL, Attribute::TYPE_URL,
Column::TYPE_ENUM, Attribute::TYPE_ENUM => UtopiaDatabase::VAR_STRING,
Column::TYPE_POINT, Attribute::TYPE_POINT => UtopiaDatabase::VAR_POINT,
Column::TYPE_LINE, Attribute::TYPE_LINE => UtopiaDatabase::VAR_LINESTRING,
Column::TYPE_POLYGON, Attribute::TYPE_POLYGON => UtopiaDatabase::VAR_POLYGON,
Column::TYPE_OBJECT, Attribute::TYPE_OBJECT => UtopiaDatabase::VAR_OBJECT,
Column::TYPE_VECTOR, Attribute::TYPE_VECTOR => UtopiaDatabase::VAR_VECTOR,
default => throw new \Exception('Invalid resource type '.$resource->getType()),
Column::TYPE_DATETIME => UtopiaDatabase::VAR_DATETIME,
Column::TYPE_BOOLEAN => UtopiaDatabase::VAR_BOOLEAN,
Column::TYPE_INTEGER => UtopiaDatabase::VAR_INTEGER,
Column::TYPE_FLOAT => UtopiaDatabase::VAR_FLOAT,
Column::TYPE_RELATIONSHIP => UtopiaDatabase::VAR_RELATIONSHIP,

Column::TYPE_STRING,
Column::TYPE_IP,
Column::TYPE_EMAIL,
Column::TYPE_URL,
Column::TYPE_ENUM => UtopiaDatabase::VAR_STRING,

Column::TYPE_POINT => UtopiaDatabase::VAR_POINT,
Column::TYPE_LINE => UtopiaDatabase::VAR_LINESTRING,
Column::TYPE_POLYGON => UtopiaDatabase::VAR_POLYGON,
Column::TYPE_TEXT => UtopiaDatabase::VAR_TEXT,
Column::TYPE_VARCHAR => UtopiaDatabase::VAR_VARCHAR,
Column::TYPE_MEDIUMTEXT => UtopiaDatabase::VAR_MEDIUMTEXT,
Column::TYPE_LONGTEXT => UtopiaDatabase::VAR_LONGTEXT,
Column::TYPE_OBJECT => UtopiaDatabase::VAR_OBJECT,
Column::TYPE_VECTOR => UtopiaDatabase::VAR_VECTOR,

default => throw new \Exception('Invalid resource type ' . $resource->getType()),
};

$database = $this->dbForProject->getDocument(
Expand Down
35 changes: 33 additions & 2 deletions src/Migration/Resources/Database/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Utopia\Migration\Resource;
use Utopia\Migration\Transfer;

abstract class Attribute extends Resource
class Attribute extends Resource
{
public const TYPE_STRING = 'string';
public const TYPE_INTEGER = 'integer';
Expand All @@ -28,6 +28,7 @@ abstract class Attribute extends Resource
/**
* @param string $key
* @param Table $table
* @param string $fieldType The actual field type (e.g., 'string', 'integer', 'email')
* @param int $size
* @param bool $required
* @param mixed|null $default
Expand All @@ -43,6 +44,7 @@ abstract class Attribute extends Resource
public function __construct(
protected readonly string $key,
protected readonly Table $table,
protected readonly string $fieldType = '',
protected readonly int $size = 0,
protected readonly bool $required = false,
protected readonly mixed $default = null,
Expand Down Expand Up @@ -85,7 +87,36 @@ public static function getName(): string
return Resource::TYPE_ATTRIBUTE;
}

abstract public function getType(): string;
public function getType(): string
{
return $this->fieldType;
}

/**
* Convert a Column resource to an Attribute resource.
*
* @param Column $column
* @return self
*/
public static function fromColumn(Column $column): self
{
return new self(
$column->getKey(),
$column->getTable(),
$column->getType(),
$column->getSize(),
$column->isRequired(),
$column->getDefault(),
$column->isArray(),
$column->isSigned(),
$column->getFormat(),
$column->getFormatOptions(),
$column->getFilters(),
$column->getOptions(),
$column->getCreatedAt(),
$column->getUpdatedAt()
);
}

public function getGroup(): string
{
Expand Down
105 changes: 0 additions & 105 deletions src/Migration/Resources/Database/Attribute/Decimal.php

This file was deleted.

37 changes: 0 additions & 37 deletions src/Migration/Resources/Database/Attribute/Email.php

This file was deleted.

37 changes: 0 additions & 37 deletions src/Migration/Resources/Database/Attribute/IP.php

This file was deleted.

Loading