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
4 changes: 4 additions & 0 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ protected function createColumn(Column $resource): bool
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,
default => throw new \Exception('Invalid resource type '.$resource->getType()),
};

Expand Down
5 changes: 5 additions & 0 deletions src/Migration/Resources/Database/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
abstract class Column extends Resource
{
public const TYPE_STRING = 'string';
public const TYPE_TEXT = 'text';
public const TYPE_VARCHAR = 'varchar';
public const TYPE_MEDIUMTEXT = 'mediumtext';
public const TYPE_LONGTEXT = 'longtext';

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

namespace Utopia\Migration\Resources\Database\Columns;

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

class LongText extends Column
{
public function __construct(
string $key,
Table $table,
bool $required = false,
?string $default = null,
bool $array = false,
int $size = 2147483647,
string $format = '',
string $createdAt = '',
string $updatedAt = ''
) {
parent::__construct(
$key,
$table,
size: $size,
required: $required,
default: $default,
array: $array,
format: $format,
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,
* default: ?string,
* array: bool,
* size: int,
* format: string,
* 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'] ?? null,
array: $array['array'],
size: $array['size'],
format: $array['format'],
createdAt: $array['createdAt'] ?? '',
updatedAt: $array['updatedAt'] ?? '',
);
}

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

public function getSize(): int
{
return $this->size;
}

public function getFormat(): string
{
return $this->format;
}
}
97 changes: 97 additions & 0 deletions src/Migration/Resources/Database/Columns/MediumText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

namespace Utopia\Migration\Resources\Database\Columns;

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

class MediumText extends Column
{
public function __construct(
string $key,
Table $table,
bool $required = false,
?string $default = null,
bool $array = false,
int $size = 16777215,
string $format = '',
string $createdAt = '',
string $updatedAt = ''
) {
parent::__construct(
$key,
$table,
size: $size,
required: $required,
default: $default,
array: $array,
format: $format,
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,
* default: ?string,
* array: bool,
* size: int,
* format: string,
* 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'] ?? null,
array: $array['array'],
size: $array['size'],
format: $array['format'],
createdAt: $array['createdAt'] ?? '',
updatedAt: $array['updatedAt'] ?? '',
);
}

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

public function getSize(): int
{
return $this->size;
}

public function getFormat(): string
{
return $this->format;
}
}
97 changes: 97 additions & 0 deletions src/Migration/Resources/Database/Columns/RegularText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

namespace Utopia\Migration\Resources\Database\Columns;

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

class RegularText extends Column
{
public function __construct(
string $key,
Table $table,
bool $required = false,
?string $default = null,
bool $array = false,
int $size = 65535,
string $format = '',
string $createdAt = '',
string $updatedAt = ''
) {
parent::__construct(
$key,
$table,
size: $size,
required: $required,
default: $default,
array: $array,
format: $format,
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,
* default: ?string,
* array: bool,
* size: int,
* format: string,
* 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'] ?? null,
array: $array['array'],
size: $array['size'],
format: $array['format'],
createdAt: $array['createdAt'] ?? '',
updatedAt: $array['updatedAt'] ?? '',
);
}

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

public function getSize(): int
{
return $this->size;
}

public function getFormat(): string
{
return $this->format;
}
}
Loading