From fcca1577420bb03f2efa765788fb4daef7deb2b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 1 Jul 2026 16:02:09 +0200 Subject: [PATCH 1/7] Fix detection at scale --- composer.lock | 12 ++++++------ .../Platform/Modules/Functions/Workers/Builds.php | 10 +++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/composer.lock b/composer.lock index f719710677..3f34311413 100644 --- a/composer.lock +++ b/composer.lock @@ -3736,16 +3736,16 @@ }, { "name": "utopia-php/detector", - "version": "0.2.4", + "version": "0.2.6", "source": { "type": "git", "url": "https://github.com/utopia-php/detector.git", - "reference": "a564381108518ce6d18b6ab441f1448bd8355afd" + "reference": "2b2744be7ea028307dc9352eeec109cd1f9ab2d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/detector/zipball/a564381108518ce6d18b6ab441f1448bd8355afd", - "reference": "a564381108518ce6d18b6ab441f1448bd8355afd", + "url": "https://api.github.com/repos/utopia-php/detector/zipball/2b2744be7ea028307dc9352eeec109cd1f9ab2d3", + "reference": "2b2744be7ea028307dc9352eeec109cd1f9ab2d3", "shasum": "" }, "require": { @@ -3775,9 +3775,9 @@ ], "support": { "issues": "https://github.com/utopia-php/detector/issues", - "source": "https://github.com/utopia-php/detector/tree/0.2.4" + "source": "https://github.com/utopia-php/detector/tree/0.2.6" }, - "time": "2026-02-17T11:26:34+00:00" + "time": "2026-07-01T14:00:11+00:00" }, { "name": "utopia-php/di", diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index feba4797ab..210e63ff21 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -729,7 +729,7 @@ class Builds extends Action } else { $outputDirectory = $deployment->getAttribute('buildOutput') ?? $resource->getAttribute('outputDirectory'); if ($resource->getCollection() === 'sites') { - $command = $this->prepareSiteBuildCommand($command, $outputDirectory ?? ''); + $command = $this->prepareSiteBuildCommand($command, $outputDirectory ?? '', $resource->getAttribute('framework', '')); } $command = 'tar -zxf /tmp/code.tar.gz -C /mnt/code && helpers/build.sh ' . \trim(\escapeshellarg($command)); @@ -1379,7 +1379,7 @@ class Builds extends Action return \substr(\hash('sha256', \json_encode($hashContext, JSON_THROW_ON_ERROR)), 0, 48); } - protected function prepareSiteBuildCommand(string $command, string $outputDirectory): string + protected function prepareSiteBuildCommand(string $command, string $outputDirectory, string $framework): string { $listFilesCommand = 'echo "{APPWRITE_DETECTION_SEPARATOR_START}" && cd /usr/local/build'; @@ -1387,7 +1387,11 @@ class Builds extends Action $listFilesCommand .= ' && cd ' . \escapeshellarg($outputDirectory); } - $listFilesCommand .= ' && find . -name \'node_modules\' -prune -o -type f -print && echo "{APPWRITE_DETECTION_SEPARATOR_END}"'; + foreach (SSR::FRAMEWORK_FILES[$framework] ?? [] as $file) { + $listFilesCommand .= ' && ( [ -e ' . \escapeshellarg($file) . ' ] && echo ' . \escapeshellarg($file) . ' || true )'; + } + + $listFilesCommand .= ' && echo "{APPWRITE_DETECTION_SEPARATOR_END}"'; if (empty($command)) { return $listFilesCommand; From 32edfd521c20c86312ae95fa4b50a39a8cfc0e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 1 Jul 2026 16:02:16 +0200 Subject: [PATCH 2/7] Fix start command starting in wrong folder --- app/controllers/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 1a7cfa70ae..61a07a6106 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -554,7 +554,7 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S } if (!empty($deployment->getAttribute('startCommand', ''))) { - $startCommand = 'cd /usr/local/server/src/function/ && ' . str_replace(['"', '`', '$'], ['\\"', '\\`', '\\$'], $deployment->getAttribute('startCommand', '')); + $startCommand = \str_replace(['"', '`', '$'], ['\\"', '\\`', '\\$'], $deployment->getAttribute('startCommand', '')); } $runtimeEntrypoint = match ($version) { From 0622d7f5b7580f967651b0f02cb408d144762251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 1 Jul 2026 16:05:11 +0200 Subject: [PATCH 3/7] Revert wrong change --- app/controllers/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 61a07a6106..1a7cfa70ae 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -554,7 +554,7 @@ function router(Http $utopia, Database $dbForPlatform, callable $getProjectDB, S } if (!empty($deployment->getAttribute('startCommand', ''))) { - $startCommand = \str_replace(['"', '`', '$'], ['\\"', '\\`', '\\$'], $deployment->getAttribute('startCommand', '')); + $startCommand = 'cd /usr/local/server/src/function/ && ' . str_replace(['"', '`', '$'], ['\\"', '\\`', '\\$'], $deployment->getAttribute('startCommand', '')); } $runtimeEntrypoint = match ($version) { From c4d5ce154c9b919f68f8c52e652e37e773eb640f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 7 Jul 2026 12:37:17 +0200 Subject: [PATCH 4/7] Update unit tests --- tests/unit/Functions/BuildsTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/Functions/BuildsTest.php b/tests/unit/Functions/BuildsTest.php index 36515d2f5b..ff64b80c15 100644 --- a/tests/unit/Functions/BuildsTest.php +++ b/tests/unit/Functions/BuildsTest.php @@ -45,20 +45,20 @@ final class BuildsTest extends TestCase public function testSiteBuildCommandAppendsDetectionFileListing(): void { - $command = $this->callBuilds('prepareSiteBuildCommand', 'npm run build', './dist folder'); + $command = $this->callBuilds('prepareSiteBuildCommand', 'npm run build', './dist folder', 'astro'); $this->assertStringStartsWith('npm run build && echo "{APPWRITE_DETECTION_SEPARATOR_START}"', $command); $this->assertStringContainsString('cd /usr/local/build && cd \'./dist folder\'', (string) $command); - $this->assertStringContainsString('find . -name \'node_modules\' -prune -o -type f -print', (string) $command); + $this->assertStringContainsString('( [ -e \'server/entry.mjs\' ] && echo \'server/entry.mjs\' || true )', (string) $command); $this->assertStringEndsWith('echo "{APPWRITE_DETECTION_SEPARATOR_END}"', $command); } public function testSiteBuildCommandCanBeOnlyDetectionFileListing(): void { - $command = $this->callBuilds('prepareSiteBuildCommand', '', ''); + $command = $this->callBuilds('prepareSiteBuildCommand', '', '', 'sveltekit'); $this->assertStringStartsWith('echo "{APPWRITE_DETECTION_SEPARATOR_START}"', $command); - $this->assertStringContainsString('cd /usr/local/build && find .', (string) $command); + $this->assertStringContainsString('cd /usr/local/build && ( [ -e \'handler.js\' ] && echo \'handler.js\' || true )', (string) $command); } public function testSplitSiteDetectionLogsRemovesDetectionBlock(): void From 93feb38b6721bf734868a06a86b91062a9c99402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 7 Jul 2026 12:50:23 +0200 Subject: [PATCH 5/7] Fix static html detection --- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 3 +++ tests/unit/Functions/BuildsTest.php | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 210e63ff21..00357211e9 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1391,6 +1391,9 @@ class Builds extends Action $listFilesCommand .= ' && ( [ -e ' . \escapeshellarg($file) . ' ] && echo ' . \escapeshellarg($file) . ' || true )'; } + // Static fallback detection only needs to distinguish 0, 1, or 2+ HTML files, so cap the output + $listFilesCommand .= ' && find . -name \'node_modules\' -prune -o -type f -name \'*.html\' -print | head -n 2'; + $listFilesCommand .= ' && echo "{APPWRITE_DETECTION_SEPARATOR_END}"'; if (empty($command)) { diff --git a/tests/unit/Functions/BuildsTest.php b/tests/unit/Functions/BuildsTest.php index ff64b80c15..00880dcc1e 100644 --- a/tests/unit/Functions/BuildsTest.php +++ b/tests/unit/Functions/BuildsTest.php @@ -50,6 +50,7 @@ final class BuildsTest extends TestCase $this->assertStringStartsWith('npm run build && echo "{APPWRITE_DETECTION_SEPARATOR_START}"', $command); $this->assertStringContainsString('cd /usr/local/build && cd \'./dist folder\'', (string) $command); $this->assertStringContainsString('( [ -e \'server/entry.mjs\' ] && echo \'server/entry.mjs\' || true )', (string) $command); + $this->assertStringContainsString('find . -name \'node_modules\' -prune -o -type f -name \'*.html\' -print | head -n 2', (string) $command); $this->assertStringEndsWith('echo "{APPWRITE_DETECTION_SEPARATOR_END}"', $command); } @@ -59,6 +60,7 @@ final class BuildsTest extends TestCase $this->assertStringStartsWith('echo "{APPWRITE_DETECTION_SEPARATOR_START}"', $command); $this->assertStringContainsString('cd /usr/local/build && ( [ -e \'handler.js\' ] && echo \'handler.js\' || true )', (string) $command); + $this->assertStringContainsString('find . -name \'node_modules\' -prune -o -type f -name \'*.html\' -print | head -n 2', (string) $command); } public function testSplitSiteDetectionLogsRemovesDetectionBlock(): void From 9f62f074ed449a4f744c5a90714e723ce60ca337 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 7 Jul 2026 17:13:25 +0400 Subject: [PATCH 6/7] Add folder attribute and index to files collections with V25 migration --- app/config/collections/common.php | 18 ++++++++++++ src/Appwrite/Migration/Version/V25.php | 38 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/app/config/collections/common.php b/app/config/collections/common.php index c5dc187ba4..2e3df819b7 100644 --- a/app/config/collections/common.php +++ b/app/config/collections/common.php @@ -2662,6 +2662,17 @@ return [ 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('folder'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 2048, + 'signed' => true, + 'required' => false, + 'default' => '', + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('signature'), 'type' => Database::VAR_STRING, @@ -2850,6 +2861,13 @@ return [ 'lengths' => [256], 'orders' => [Database::ORDER_ASC], ], + [ + '$id' => ID::custom('_key_folder'), + 'type' => Database::INDEX_KEY, + 'attributes' => ['folder'], + 'lengths' => [256], + 'orders' => [Database::ORDER_ASC], + ], [ '$id' => ID::custom('_key_signature'), 'type' => Database::INDEX_KEY, diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 800b9b451f..3ca42d2af3 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -7,6 +7,8 @@ use Exception; use Throwable; use Utopia\Console; use Utopia\Database\Database; +use Utopia\Database\Document; +use Utopia\Database\Exception\Duplicate; class V25 extends Migration { @@ -17,6 +19,9 @@ class V25 extends Migration { Console::info('Migrating collections'); $this->migrateCollections(); + + Console::info('Migrating buckets'); + $this->migrateBuckets(); } /** @@ -66,4 +71,37 @@ class V25 extends Migration } } } + + /** + * Add the virtual folder `folder` attribute and index to every + * per-bucket files collection. + * + * @return void + * @throws Throwable + */ + private function migrateBuckets(): void + { + $this->dbForProject->foreach('buckets', function (Document $bucket) { + $bucketTable = "bucket_{$bucket->getSequence()}"; + Console::log("Migrating Bucket {$bucket->getId()} ({$bucket->getAttribute('name')})"); + + try { + $this->createAttributeFromCollection($this->dbForProject, $bucketTable, 'folder', 'files'); + } catch (Duplicate) { + Console::warning("'folder' from {$bucketTable}: Column already exists"); + } catch (Throwable $th) { + Console::warning("'folder' from {$bucketTable}: {$th->getMessage()}"); + } + + try { + $this->createIndexFromCollection($this->dbForProject, $bucketTable, '_key_folder', 'files'); + } catch (Duplicate) { + Console::warning("'_key_folder' from {$bucketTable}: Index already exists"); + } catch (Throwable $th) { + Console::warning("'_key_folder' from {$bucketTable}: {$th->getMessage()}"); + } + + $this->dbForProject->purgeCachedCollection($bucketTable); + }); + } } From 9be60d5486b8b863c77b1d4f22945793c2d14e06 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 7 Jul 2026 17:27:50 +0400 Subject: [PATCH 7/7] Purge metadata cache for bucket tables in V25 migration --- src/Appwrite/Migration/Version/V25.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Appwrite/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index 3ca42d2af3..c66bd0384c 100644 --- a/src/Appwrite/Migration/Version/V25.php +++ b/src/Appwrite/Migration/Version/V25.php @@ -102,6 +102,7 @@ class V25 extends Migration } $this->dbForProject->purgeCachedCollection($bucketTable); + $this->dbForProject->purgeCachedDocument(Database::METADATA, $bucketTable); }); } }