From 728ed57df0ca5f1869d438930d1906c0fb388b7d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jan 2026 18:43:28 +1300 Subject: [PATCH 1/3] Fix database initialization after utopia-php/database 4.5.2 update The 4.5.2 update removed the automatic USE database statement on init, requiring explicit setDatabase() calls on all database resources. Co-Authored-By: Claude Opus 4.5 --- app/cli.php | 2 ++ app/init/constants.php | 3 +++ app/init/resources.php | 2 ++ app/realtime.php | 1 + app/worker.php | 2 ++ 5 files changed, 10 insertions(+) diff --git a/app/cli.php b/app/cli.php index 7493d10ab3..bca0c75442 100644 --- a/app/cli.php +++ b/app/cli.php @@ -78,6 +78,7 @@ CLI::setResource('dbForPlatform', function ($pools, $cache, $authorization) { $dbForPlatform = new Database($adapter, $cache); $dbForPlatform + ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setNamespace('_console') ->setMetadata('host', \gethostname()) @@ -189,6 +190,7 @@ CLI::setResource('getLogsDB', function (Group $pools, Cache $cache, Authorizatio $database = new Database($adapter, $cache); $database + ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setSharedTables(true) ->setNamespace('logsV1') diff --git a/app/init/constants.php b/app/init/constants.php index 0c95c4543b..d51cb6b7af 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -161,6 +161,9 @@ const ACTIVITY_TYPE_GUEST = 'guest'; const MFA_RECENT_DURATION = 1800; // 30 mins +// Database name +const APP_DATABASE = 'appwrite'; + // Database Reconnect const DATABASE_RECONNECT_SLEEP = 2; const DATABASE_RECONNECT_MAX_ATTEMPTS = 10; diff --git a/app/init/resources.php b/app/init/resources.php index 371609da97..afe419f509 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -563,6 +563,7 @@ App::setResource('dbForPlatform', function (Group $pools, Cache $cache, Authoriz $database = new Database($adapter, $cache); $database + ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setNamespace('_console') ->setMetadata('host', \gethostname()) @@ -643,6 +644,7 @@ App::setResource('getLogsDB', function (Group $pools, Cache $cache, Authorizatio $database = new Database($adapter, $cache); $database + ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setSharedTables(true) ->setNamespace('logsV1') diff --git a/app/realtime.php b/app/realtime.php index 31e6015d92..c041683668 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -66,6 +66,7 @@ if (!function_exists('getConsoleDB')) { $adapter = new DatabasePool($pools->get('console')); $database = new Database($adapter, getCache()); $database + ->setDatabase(APP_DATABASE) ->setNamespace('_console') ->setMetadata('host', \gethostname()) ->setMetadata('project', '_console'); diff --git a/app/worker.php b/app/worker.php index d31e63fc8b..5f9d7d88ae 100644 --- a/app/worker.php +++ b/app/worker.php @@ -65,6 +65,7 @@ Server::setResource('dbForPlatform', function (Cache $cache, Registry $register, $dbForPlatform = new Database($adapter, $cache); $dbForPlatform + ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setNamespace('_console') ->setDocumentType('users', User::class) @@ -198,6 +199,7 @@ Server::setResource('getLogsDB', function (Group $pools, Cache $cache, Authoriza $database = new Database($adapter, $cache); $database + ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setSharedTables(true) ->setNamespace('logsV1') From a0e4e89621549ee592f970b639a2c7b35f3b401e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jan 2026 18:45:18 +1300 Subject: [PATCH 2/3] Update lock --- composer.lock | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/composer.lock b/composer.lock index 6fead373dd..c06922f434 100644 --- a/composer.lock +++ b/composer.lock @@ -3455,24 +3455,25 @@ }, { "name": "utopia-php/abuse", - "version": "1.0.2", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/utopia-php/abuse.git", - "reference": "611fa66a97e87c0dbbc133a717d970da7a5ca828" + "reference": "15cd5dbefa4453e8a2d90649a7078e242966ac3f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/abuse/zipball/611fa66a97e87c0dbbc133a717d970da7a5ca828", - "reference": "611fa66a97e87c0dbbc133a717d970da7a5ca828", + "url": "https://api.github.com/repos/utopia-php/abuse/zipball/15cd5dbefa4453e8a2d90649a7078e242966ac3f", + "reference": "15cd5dbefa4453e8a2d90649a7078e242966ac3f", "shasum": "" }, "require": { + "appwrite/appwrite": "19.*", "ext-curl": "*", "ext-pdo": "*", "ext-redis": "*", "php": ">=8.0", - "utopia-php/database": "*" + "utopia-php/database": "4.*" }, "require-dev": { "laravel/pint": "1.*", @@ -3500,9 +3501,9 @@ ], "support": { "issues": "https://github.com/utopia-php/abuse/issues", - "source": "https://github.com/utopia-php/abuse/tree/1.0.2" + "source": "https://github.com/utopia-php/abuse/tree/1.2.1" }, - "time": "2025-10-20T07:18:33+00:00" + "time": "2026-01-15T02:09:49+00:00" }, { "name": "utopia-php/analytics", @@ -3898,16 +3899,16 @@ }, { "name": "utopia-php/database", - "version": "4.5.1", + "version": "4.5.2", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "7b935bb09aeae8aeff5a28f6f2485cef1cc4d898" + "reference": "8e6a033d4da09a2f2ac1f79fd85fcfa2da018d23" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/7b935bb09aeae8aeff5a28f6f2485cef1cc4d898", - "reference": "7b935bb09aeae8aeff5a28f6f2485cef1cc4d898", + "url": "https://api.github.com/repos/utopia-php/database/zipball/8e6a033d4da09a2f2ac1f79fd85fcfa2da018d23", + "reference": "8e6a033d4da09a2f2ac1f79fd85fcfa2da018d23", "shasum": "" }, "require": { @@ -3950,9 +3951,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/4.5.1" + "source": "https://github.com/utopia-php/database/tree/4.5.2" }, - "time": "2026-01-14T12:07:24+00:00" + "time": "2026-01-15T04:23:30+00:00" }, { "name": "utopia-php/detector", From b1171c661ea7fe98a21ca1b1613797a0471b532a Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 15 Jan 2026 19:08:25 +1300 Subject: [PATCH 3/3] Add setDatabase() to all project database instances This completes the fix for utopia-php/database 4.5.2 which removed the automatic USE database statement. All Database instances that create or query project databases now have explicit setDatabase() calls. Co-Authored-By: Claude Opus 4.5 --- app/cli.php | 1 + app/controllers/api/projects.php | 1 + app/init/resources.php | 2 ++ app/realtime.php | 1 + app/worker.php | 2 ++ 5 files changed, 7 insertions(+) diff --git a/app/cli.php b/app/cli.php index bca0c75442..4b85ba35c6 100644 --- a/app/cli.php +++ b/app/cli.php @@ -169,6 +169,7 @@ CLI::setResource('getProjectDB', function (Group $pools, Database $dbForPlatform } $database + ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setMetadata('host', \gethostname()) ->setMetadata('project', $project->getId()); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 74f734a856..b0493ff38f 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -227,6 +227,7 @@ App::post('/v1/projects') if (!$sharedTablesV2) { $adapter = new DatabasePool($pools->get($dsn->getHost())); $dbForProject = new Database($adapter, $cache); + $dbForProject->setDatabase(APP_DATABASE); if ($sharedTables) { $dbForProject diff --git a/app/init/resources.php b/app/init/resources.php index afe419f509..a9d46a17be 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -533,6 +533,7 @@ App::setResource('dbForProject', function (Group $pools, Database $dbForPlatform $database = new Database($adapter, $cache); $database + ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setMetadata('host', \gethostname()) ->setMetadata('project', $project->getId()) @@ -593,6 +594,7 @@ App::setResource('getProjectDB', function (Group $pools, Database $dbForPlatform $configure = (function (Database $database) use ($project, $dsn, $authorization) { $database + ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setMetadata('host', \gethostname()) ->setMetadata('project', $project->getId()) diff --git a/app/realtime.php b/app/realtime.php index c041683668..fcc5329982 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -123,6 +123,7 @@ if (!function_exists('getProjectDB')) { } $database + ->setDatabase(APP_DATABASE) ->setMetadata('host', \gethostname()) ->setMetadata('project', $project->getId()); diff --git a/app/worker.php b/app/worker.php index 5f9d7d88ae..ba8bf98568 100644 --- a/app/worker.php +++ b/app/worker.php @@ -119,6 +119,7 @@ Server::setResource('dbForProject', function (Cache $cache, Registry $register, } $database + ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER); @@ -180,6 +181,7 @@ Server::setResource('getProjectDB', function (Group $pools, Database $dbForPlatf } $database + ->setDatabase(APP_DATABASE) ->setAuthorization($authorization) ->setTimeout(APP_DATABASE_TIMEOUT_MILLISECONDS_WORKER);