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/Sources/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -3269,6 +3269,10 @@ public static function getRecord(string $databaseType, array $record): Resource

public static function getColumn(Table $table, mixed $column): Column
{
if ($column instanceof UtopiaDocument) {
$column = $column->getArrayCopy();
}

// Appwrite accepts a format (`email`, `url`, `ip`, `enum`) as a type on
// an inline column definition, and reports no size for the types whose
// size the type itself implies. Resolve both the way the server does.
Expand Down
14 changes: 14 additions & 0 deletions tests/Migration/Unit/Sources/AppwriteColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPUnit\Framework\TestCase;
use Utopia\Database\Database as UtopiaDatabase;
use Utopia\Database\Document as UtopiaDocument;
use Utopia\Migration\Resources\Database\Column;
use Utopia\Migration\Resources\Database\Columns\Email;
use Utopia\Migration\Resources\Database\Columns\Enum;
Expand Down Expand Up @@ -108,6 +109,19 @@ public function testStringKeepsItsSize(): void
$this->assertSame(128, $string->getSize());
}

public function testDatabaseDocumentKeepsStringSize(): void
{
$column = Appwrite::getColumn($this->table, new UtopiaDocument($this->payload([
'key' => 'title',
'type' => Column::TYPE_STRING,
'size' => 128,
'format' => '',
])));

$this->assertSame(Text::class, $column::class);
$this->assertSame(128, $column->getSize());
}

public function testFormattedStringsWithoutASize(): void
{
$email = Appwrite::getColumn($this->table, $this->payload([
Expand Down
Loading