diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index e649443a..61443459 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -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. diff --git a/tests/Migration/Unit/Sources/AppwriteColumnTest.php b/tests/Migration/Unit/Sources/AppwriteColumnTest.php index 743b9ace..b79e6812 100644 --- a/tests/Migration/Unit/Sources/AppwriteColumnTest.php +++ b/tests/Migration/Unit/Sources/AppwriteColumnTest.php @@ -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; @@ -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([