diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index e5a13f7..6b730a1 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -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()), }; diff --git a/src/Migration/Resources/Database/Column.php b/src/Migration/Resources/Database/Column.php index e064a40..c1b82e8 100644 --- a/src/Migration/Resources/Database/Column.php +++ b/src/Migration/Resources/Database/Column.php @@ -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'; diff --git a/src/Migration/Resources/Database/Columns/LongText.php b/src/Migration/Resources/Database/Columns/LongText.php new file mode 100644 index 0000000..7f6230c --- /dev/null +++ b/src/Migration/Resources/Database/Columns/LongText.php @@ -0,0 +1,97 @@ + + * }, + * table?: array{ + * database: array{ + * id: string, + * name: string, + * }, + * name: string, + * id: string, + * rowSecurity: bool, + * permissions: ?array + * }, + * 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; + } +} diff --git a/src/Migration/Resources/Database/Columns/MediumText.php b/src/Migration/Resources/Database/Columns/MediumText.php new file mode 100644 index 0000000..35acc31 --- /dev/null +++ b/src/Migration/Resources/Database/Columns/MediumText.php @@ -0,0 +1,97 @@ + + * }, + * table?: array{ + * database: array{ + * id: string, + * name: string, + * }, + * name: string, + * id: string, + * rowSecurity: bool, + * permissions: ?array + * }, + * 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; + } +} diff --git a/src/Migration/Resources/Database/Columns/RegularText.php b/src/Migration/Resources/Database/Columns/RegularText.php new file mode 100644 index 0000000..9ae55b1 --- /dev/null +++ b/src/Migration/Resources/Database/Columns/RegularText.php @@ -0,0 +1,97 @@ + + * }, + * table?: array{ + * database: array{ + * id: string, + * name: string, + * }, + * name: string, + * id: string, + * rowSecurity: bool, + * permissions: ?array + * }, + * 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; + } +} diff --git a/src/Migration/Resources/Database/Columns/Varchar.php b/src/Migration/Resources/Database/Columns/Varchar.php new file mode 100644 index 0000000..9df3a4b --- /dev/null +++ b/src/Migration/Resources/Database/Columns/Varchar.php @@ -0,0 +1,97 @@ + + * }, + * table?: array{ + * database: array{ + * id: string, + * name: string, + * }, + * name: string, + * id: string, + * rowSecurity: bool, + * permissions: ?array + * }, + * 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_VARCHAR; + } + + public function getSize(): int + { + return $this->size; + } + + public function getFormat(): string + { + return $this->format; + } +} diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index d07688a..c99b667 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -28,11 +28,15 @@ use Utopia\Migration\Resources\Database\Columns\Integer; use Utopia\Migration\Resources\Database\Columns\IP; use Utopia\Migration\Resources\Database\Columns\Line; +use Utopia\Migration\Resources\Database\Columns\LongText; +use Utopia\Migration\Resources\Database\Columns\MediumText; use Utopia\Migration\Resources\Database\Columns\Point; use Utopia\Migration\Resources\Database\Columns\Polygon; +use Utopia\Migration\Resources\Database\Columns\RegularText; use Utopia\Migration\Resources\Database\Columns\Relationship; use Utopia\Migration\Resources\Database\Columns\Text; use Utopia\Migration\Resources\Database\Columns\URL; +use Utopia\Migration\Resources\Database\Columns\Varchar; use Utopia\Migration\Resources\Database\Database; use Utopia\Migration\Resources\Database\Index; use Utopia\Migration\Resources\Database\Row; @@ -1090,6 +1094,58 @@ private function exportColumns(int $batchSize): void updatedAt: $column['$updatedAt'] ?? '', ); break; + + case Column::TYPE_VARCHAR: + $col = new Varchar( + $column['key'], + $table, + required: $column['required'], + default: $column['default'], + array: $column['array'], + size: $column['size'] ?? 255, + createdAt: $column['$createdAt'] ?? '', + updatedAt: $column['$updatedAt'] ?? '', + ); + break; + + case Column::TYPE_TEXT: + $col = new RegularText( + $column['key'], + $table, + required: $column['required'], + default: $column['default'], + array: $column['array'], + size: $column['size'] ?? 65535, + createdAt: $column['$createdAt'] ?? '', + updatedAt: $column['$updatedAt'] ?? '', + ); + break; + + case Column::TYPE_MEDIUMTEXT: + $col = new MediumText( + $column['key'], + $table, + required: $column['required'], + default: $column['default'], + array: $column['array'], + size: $column['size'] ?? 16777215, + createdAt: $column['$createdAt'] ?? '', + updatedAt: $column['$updatedAt'] ?? '', + ); + break; + + case Column::TYPE_LONGTEXT: + $col = new LongText( + $column['key'], + $table, + required: $column['required'], + default: $column['default'], + array: $column['array'], + size: $column['size'] ?? 2147483647, + createdAt: $column['$createdAt'] ?? '', + updatedAt: $column['$updatedAt'] ?? '', + ); + break; } if (!isset($col)) { diff --git a/tests/Migration/E2E/Sources/NHostTest.php b/tests/Migration/E2E/Sources/NHostTest.php index ca4d9f3..d269ad0 100644 --- a/tests/Migration/E2E/Sources/NHostTest.php +++ b/tests/Migration/E2E/Sources/NHostTest.php @@ -109,7 +109,8 @@ public function testRunTransfer($state) { $this->transfer->run( $this->source->getSupportedResources(), - function () {} + function () { + } ); $this->assertCount(0, $this->transfer->getReport('error')); diff --git a/tests/Migration/E2E/Sources/SupabaseTest.php b/tests/Migration/E2E/Sources/SupabaseTest.php index 2ce0397..c41f063 100644 --- a/tests/Migration/E2E/Sources/SupabaseTest.php +++ b/tests/Migration/E2E/Sources/SupabaseTest.php @@ -89,7 +89,8 @@ public function testRunTransfer($state) { $this->transfer->run( $this->source->getSupportedResources(), - function () {} + function () { + } ); $this->assertCount(0, $this->transfer->getReport('error')); diff --git a/tests/Migration/Unit/General/CSVTest.php b/tests/Migration/Unit/General/CSVTest.php index 530a596..e4fd3ec 100644 --- a/tests/Migration/Unit/General/CSVTest.php +++ b/tests/Migration/Unit/General/CSVTest.php @@ -169,7 +169,8 @@ public function testCSVExportWithSpecialCharacters() 'mixed_field' => 'Text with "quotes", commas, and\nnewlines' ]); - $csvDestination->testableImport([$row], function ($resources) {}); + $csvDestination->testableImport([$row], function ($resources) { + }); $csvDestination->shutdown(); $csvFile = $csvDestination->getLocalRoot() . '/test_db_test_table_id.csv'; @@ -215,7 +216,8 @@ public function testCSVExportWithArrays() 'nested' => [['id' => 1], ['id' => 2]] ]); - $csvDestination->testableImport([$row], function ($resources) {}); + $csvDestination->testableImport([$row], function ($resources) { + }); $csvDestination->shutdown(); $csvFile = $csvDestination->getLocalRoot() . '/test_db_test_table_id.csv'; @@ -262,7 +264,8 @@ public function testCSVExportWithNullValues() 'false_bool' => false ]); - $csvDestination->testableImport([$row], function ($resources) {}); + $csvDestination->testableImport([$row], function ($resources) { + }); $csvDestination->shutdown(); $csvFile = $csvDestination->getLocalRoot() . '/test_db_test_table_id.csv'; @@ -309,7 +312,8 @@ public function testCSVExportWithAllowedAttributes() 'secret' => 'should_not_appear' ]); - $csvDestination->testableImport([$row], function ($resources) {}); + $csvDestination->testableImport([$row], function ($resources) { + }); $csvDestination->shutdown(); $csvFile = $csvDestination->getLocalRoot() . '/test_db_test_table_id.csv'; @@ -365,7 +369,8 @@ public function testCSVExportImportCompatibility() $row = new Row('compat_row', $table, $originalData); $row->setPermissions(['read("user:123")']); - $csvDestination->testableImport([$row], function ($resources) {}); + $csvDestination->testableImport([$row], function ($resources) { + }); $csvDestination->shutdown(); // Verify the exported CSV can be parsed by PHP's built-in CSV functions diff --git a/tests/Migration/Unit/General/TransferTest.php b/tests/Migration/Unit/General/TransferTest.php index 9a14439..bf21f84 100644 --- a/tests/Migration/Unit/General/TransferTest.php +++ b/tests/Migration/Unit/General/TransferTest.php @@ -36,7 +36,8 @@ public function testRootResourceId(): void * Make sure we can't create a transfer with multiple root resources when supplying a rootResourceId */ try { - $this->transfer->run([Resource::TYPE_USER, Resource::TYPE_DATABASE], function () {}, 'rootResourceId'); + $this->transfer->run([Resource::TYPE_USER, Resource::TYPE_DATABASE], function () { + }, 'rootResourceId'); $this->fail('Multiple root resources should not be allowed'); } catch (\Exception $e) { $this->assertSame('Resource type must be set when resource ID is set.', $e->getMessage()); @@ -50,7 +51,8 @@ public function testRootResourceId(): void */ $this->transfer->run( [Resource::TYPE_DATABASE], - function () {}, + function () { + }, 'test', Resource::TYPE_DATABASE );