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/composer.lock b/composer.lock index 5dfa924579..99d770e9a8 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/Migration/Version/V25.php b/src/Appwrite/Migration/Version/V25.php index f59f4e3542..1b8533fb39 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; use Utopia\Database\Query; class V25 extends Migration @@ -18,6 +20,9 @@ class V25 extends Migration { Console::info('Migrating collections'); $this->migrateCollections(); + + Console::info('Migrating buckets'); + $this->migrateBuckets(); } /** @@ -87,4 +92,38 @@ 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); + $this->dbForProject->purgeCachedDocument(Database::METADATA, $bucketTable); + }); + } } diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 077dc3bc1c..f1ec93bc86 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -749,7 +749,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)); @@ -1399,7 +1399,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'; @@ -1407,7 +1407,14 @@ 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 )'; + } + + // 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)) { return $listFilesCommand; diff --git a/tests/unit/Functions/BuildsTest.php b/tests/unit/Functions/BuildsTest.php index fd387c20ba..a14a8137b3 100644 --- a/tests/unit/Functions/BuildsTest.php +++ b/tests/unit/Functions/BuildsTest.php @@ -45,20 +45,22 @@ 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->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); } 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); + $this->assertStringContainsString('find . -name \'node_modules\' -prune -o -type f -name \'*.html\' -print | head -n 2', (string) $command); } public function testSplitSiteDetectionLogsRemovesDetectionBlock(): void