diff --git a/composer.json b/composer.json index 3430b0e..5585f2a 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/composer.lock b/composer.lock index ee17709..17d1422 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "29e79affc489fb76f06516f9821306d2", + "content-hash": "37980b9001fbbd4f213f3102c1332727", "packages": [ { "name": "appwrite/appwrite", @@ -50,16 +50,16 @@ }, { "name": "brick/math", - "version": "0.14.1", + "version": "0.14.8", "source": { "type": "git", "url": "https://github.com/brick/math.git", - "reference": "f05858549e5f9d7bb45875a75583240a38a281d0" + "reference": "63422359a44b7f06cae63c3b429b59e8efcc0629" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brick/math/zipball/f05858549e5f9d7bb45875a75583240a38a281d0", - "reference": "f05858549e5f9d7bb45875a75583240a38a281d0", + "url": "https://api.github.com/repos/brick/math/zipball/63422359a44b7f06cae63c3b429b59e8efcc0629", + "reference": "63422359a44b7f06cae63c3b429b59e8efcc0629", "shasum": "" }, "require": { @@ -98,7 +98,7 @@ ], "support": { "issues": "https://github.com/brick/math/issues", - "source": "https://github.com/brick/math/tree/0.14.1" + "source": "https://github.com/brick/math/tree/0.14.8" }, "funding": [ { @@ -106,7 +106,7 @@ "type": "github" } ], - "time": "2025-11-24T14:40:29+00:00" + "time": "2026-02-10T14:33:43+00:00" }, { "name": "composer/semver", @@ -643,16 +643,16 @@ }, { "name": "open-telemetry/exporter-otlp", - "version": "1.3.4", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/opentelemetry-php/exporter-otlp.git", - "reference": "62e680d587beb42e5247aa6ecd89ad1ca406e8ca" + "reference": "283a0d66522f2adc6d8d7debfd7686be91c282be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opentelemetry-php/exporter-otlp/zipball/62e680d587beb42e5247aa6ecd89ad1ca406e8ca", - "reference": "62e680d587beb42e5247aa6ecd89ad1ca406e8ca", + "url": "https://api.github.com/repos/opentelemetry-php/exporter-otlp/zipball/283a0d66522f2adc6d8d7debfd7686be91c282be", + "reference": "283a0d66522f2adc6d8d7debfd7686be91c282be", "shasum": "" }, "require": { @@ -703,7 +703,7 @@ "issues": "https://github.com/open-telemetry/opentelemetry-php/issues", "source": "https://github.com/open-telemetry/opentelemetry-php" }, - "time": "2026-01-15T09:31:34+00:00" + "time": "2026-02-05T09:44:52+00:00" }, { "name": "open-telemetry/gen-otlp-protobuf", @@ -770,16 +770,16 @@ }, { "name": "open-telemetry/sdk", - "version": "1.12.0", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/opentelemetry-php/sdk.git", - "reference": "7f1bd524465c1ca42755a9ef1143ba09913f5be0" + "reference": "c76f91203bf7ef98ab3f4e0a82ca21699af185e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opentelemetry-php/sdk/zipball/7f1bd524465c1ca42755a9ef1143ba09913f5be0", - "reference": "7f1bd524465c1ca42755a9ef1143ba09913f5be0", + "url": "https://api.github.com/repos/opentelemetry-php/sdk/zipball/c76f91203bf7ef98ab3f4e0a82ca21699af185e1", + "reference": "c76f91203bf7ef98ab3f4e0a82ca21699af185e1", "shasum": "" }, "require": { @@ -863,7 +863,7 @@ "issues": "https://github.com/open-telemetry/opentelemetry-php/issues", "source": "https://github.com/open-telemetry/opentelemetry-php" }, - "time": "2026-01-21T04:14:03+00:00" + "time": "2026-01-28T11:38:11+00:00" }, { "name": "open-telemetry/sem-conv", @@ -2228,16 +2228,16 @@ }, { "name": "utopia-php/database", - "version": "5.0.0", + "version": "5.2.1", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "221794bd7de027f9177cd325209e8162ca2520cb" + "reference": "adfdf201144353a1d2ce14bb197ab746079894e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/221794bd7de027f9177cd325209e8162ca2520cb", - "reference": "221794bd7de027f9177cd325209e8162ca2520cb", + "url": "https://api.github.com/repos/utopia-php/database/zipball/adfdf201144353a1d2ce14bb197ab746079894e0", + "reference": "adfdf201144353a1d2ce14bb197ab746079894e0", "shasum": "" }, "require": { @@ -2245,10 +2245,10 @@ "ext-mongodb": "*", "ext-pdo": "*", "php": ">=8.4", - "utopia-php/cache": "1.0.*", + "utopia-php/cache": "1.*", "utopia-php/framework": "0.33.*", - "utopia-php/mongo": "0.11.*", - "utopia-php/pools": "1.0.*" + "utopia-php/mongo": "1.*", + "utopia-php/pools": "1.*" }, "require-dev": { "fakerphp/faker": "1.23.*", @@ -2280,9 +2280,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/5.0.0" + "source": "https://github.com/utopia-php/database/tree/5.2.1" }, - "time": "2026-01-30T06:17:53+00:00" + "time": "2026-02-16T11:01:13+00:00" }, { "name": "utopia-php/dsn", @@ -2333,27 +2333,30 @@ }, { "name": "utopia-php/framework", - "version": "0.33.11", + "version": "0.33.39", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "354ff0d23bfc6e82bea0fe8e89e115cff1af8466" + "reference": "409a258814d664d3a50fa2f48b6695679334d30b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/354ff0d23bfc6e82bea0fe8e89e115cff1af8466", - "reference": "354ff0d23bfc6e82bea0fe8e89e115cff1af8466", + "url": "https://api.github.com/repos/utopia-php/http/zipball/409a258814d664d3a50fa2f48b6695679334d30b", + "reference": "409a258814d664d3a50fa2f48b6695679334d30b", "shasum": "" }, "require": { - "php": ">=8.0", - "utopia-php/compression": "0.1.*" + "php": ">=8.3", + "utopia-php/compression": "0.1.*", + "utopia-php/telemetry": "0.2.*", + "utopia-php/validators": "0.2.*" }, "require-dev": { - "laravel/pint": "^1.2", - "phpbench/phpbench": "^1.2", - "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.5.25" + "laravel/pint": "1.*", + "phpbench/phpbench": "1.*", + "phpstan/phpstan": "1.*", + "phpunit/phpunit": "9.*", + "swoole/ide-helper": "^6.0" }, "type": "library", "autoload": { @@ -2373,22 +2376,22 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.11" + "source": "https://github.com/utopia-php/http/tree/0.33.39" }, - "time": "2024-11-08T18:47:43+00:00" + "time": "2026-02-11T06:33:42+00:00" }, { "name": "utopia-php/mongo", - "version": "0.11.0", + "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/utopia-php/mongo.git", - "reference": "34bc0cda8ea368cde68702a6fffe2c3ac625398e" + "reference": "45bedf36c2c946ec7a0a3e59b9f12f772de0b01d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/mongo/zipball/34bc0cda8ea368cde68702a6fffe2c3ac625398e", - "reference": "34bc0cda8ea368cde68702a6fffe2c3ac625398e", + "url": "https://api.github.com/repos/utopia-php/mongo/zipball/45bedf36c2c946ec7a0a3e59b9f12f772de0b01d", + "reference": "45bedf36c2c946ec7a0a3e59b9f12f772de0b01d", "shasum": "" }, "require": { @@ -2434,9 +2437,9 @@ ], "support": { "issues": "https://github.com/utopia-php/mongo/issues", - "source": "https://github.com/utopia-php/mongo/tree/0.11.0" + "source": "https://github.com/utopia-php/mongo/tree/1.0.0" }, - "time": "2025-10-20T11:11:23+00:00" + "time": "2026-02-12T05:54:06+00:00" }, { "name": "utopia-php/pools", @@ -2493,32 +2496,27 @@ }, { "name": "utopia-php/storage", - "version": "0.18.22", + "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/utopia-php/storage.git", - "reference": "c46bd78c1f52281df89f8921159782b20260ce31" + "reference": "f672e8865938e5d1d6dc3bd149ceba4e5582199e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/storage/zipball/c46bd78c1f52281df89f8921159782b20260ce31", - "reference": "c46bd78c1f52281df89f8921159782b20260ce31", + "url": "https://api.github.com/repos/utopia-php/storage/zipball/f672e8865938e5d1d6dc3bd149ceba4e5582199e", + "reference": "f672e8865938e5d1d6dc3bd149ceba4e5582199e", "shasum": "" }, "require": { - "ext-brotli": "*", "ext-curl": "*", "ext-fileinfo": "*", - "ext-lz4": "*", "ext-simplexml": "*", - "ext-snappy": "*", - "ext-xz": "*", "ext-zlib": "*", - "ext-zstd": "*", "php": ">=8.1", "utopia-php/system": "0.*.*", "utopia-php/telemetry": "0.2.*", - "utopia-php/validators": "0.1.*" + "utopia-php/validators": "0.2.*" }, "require-dev": { "laravel/pint": "1.2.*", @@ -2545,9 +2543,9 @@ ], "support": { "issues": "https://github.com/utopia-php/storage/issues", - "source": "https://github.com/utopia-php/storage/tree/0.18.22" + "source": "https://github.com/utopia-php/storage/tree/1.0.0" }, - "time": "2026-01-15T01:36:39+00:00" + "time": "2026-02-17T04:37:10+00:00" }, { "name": "utopia-php/system", @@ -2662,16 +2660,16 @@ }, { "name": "utopia-php/validators", - "version": "0.1.0", + "version": "0.2.0", "source": { "type": "git", "url": "https://github.com/utopia-php/validators.git", - "reference": "5c57d5b6cf964f8981807c1d3ea8df620c869080" + "reference": "30b6030a5b100fc1dff34506e5053759594b2a20" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/validators/zipball/5c57d5b6cf964f8981807c1d3ea8df620c869080", - "reference": "5c57d5b6cf964f8981807c1d3ea8df620c869080", + "url": "https://api.github.com/repos/utopia-php/validators/zipball/30b6030a5b100fc1dff34506e5053759594b2a20", + "reference": "30b6030a5b100fc1dff34506e5053759594b2a20", "shasum": "" }, "require": { @@ -2679,7 +2677,7 @@ }, "require-dev": { "laravel/pint": "1.*", - "phpstan/phpstan": "1.*", + "phpstan/phpstan": "2.*", "phpunit/phpunit": "11.*" }, "type": "library", @@ -2701,9 +2699,9 @@ ], "support": { "issues": "https://github.com/utopia-php/validators/issues", - "source": "https://github.com/utopia-php/validators/tree/0.1.0" + "source": "https://github.com/utopia-php/validators/tree/0.2.0" }, - "time": "2025-11-18T11:05:46+00:00" + "time": "2026-01-13T09:16:51+00:00" } ], "packages-dev": [ @@ -2771,16 +2769,16 @@ }, { "name": "laravel/pint", - "version": "v1.27.0", + "version": "v1.27.1", "source": { "type": "git", "url": "https://github.com/laravel/pint.git", - "reference": "c67b4195b75491e4dfc6b00b1c78b68d86f54c90" + "reference": "54cca2de13790570c7b6f0f94f37896bee4abcb5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/c67b4195b75491e4dfc6b00b1c78b68d86f54c90", - "reference": "c67b4195b75491e4dfc6b00b1c78b68d86f54c90", + "url": "https://api.github.com/repos/laravel/pint/zipball/54cca2de13790570c7b6f0f94f37896bee4abcb5", + "reference": "54cca2de13790570c7b6f0f94f37896bee4abcb5", "shasum": "" }, "require": { @@ -2791,13 +2789,13 @@ "php": "^8.2.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.92.4", - "illuminate/view": "^12.44.0", - "larastan/larastan": "^3.8.1", - "laravel-zero/framework": "^12.0.4", + "friendsofphp/php-cs-fixer": "^3.93.1", + "illuminate/view": "^12.51.0", + "larastan/larastan": "^3.9.2", + "laravel-zero/framework": "^12.0.5", "mockery/mockery": "^1.6.12", "nunomaduro/termwind": "^2.3.3", - "pestphp/pest": "^3.8.4" + "pestphp/pest": "^3.8.5" }, "bin": [ "builds/pint" @@ -2834,7 +2832,7 @@ "issues": "https://github.com/laravel/pint/issues", "source": "https://github.com/laravel/pint" }, - "time": "2026-01-05T16:49:17+00:00" + "time": "2026-02-10T20:00:20+00:00" }, { "name": "myclabs/deep-copy", @@ -3292,28 +3290,28 @@ }, { "name": "phpunit/php-file-iterator", - "version": "5.1.0", + "version": "5.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6" + "reference": "2f3a64888c814fc235386b7387dd5b5ed92ad903" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/118cfaaa8bc5aef3287bf315b6060b1174754af6", - "reference": "118cfaaa8bc5aef3287bf315b6060b1174754af6", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/2f3a64888c814fc235386b7387dd5b5ed92ad903", + "reference": "2f3a64888c814fc235386b7387dd5b5ed92ad903", "shasum": "" }, "require": { "php": ">=8.2" }, "require-dev": { - "phpunit/phpunit": "^11.0" + "phpunit/phpunit": "^11.3" }, "type": "library", "extra": { "branch-alias": { - "dev-main": "5.0-dev" + "dev-main": "5.1-dev" } }, "autoload": { @@ -3341,15 +3339,27 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.1.0" + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/5.1.1" }, "funding": [ { "url": "https://github.com/sebastianbergmann", "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/php-file-iterator", + "type": "tidelift" } ], - "time": "2024-08-27T05:02:59+00:00" + "time": "2026-02-02T13:52:54+00:00" }, { "name": "phpunit/php-invoker", @@ -3537,16 +3547,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.5.50", + "version": "11.5.53", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "fdfc727f0fcacfeb8fcb30c7e5da173125b58be3" + "reference": "a997a653a82845f1240d73ee73a8a4e97e4b0607" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fdfc727f0fcacfeb8fcb30c7e5da173125b58be3", - "reference": "fdfc727f0fcacfeb8fcb30c7e5da173125b58be3", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a997a653a82845f1240d73ee73a8a4e97e4b0607", + "reference": "a997a653a82845f1240d73ee73a8a4e97e4b0607", "shasum": "" }, "require": { @@ -3561,7 +3571,7 @@ "phar-io/version": "^3.2.1", "php": ">=8.2", "phpunit/php-code-coverage": "^11.0.12", - "phpunit/php-file-iterator": "^5.1.0", + "phpunit/php-file-iterator": "^5.1.1", "phpunit/php-invoker": "^5.0.1", "phpunit/php-text-template": "^4.0.1", "phpunit/php-timer": "^7.0.1", @@ -3573,6 +3583,7 @@ "sebastian/exporter": "^6.3.2", "sebastian/global-state": "^7.0.2", "sebastian/object-enumerator": "^6.0.1", + "sebastian/recursion-context": "^6.0.3", "sebastian/type": "^5.1.3", "sebastian/version": "^5.0.2", "staabm/side-effects-detector": "^1.0.5" @@ -3618,7 +3629,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.50" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.53" }, "funding": [ { @@ -3642,7 +3653,7 @@ "type": "tidelift" } ], - "time": "2026-01-27T05:59:18+00:00" + "time": "2026-02-10T12:28:25+00:00" }, { "name": "sebastian/cli-parser", @@ -4986,7 +4997,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index d04cb8e..1d7522c 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -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( diff --git a/src/Migration/Resources/Database/Attribute/Decimal.php b/src/Migration/Resources/Database/Attribute/Decimal.php deleted file mode 100644 index acbcad4..0000000 --- a/src/Migration/Resources/Database/Attribute/Decimal.php +++ /dev/null @@ -1,105 +0,0 @@ - $min, - 'max' => $max, - ], - createdAt: $createdAt, - updatedAt: $updatedAt - ); - } - - /** - * @param array{ - * key: string, - * collection?: array{ - * database: array{ - * id: string, - * name: string, - * }, - * name: string, - * id: string, - * documentSecurity: bool, - * permissions: ?array - * }, - * table?: array{ - * database: array{ - * id: string, - * name: string, - * }, - * name: string, - * id: string, - * rowSecurity: bool, - * permissions: ?array - * }, - * required: bool, - * array: bool, - * default: ?float, - * formatOptions: array{ - * min: ?float, - * max: ?float - * }, - * createdAt: string, - * updatedAt: string, - * } $array - * @return self - */ - public static function fromArray(array $array): self - { - return new self( - $array['key'], - Collection::fromArray($array['table'] ?? $array['collection']), - required: $array['required'], - default: $array['default'], - array: $array['array'], - min: $array['formatOptions']['min'], - max: $array['formatOptions']['max'], - createdAt: $array['createdAt'] ?? '', - updatedAt: $array['updatedAt'] ?? '', - ); - } - - public function getType(): string - { - return Attribute::TYPE_FLOAT; - } - - public function getMin(): ?float - { - return (float)$this->formatOptions['min']; - } - - public function getMax(): ?float - { - return (float)$this->formatOptions['max']; - } -} diff --git a/src/Migration/Resources/Database/Attribute/Email.php b/src/Migration/Resources/Database/Attribute/Email.php deleted file mode 100644 index 2c460f3..0000000 --- a/src/Migration/Resources/Database/Attribute/Email.php +++ /dev/null @@ -1,37 +0,0 @@ - 2147483647 ? 8 : 4; - - parent::__construct( - $key, - $collection, - size: $size, - required: $required, - default: $default, - array: $array, - signed: $signed, - formatOptions: [ - 'min' => $min, - 'max' => $max, - ], - createdAt: $createdAt, - updatedAt: $updatedAt - ); - } - - /** - * @param array{ - * key: string, - * collection?: array{ - * database: array{ - * id: string, - * name: string, - * }, - * name: string, - * id: string, - * documentSecurity: bool, - * permissions: ?array - * }, - * table?: array{ - * database: array{ - * id: string, - * name: string, - * }, - * name: string, - * id: string, - * rowSecurity: bool, - * permissions: ?array - * }, - * required: bool, - * array: bool, - * default: ?int, - * formatOptions: array{ - * min: ?int, - * max: ?int - * }, - * createdAt: string, - * updatedAt: string, - * signed?: bool - * } $array - * @return self - */ - public static function fromArray(array $array): self - { - return new self( - $array['key'], - Collection::fromArray($array['table'] ?? $array['collection']), - required: $array['required'], - default: $array['default'], - array: $array['array'], - min: $array['formatOptions']['min'] ?? null, - max: $array['formatOptions']['max'] ?? null, - createdAt: $array['createdAt'] ?? '', - updatedAt: $array['updatedAt'] ?? '', - signed: $array['signed'] ?? true - ); - } - - public function getType(): string - { - return Attribute::TYPE_INTEGER; - } - - public function getMin(): ?int - { - return (int)$this->formatOptions['min']; - } - - public function getMax(): ?int - { - return (int)$this->formatOptions['max']; - } -} diff --git a/src/Migration/Resources/Database/Attribute/Line.php b/src/Migration/Resources/Database/Attribute/Line.php deleted file mode 100644 index dfa360a..0000000 --- a/src/Migration/Resources/Database/Attribute/Line.php +++ /dev/null @@ -1,74 +0,0 @@ - - * }, - * table?: array{ - * database: array{ - * id: string, - * name: string, - * }, - * name: string, - * id: string, - * rowSecurity: bool, - * permissions: ?array - * }, - * required: bool, - * default: ?array, - * createdAt: string, - * updatedAt: string, - * } $array - * @return self - */ - public static function fromArray(array $array): self - { - return new self( - $array['key'], - Collection::fromArray($array['table'] ?? $array['collection']), - required: $array['required'], - default: $array['default'], - createdAt: $array['createdAt'] ?? '', - updatedAt: $array['updatedAt'] ?? '', - ); - } - - public function getType(): string - { - return Attribute::TYPE_LINE; - } -} diff --git a/src/Migration/Resources/Database/Attribute/ObjectType.php b/src/Migration/Resources/Database/Attribute/ObjectType.php deleted file mode 100644 index e3ef99d..0000000 --- a/src/Migration/Resources/Database/Attribute/ObjectType.php +++ /dev/null @@ -1,74 +0,0 @@ - - * }, - * table?: array{ - * database: array{ - * id: string, - * name: string, - * }, - * name: string, - * id: string, - * rowSecurity: bool, - * permissions: ?array - * }, - * required: bool, - * default: ?array, - * createdAt: string, - * updatedAt: string, - * } $array - * @return self - */ - public static function fromArray(array $array): self - { - return new self( - $array['key'], - Collection::fromArray($array['table'] ?? $array['collection']), - required: $array['required'], - default: $array['default'], - createdAt: $array['createdAt'] ?? '', - updatedAt: $array['updatedAt'] ?? '', - ); - } - - public function getType(): string - { - return Attribute::TYPE_OBJECT; - } -} diff --git a/src/Migration/Resources/Database/Attribute/Point.php b/src/Migration/Resources/Database/Attribute/Point.php deleted file mode 100644 index a82d7d3..0000000 --- a/src/Migration/Resources/Database/Attribute/Point.php +++ /dev/null @@ -1,74 +0,0 @@ - - * }, - * table?: array{ - * database: array{ - * id: string, - * name: string, - * }, - * name: string, - * id: string, - * rowSecurity: bool, - * permissions: ?array - * }, - * required: bool, - * default: ?array, - * createdAt: string, - * updatedAt: string, - * } $array - * @return self - */ - public static function fromArray(array $array): self - { - return new self( - $array['key'], - Collection::fromArray($array['table'] ?? $array['collection']), - required: $array['required'], - default: $array['default'], - createdAt: $array['createdAt'] ?? '', - updatedAt: $array['updatedAt'] ?? '', - ); - } - - public function getType(): string - { - return Attribute::TYPE_POINT; - } -} diff --git a/src/Migration/Resources/Database/Attribute/Polygon.php b/src/Migration/Resources/Database/Attribute/Polygon.php deleted file mode 100644 index 173eec6..0000000 --- a/src/Migration/Resources/Database/Attribute/Polygon.php +++ /dev/null @@ -1,74 +0,0 @@ - - * }, - * table?: array{ - * database: array{ - * id: string, - * name: string, - * }, - * name: string, - * id: string, - * rowSecurity: bool, - * permissions: ?array - * }, - * required: bool, - * default: ?array, - * createdAt: string, - * updatedAt: string, - * } $array - * @return self - */ - public static function fromArray(array $array): self - { - return new self( - $array['key'], - Collection::fromArray($array['table'] ?? $array['collection']), - required: $array['required'], - default: $array['default'] ?? null, - createdAt: $array['createdAt'] ?? '', - updatedAt: $array['updatedAt'] ?? '', - ); - } - - public function getType(): string - { - return Attribute::TYPE_POLYGON; - } -} diff --git a/src/Migration/Resources/Database/Attribute/Relationship.php b/src/Migration/Resources/Database/Attribute/Relationship.php deleted file mode 100644 index aa252ab..0000000 --- a/src/Migration/Resources/Database/Attribute/Relationship.php +++ /dev/null @@ -1,125 +0,0 @@ - $relatedTable, - 'relationType' => $relationType, - 'twoWay' => $twoWay, - 'twoWayKey' => $twoWayKey, - 'onDelete' => $onDelete, - 'side' => $side, - ], - createdAt: $createdAt, - updatedAt: $updatedAt - ); - } - - /** - * @param array{ - * key: string, - * collection?: array{ - * database: array{ - * id: string, - * name: string, - * }, - * name: string, - * id: string, - * documentSecurity: bool, - * permissions: ?array - * }, - * table?: array{ - * database: array{ - * id: string, - * name: string, - * }, - * name: string, - * id: string, - * rowSecurity: bool, - * permissions: ?array - * }, - * options: array{ - * relatedCollection: string, - * relationType: string, - * twoWay: bool, - * twoWayKey: ?string, - * onDelete: string, - * side: string, - * }, - * createdAt: string, - * updatedAt: string, - * } $array - * @return self - */ - public static function fromArray(array $array): self - { - return new self( - $array['key'], - Collection::fromArray($array['table'] ?? $array['collection']), - relatedTable: $array['options']['relatedTable'] ?? $array['options']['relatedCollection'], - relationType: $array['options']['relationType'], - twoWay: $array['options']['twoWay'], - twoWayKey: $array['options']['twoWayKey'], - onDelete: $array['options']['onDelete'], - side: $array['options']['side'], - createdAt: $array['createdAt'] ?? '', - updatedAt: $array['updatedAt'] ?? '', - ); - } - - public function getType(): string - { - return Attribute::TYPE_RELATIONSHIP; - } - - public function getRelatedTable(): string - { - return $this->options['relatedTable'] ?? $this->options['relatedCollection']; - } - - public function getRelationType(): string - { - return $this->options['relationType']; - } - - public function getTwoWay(): bool - { - return $this->options['twoWay']; - } - - public function getTwoWayKey(): ?string - { - return $this->options['twoWayKey']; - } - - public function getOnDelete(): string - { - return $this->options['onDelete']; - } - - public function getSide(): string - { - return $this->options['side']; - } -} diff --git a/src/Migration/Resources/Database/Attribute/URL.php b/src/Migration/Resources/Database/Attribute/URL.php deleted file mode 100644 index 2e83a0f..0000000 --- a/src/Migration/Resources/Database/Attribute/URL.php +++ /dev/null @@ -1,37 +0,0 @@ - - * }, - * table?: array{ - * database: array{ - * id: string, - * name: string, - * }, - * name: string, - * id: string, - * rowSecurity: bool, - * permissions: ?array - * }, - * size: int, - * required: bool, - * default: ?array, - * createdAt: string, - * updatedAt: string, - * } $array - * @return self - */ - public static function fromArray(array $array): self - { - return new self( - $array['key'], - Collection::fromArray($array['table'] ?? $array['collection']), - required: $array['required'], - size:$array['size'], - default: $array['default'], - createdAt: $array['createdAt'] ?? '', - updatedAt: $array['updatedAt'] ?? '', - ); - } - - public function getType(): string - { - return Attribute::TYPE_VECTOR; - } -} diff --git a/src/Migration/Resources/Database/Column.php b/src/Migration/Resources/Database/Column.php index e80d172..ed13c95 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'; @@ -155,4 +160,16 @@ public function &getOptions(): array { return $this->options; } + + /** + * Convert this Column resource to an Attribute resource. + * This provides a deterministic way to derive attributes from columns, + * eliminating the need to maintain duplicate per-type Attribute implementations. + * + * @return Attribute + */ + public function getAttribute(): Attribute + { + return GenericAttribute::fromColumn($this); + } } diff --git a/src/Migration/Resources/Database/Attribute/Text.php b/src/Migration/Resources/Database/Columns/LongText.php similarity index 83% rename from src/Migration/Resources/Database/Attribute/Text.php rename to src/Migration/Resources/Database/Columns/LongText.php index a0c60ec..7f6230c 100644 --- a/src/Migration/Resources/Database/Attribute/Text.php +++ b/src/Migration/Resources/Database/Columns/LongText.php @@ -1,27 +1,27 @@ $elements - */ public function __construct( string $key, - Collection $collection, - array $elements, + Table $table, bool $required = false, ?string $default = null, bool $array = false, - int $size = 256, + int $size = 16777215, + string $format = '', string $createdAt = '', string $updatedAt = '' ) { parent::__construct( $key, - $collection, + $table, size: $size, required: $required, default: $default, array: $array, - format: 'enum', - formatOptions: [ - 'elements' => $elements, - ], + format: $format, createdAt: $createdAt, updatedAt: $updatedAt ); @@ -60,13 +55,11 @@ public function __construct( * rowSecurity: bool, * permissions: ?array * }, - * size: int, * required: bool, * default: ?string, * array: bool, - * formatOptions: array{ - * elements: array - * }, + * size: int, + * format: string, * createdAt: string, * updatedAt: string, * } $array @@ -76,12 +69,12 @@ public static function fromArray(array $array): self { return new self( $array['key'], - Collection::fromArray($array['table'] ?? $array['collection']), - elements: $array['formatOptions']['elements'], + Table::fromArray($array['table'] ?? $array['collection']), required: $array['required'], - default: $array['default'], + default: $array['default'] ?? null, array: $array['array'], size: $array['size'], + format: $array['format'], createdAt: $array['createdAt'] ?? '', updatedAt: $array['updatedAt'] ?? '', ); @@ -89,14 +82,16 @@ public static function fromArray(array $array): self public function getType(): string { - return Attribute::TYPE_ENUM; + return Column::TYPE_MEDIUMTEXT; } - /** - * @return array - */ - public function getElements(): array + public function getSize(): int + { + return $this->size; + } + + public function getFormat(): string { - return (array)$this->formatOptions['elements']; + return $this->format; } } diff --git a/src/Migration/Resources/Database/Attribute/Boolean.php b/src/Migration/Resources/Database/Columns/RegularText.php similarity index 58% rename from src/Migration/Resources/Database/Attribute/Boolean.php rename to src/Migration/Resources/Database/Columns/RegularText.php index 6bbe4b1..9ae55b1 100644 --- a/src/Migration/Resources/Database/Attribute/Boolean.php +++ b/src/Migration/Resources/Database/Columns/RegularText.php @@ -1,27 +1,32 @@ * }, * required: bool, + * default: ?string, * array: bool, - * default: ?bool, + * size: int, + * format: string, * createdAt: string, * updatedAt: string, * } $array @@ -62,10 +69,12 @@ public static function fromArray(array $array): self { return new self( $array['key'], - Collection::fromArray($array['table'] ?? $array['collection']), + Table::fromArray($array['table'] ?? $array['collection']), required: $array['required'], - default: $array['default'], + default: $array['default'] ?? null, array: $array['array'], + size: $array['size'], + format: $array['format'], createdAt: $array['createdAt'] ?? '', updatedAt: $array['updatedAt'] ?? '', ); @@ -73,6 +82,16 @@ public static function fromArray(array $array): self public function getType(): string { - return Attribute::TYPE_BOOLEAN; + 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/Attribute/DateTime.php b/src/Migration/Resources/Database/Columns/Varchar.php similarity index 67% rename from src/Migration/Resources/Database/Attribute/DateTime.php rename to src/Migration/Resources/Database/Columns/Varchar.php index f81a375..9df3a4b 100644 --- a/src/Migration/Resources/Database/Attribute/DateTime.php +++ b/src/Migration/Resources/Database/Columns/Varchar.php @@ -1,38 +1,37 @@ * }, * required: bool, - * array: bool, * default: ?string, + * array: bool, + * size: int, + * format: string, * createdAt: string, * updatedAt: string, * } $array @@ -68,12 +69,29 @@ public static function fromArray(array $array): self { return new self( $array['key'], - Collection::fromArray($array['table'] ?? $array['collection']), + Table::fromArray($array['table'] ?? $array['collection']), required: $array['required'], - default: $array['default'], + 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/Resources/Database/GenericAttribute.php b/src/Migration/Resources/Database/GenericAttribute.php new file mode 100644 index 0000000..e959739 --- /dev/null +++ b/src/Migration/Resources/Database/GenericAttribute.php @@ -0,0 +1,98 @@ + $formatOptions + * @param array $filters + * @param array $options + * @param string $createdAt + * @param string $updatedAt + */ + public function __construct( + string $key, + Table $table, + protected readonly string $fieldType, + int $size = 0, + bool $required = false, + mixed $default = null, + bool $array = false, + bool $signed = false, + string $format = '', + array $formatOptions = [], + array $filters = [], + array $options = [], + string $createdAt = '', + string $updatedAt = '', + ) { + parent::__construct( + $key, + $table, + $size, + $required, + $default, + $array, + $signed, + $format, + $formatOptions, + $filters, + $options, + $createdAt, + $updatedAt + ); + } + + /** + * Convert a Column resource to an Attribute resource. + * This provides a deterministic way to derive attributes from columns. + * + * @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() + ); + } + + /** + * Returns the field type (e.g., 'string', 'integer', 'email'). + * This is stored separately from the resource name (which is 'attribute'). + * + * @return string + */ + public function getType(): string + { + return $this->fieldType; + } +} diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index 321cd85..99bea83 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -21,21 +21,6 @@ use Utopia\Migration\Resources\Auth\Team; use Utopia\Migration\Resources\Auth\User; use Utopia\Migration\Resources\Database\Attribute; -use Utopia\Migration\Resources\Database\Attribute\Boolean as AttributeBoolean; -use Utopia\Migration\Resources\Database\Attribute\DateTime as AttributeDateTime; -use Utopia\Migration\Resources\Database\Attribute\Decimal as AttributeDecimal; -use Utopia\Migration\Resources\Database\Attribute\Email as AttributeEmail; -use Utopia\Migration\Resources\Database\Attribute\Enum as AttributeEnum; -use Utopia\Migration\Resources\Database\Attribute\Integer as AttributeInteger; -use Utopia\Migration\Resources\Database\Attribute\IP as AttributeIP; -use Utopia\Migration\Resources\Database\Attribute\Line as AttributeLine; -use Utopia\Migration\Resources\Database\Attribute\ObjectType as AttributeObjectType; -use Utopia\Migration\Resources\Database\Attribute\Point as AttributePoint; -use Utopia\Migration\Resources\Database\Attribute\Polygon as AttributePolygon; -use Utopia\Migration\Resources\Database\Attribute\Relationship as AttributeRelationship; -use Utopia\Migration\Resources\Database\Attribute\Text as AttributeText; -use Utopia\Migration\Resources\Database\Attribute\URL as AttributeURL; -use Utopia\Migration\Resources\Database\Attribute\Vector as AttributeVector; use Utopia\Migration\Resources\Database\Collection; use Utopia\Migration\Resources\Database\Column; use Utopia\Migration\Resources\Database\Columns\Boolean; @@ -46,12 +31,16 @@ 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\ObjectType; 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\Columns\Vector; use Utopia\Migration\Resources\Database\Database; use Utopia\Migration\Resources\Database\Document; @@ -972,7 +961,7 @@ private function exportFields(string $entityType, int $batchSize): void /** @var Table $table */ $col = match($table->getDatabase()->getType()) { - Resource::TYPE_DATABASE_VECTORDB => self::getAttribute($table, $column), + Resource::TYPE_DATABASE_VECTORDB => self::getColumn($table, $column)->getAttribute(), default => self::getColumn($table, $column), }; @@ -2077,173 +2066,70 @@ public static function getColumn(Table $table, mixed $column): Column updatedAt: $column['$updatedAt'] ?? '', ), - default => throw new \InvalidArgumentException("Unsupported column type: {$column['type']}"), - }; - - } - - public static function getAttribute(Collection $collection, mixed $attribute): Attribute - { - return match ($attribute['type']) { - Attribute::TYPE_STRING => match ($attribute['format'] ?? '') { - Attribute::TYPE_EMAIL => new AttributeEmail( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - array: $attribute['array'], - size: $attribute['size'] ?? 254, - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', - ), - Attribute::TYPE_ENUM => new AttributeEnum( - $attribute['key'], - $collection, - elements: $attribute['elements'], - required: $attribute['required'], - default: $attribute['default'], - array: $attribute['array'], - size: $attribute['size'] ?? UtopiaDatabase::LENGTH_KEY, - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', - ), - Attribute::TYPE_URL => new AttributeURL( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - array: $attribute['array'], - size: $attribute['size'] ?? 2000, - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', - ), - Attribute::TYPE_IP => new AttributeIP( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - array: $attribute['array'], - size: $attribute['size'] ?? 39, - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', - ), - default => new AttributeText( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - array: $attribute['array'], - size: $attribute['size'] ?? 0, - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', - ), - }, - - Attribute::TYPE_BOOLEAN => new AttributeBoolean( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - array: $attribute['array'], - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', - ), - - Attribute::TYPE_INTEGER => new AttributeInteger( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - array: $attribute['array'], - min: $attribute['min'] ?? null, - max: $attribute['max'] ?? null, - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', - ), - - Attribute::TYPE_FLOAT => new AttributeDecimal( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - array: $attribute['array'], - min: $attribute['min'] ?? null, - max: $attribute['max'] ?? null, - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', - ), - - Attribute::TYPE_RELATIONSHIP => new AttributeRelationship( - $attribute['key'], - $collection, - relatedTable: $attribute['relatedTable'] ?? $attribute['relatedCollection'], - relationType: $attribute['relationType'], - twoWay: $attribute['twoWay'], - twoWayKey: $attribute['twoWayKey'], - onDelete: $attribute['onDelete'], - side: $attribute['side'], - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', + Column::TYPE_VARCHAR => new Varchar( + $column['key'], + $table, + required: $column['required'], + default: $column['default'], + array: $column['array'], + size: $column['size'] ?? 255, + createdAt: $column['$createdAt'] ?? '', + updatedAt: $column['$updatedAt'] ?? '', ), - Attribute::TYPE_DATETIME => new AttributeDateTime( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - array: $attribute['array'], - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', + Column::TYPE_TEXT => new RegularText( + $column['key'], + $table, + required: $column['required'], + default: $column['default'], + array: $column['array'], + size: $column['size'] ?? 65535, + createdAt: $column['$createdAt'] ?? '', + updatedAt: $column['$updatedAt'] ?? '', ), - Attribute::TYPE_POINT => new AttributePoint( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', + Column::TYPE_MEDIUMTEXT => new MediumText( + $column['key'], + $table, + required: $column['required'], + default: $column['default'], + array: $column['array'], + size: $column['size'] ?? 16777215, + createdAt: $column['$createdAt'] ?? '', + updatedAt: $column['$updatedAt'] ?? '', ), - Attribute::TYPE_LINE => new AttributeLine( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', + Column::TYPE_LONGTEXT => new LongText( + $column['key'], + $table, + required: $column['required'], + default: $column['default'], + array: $column['array'], + size: $column['size'] ?? 2147483647, + createdAt: $column['$createdAt'] ?? '', + updatedAt: $column['$updatedAt'] ?? '', ), - Attribute::TYPE_POLYGON => new AttributePolygon( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', - ), - Attribute::TYPE_OBJECT => new AttributeObjectType( - $attribute['key'], - $collection, - required: $attribute['required'], - default: $attribute['default'], - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', - ), + default => throw new \InvalidArgumentException("Unsupported column type: {$column['type']}"), + }; - Attribute::TYPE_VECTOR => new AttributeVector( - $attribute['key'], - $collection, - size: $attribute['size'], - required: $attribute['required'], - default: $attribute['default'], - createdAt: $attribute['$createdAt'] ?? '', - updatedAt: $attribute['$updatedAt'] ?? '', - ), + } - default => throw new \InvalidArgumentException("Unsupported attribute type: {$attribute['type']}"), - }; + /** + * Convert a raw attribute array to an Attribute resource. + * This is now a thin wrapper that uses getColumn() and then converts to Attribute. + * Since Collection extends Table, we can pass it directly to getColumn(). + * + * @param Collection $collection + * @param mixed $attribute + * @return Attribute + */ + public static function getAttribute(Collection $collection, mixed $attribute): Attribute + { + // Use getColumn() to create the Column resource, then convert to Attribute + // This eliminates duplication - all type-specific logic is in getColumn() + return self::getColumn($collection, $attribute)->getAttribute(); } /** 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 );