From ea8804fd52d38d0c0fd24151b35c1fd1ff6da9a2 Mon Sep 17 00:00:00 2001 From: shimon Date: Fri, 2 Jun 2023 08:10:03 +0300 Subject: [PATCH 01/11] Extract db from list while backing --- app/controllers/api/projects.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index dec5520d85..5045e76161 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -18,7 +18,6 @@ use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\ID; -use Utopia\Database\DateTime; use Utopia\Database\Permission; use Utopia\Database\Query; use Utopia\Database\Role; @@ -90,7 +89,26 @@ App::post('/v1/projects') } $projectId = ($projectId == 'unique()') ? ID::unique() : $projectId; + + $backups[0] = ['from' => '4:30', 'to' => '5:30']; + $backups[1] = ['from' => '11:30', 'to' => '12:30']; + $backups[2] = ['from' => '21:30', 'to' => '22:30']; + $databases = Config::getParam('pools-database', []); + /** + * Extract db from list while backing + */ + $now = new \DateTime(); + foreach ($databases as $pos => $database) { + $backup = $backups[$pos]; + $from = DateTime::createFromFormat('H:i', $backup['from']); + $to = DateTime::createFromFormat('H:i', $backup['to']); + + if ($now >= $from && $now <= $to) { + unset($databases[$pos]); + } + } + $database = $databases[array_rand($databases)]; if ($projectId === 'console') { From 071b2e58264bf82fee08c36479340704f83aca10 Mon Sep 17 00:00:00 2001 From: shimon Date: Fri, 2 Jun 2023 11:06:35 +0300 Subject: [PATCH 02/11] Extract db from list while backing --- app/controllers/api/projects.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 5045e76161..c867e8077a 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -98,17 +98,18 @@ App::post('/v1/projects') /** * Extract db from list while backing */ - $now = new \DateTime(); - foreach ($databases as $pos => $database) { - $backup = $backups[$pos]; - $from = DateTime::createFromFormat('H:i', $backup['from']); - $to = DateTime::createFromFormat('H:i', $backup['to']); + if (count($databases) > 1) { + $now = new \DateTime(); + foreach ($databases as $pos => $database) { + $backup = $backups[$pos]; + $from = DateTime::createFromFormat('H:i', $backup['from']); + $to = DateTime::createFromFormat('H:i', $backup['to']); - if ($now >= $from && $now <= $to) { - unset($databases[$pos]); + if ($now >= $from && $now <= $to) { + unset($databases[$pos]); + } } } - $database = $databases[array_rand($databases)]; if ($projectId === 'console') { From 9a071df37805fa9bf6c5cca16c889dd9f7db70a2 Mon Sep 17 00:00:00 2001 From: shimon Date: Fri, 2 Jun 2023 16:23:21 +0300 Subject: [PATCH 03/11] minor changes --- app/controllers/api/projects.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index c867e8077a..bb2809d275 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -90,9 +90,9 @@ App::post('/v1/projects') $projectId = ($projectId == 'unique()') ? ID::unique() : $projectId; - $backups[0] = ['from' => '4:30', 'to' => '5:30']; - $backups[1] = ['from' => '11:30', 'to' => '12:30']; - $backups[2] = ['from' => '21:30', 'to' => '22:30']; + $backups['cloud-fra1-prod-database-project-0'] = ['from' => '4:30', 'to' => '5:30']; + $backups['cloud-fra1-prod-database-project-1'] = ['from' => '11:30', 'to' => '12:30']; + $backups['cloud-fra1-prod-database-project-2'] = ['from' => '21:30', 'to' => '22:30']; $databases = Config::getParam('pools-database', []); /** @@ -100,13 +100,14 @@ App::post('/v1/projects') */ if (count($databases) > 1) { $now = new \DateTime(); - foreach ($databases as $pos => $database) { - $backup = $backups[$pos]; + foreach ($databases as $name => $database) { + $backup = $backups[$name]; $from = DateTime::createFromFormat('H:i', $backup['from']); $to = DateTime::createFromFormat('H:i', $backup['to']); if ($now >= $from && $now <= $to) { - unset($databases[$pos]); + unset($databases[$name]); + break; } } } From f5c4e4cd8a7e2a68ca372226ea3d0d9921a18128 Mon Sep 17 00:00:00 2001 From: shimon Date: Fri, 2 Jun 2023 16:52:38 +0300 Subject: [PATCH 04/11] minor changes --- app/controllers/api/projects.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index bb2809d275..6a144a2c02 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -90,27 +90,33 @@ App::post('/v1/projects') $projectId = ($projectId == 'unique()') ? ID::unique() : $projectId; - $backups['cloud-fra1-prod-database-project-0'] = ['from' => '4:30', 'to' => '5:30']; - $backups['cloud-fra1-prod-database-project-1'] = ['from' => '11:30', 'to' => '12:30']; - $backups['cloud-fra1-prod-database-project-2'] = ['from' => '21:30', 'to' => '22:30']; + $backups['db_fra1_01'] = ['from' => '4:30', 'to' => '5:30']; + $backups['db_fra1_02'] = ['from' => '13:30', 'to' => '14:30']; + $backups['db_fra1_03'] = ['from' => '21:30', 'to' => '22:30']; $databases = Config::getParam('pools-database', []); + /** * Extract db from list while backing */ if (count($databases) > 1) { $now = new \DateTime(); - foreach ($databases as $name => $database) { - $backup = $backups[$name]; + + foreach ($databases as $pos => $database) { + if (empty($backups[$database])) { + continue; + } + $backup = $backups[$database]; $from = DateTime::createFromFormat('H:i', $backup['from']); $to = DateTime::createFromFormat('H:i', $backup['to']); - if ($now >= $from && $now <= $to) { - unset($databases[$name]); + unset($databases[$pos]); break; } } + $databases = array_values($databases); } + $database = $databases[array_rand($databases)]; if ($projectId === 'console') { From 5c9ad6fddda59213c06fd9a539205d9ec6931e6c Mon Sep 17 00:00:00 2001 From: shimon Date: Fri, 2 Jun 2023 17:01:15 +0300 Subject: [PATCH 05/11] minor changes --- app/controllers/api/projects.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 6a144a2c02..57abbbd391 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -95,7 +95,7 @@ App::post('/v1/projects') $backups['db_fra1_03'] = ['from' => '21:30', 'to' => '22:30']; $databases = Config::getParam('pools-database', []); - + var_dump($databases); /** * Extract db from list while backing */ From 6a9011af72040a8f6b63bcfb2f1cd8eff4444b19 Mon Sep 17 00:00:00 2001 From: shimon Date: Fri, 2 Jun 2023 17:14:10 +0300 Subject: [PATCH 06/11] minor changes --- app/controllers/api/projects.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 57abbbd391..74606f143c 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -90,12 +90,12 @@ App::post('/v1/projects') $projectId = ($projectId == 'unique()') ? ID::unique() : $projectId; - $backups['db_fra1_01'] = ['from' => '4:30', 'to' => '5:30']; - $backups['db_fra1_02'] = ['from' => '13:30', 'to' => '14:30']; - $backups['db_fra1_03'] = ['from' => '21:30', 'to' => '22:30']; + $backups['database_db_fra1_02'] = ['from' => '4:30', 'to' => '5:30']; + $backups['database_db_fra1_03'] = ['from' => '13:30', 'to' => '14:30']; + $backups['database_db_fra1_04'] = ['from' => '21:30', 'to' => '22:30']; $databases = Config::getParam('pools-database', []); - var_dump($databases); + /** * Extract db from list while backing */ From 931b6fa3857f261f8cda547b804041144febecc1 Mon Sep 17 00:00:00 2001 From: shimon Date: Fri, 2 Jun 2023 17:44:24 +0300 Subject: [PATCH 07/11] minor cache authorization fix --- app/controllers/shared/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index db35cebc65..4fc0d9c345 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -465,7 +465,7 @@ App::shutdown() ]) ; $signature = md5($data); - $cacheLog = $dbForProject->getDocument('cache', $key); + $cacheLog = Authorization::skip(fn () => $dbForProject->getDocument('cache', $key)); $accessedAt = $cacheLog->getAttribute('accessedAt', ''); $now = DateTime::now(); if ($cacheLog->isEmpty()) { From d7733dde011370d4417632c32fd3fe918aa20b6b Mon Sep 17 00:00:00 2001 From: shimon Date: Fri, 2 Jun 2023 17:52:19 +0300 Subject: [PATCH 08/11] minor cache authorization fix rollback --- app/controllers/shared/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 4fc0d9c345..db35cebc65 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -465,7 +465,7 @@ App::shutdown() ]) ; $signature = md5($data); - $cacheLog = Authorization::skip(fn () => $dbForProject->getDocument('cache', $key)); + $cacheLog = $dbForProject->getDocument('cache', $key); $accessedAt = $cacheLog->getAttribute('accessedAt', ''); $now = DateTime::now(); if ($cacheLog->isEmpty()) { From 9f02ed700d65d8bb3d87ce18bd3e763dc7d19755 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 6 Jun 2023 12:09:14 +0000 Subject: [PATCH 09/11] feat: update db backups schedule --- app/controllers/api/projects.php | 6 +-- composer.lock | 73 +++++++++++++++++--------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 74606f143c..6f930c8c66 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -90,9 +90,9 @@ App::post('/v1/projects') $projectId = ($projectId == 'unique()') ? ID::unique() : $projectId; - $backups['database_db_fra1_02'] = ['from' => '4:30', 'to' => '5:30']; - $backups['database_db_fra1_03'] = ['from' => '13:30', 'to' => '14:30']; - $backups['database_db_fra1_04'] = ['from' => '21:30', 'to' => '22:30']; + $backups['database_db_fra1_02'] = ['from' => '7:30', 'to' => '8:15']; + $backups['database_db_fra1_03'] = ['from' => '10:30', 'to' => '11:15']; + $backups['database_db_fra1_04'] = ['from' => '13:30', 'to' => '14:15']; $databases = Config::getParam('pools-database', []); diff --git a/composer.lock b/composer.lock index 3d9a6c8bda..4510e49ba7 100644 --- a/composer.lock +++ b/composer.lock @@ -1540,16 +1540,16 @@ }, { "name": "symfony/deprecation-contracts", - "version": "v3.2.1", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e" + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e", - "reference": "e2d1534420bd723d0ef5aec58a22c5fe60ce6f5e", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", "shasum": "" }, "require": { @@ -1558,7 +1558,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "3.3-dev" + "dev-main": "3.4-dev" }, "thanks": { "name": "symfony/contracts", @@ -1587,7 +1587,7 @@ "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.2.1" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.3.0" }, "funding": [ { @@ -1603,7 +1603,7 @@ "type": "tidelift" } ], - "time": "2023-03-01T10:25:55+00:00" + "time": "2023-05-23T14:45:45+00:00" }, { "name": "utopia-php/abuse", @@ -2058,16 +2058,16 @@ }, { "name": "utopia-php/framework", - "version": "0.26.1", + "version": "0.26.3", "source": { "type": "git", "url": "https://github.com/utopia-php/framework.git", - "reference": "feb8941f8dbd37f869986ca56c81a0f76b29fbcd" + "reference": "7a18a2b0d6c8dba878c926b73650fd2c4eeaa70d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/feb8941f8dbd37f869986ca56c81a0f76b29fbcd", - "reference": "feb8941f8dbd37f869986ca56c81a0f76b29fbcd", + "url": "https://api.github.com/repos/utopia-php/framework/zipball/7a18a2b0d6c8dba878c926b73650fd2c4eeaa70d", + "reference": "7a18a2b0d6c8dba878c926b73650fd2c4eeaa70d", "shasum": "" }, "require": { @@ -2096,9 +2096,9 @@ ], "support": { "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.26.1" + "source": "https://github.com/utopia-php/framework/tree/0.26.3" }, - "time": "2023-05-30T07:18:22+00:00" + "time": "2023-06-03T14:01:15+00:00" }, { "name": "utopia-php/image", @@ -2953,25 +2953,29 @@ }, { "name": "doctrine/deprecations", - "version": "v1.1.0", + "version": "v1.1.1", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "8cffffb2218e01f3b370bf763e00e81697725259" + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/8cffffb2218e01f3b370bf763e00e81697725259", - "reference": "8cffffb2218e01f3b370bf763e00e81697725259", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", + "reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { "doctrine/coding-standard": "^9", - "phpunit/phpunit": "^7.5|^8.5|^9.5", - "psr/log": "^1|^2|^3" + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" }, "suggest": { "psr/log": "Allows logging deprecations via PSR-3 logger implementation" @@ -2990,9 +2994,9 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/v1.1.0" + "source": "https://github.com/doctrine/deprecations/tree/v1.1.1" }, - "time": "2023-05-29T18:55:17+00:00" + "time": "2023-06-03T09:27:29+00:00" }, { "name": "doctrine/instantiator", @@ -3526,16 +3530,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.7.1", + "version": "1.7.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "dfc078e8af9c99210337325ff5aa152872c98714" + "reference": "b2fe4d22a5426f38e014855322200b97b5362c0d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/dfc078e8af9c99210337325ff5aa152872c98714", - "reference": "dfc078e8af9c99210337325ff5aa152872c98714", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/b2fe4d22a5426f38e014855322200b97b5362c0d", + "reference": "b2fe4d22a5426f38e014855322200b97b5362c0d", "shasum": "" }, "require": { @@ -3578,9 +3582,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.1" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.2" }, - "time": "2023-03-27T19:02:04+00:00" + "time": "2023-05-30T18:13:47+00:00" }, { "name": "phpspec/prophecy", @@ -3652,22 +3656,23 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.21.3", + "version": "1.22.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "b0c366dd2cea79407d635839d25423ba07c55dd6" + "reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/b0c366dd2cea79407d635839d25423ba07c55dd6", - "reference": "b0c366dd2cea79407d635839d25423ba07c55dd6", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/ec58baf7b3c7f1c81b3b00617c953249fb8cf30c", + "reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c", "shasum": "" }, "require": { "php": "^7.2 || ^8.0" }, "require-dev": { + "doctrine/annotations": "^2.0", "nikic/php-parser": "^4.15", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/extension-installer": "^1.0", @@ -3692,9 +3697,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.21.3" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.0" }, - "time": "2023-05-29T19:31:28+00:00" + "time": "2023-06-01T12:35:21+00:00" }, { "name": "phpunit/php-code-coverage", From 5c6cbbe370bef7f3c59df09052523775d56be35c Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 6 Jun 2023 12:11:50 +0000 Subject: [PATCH 10/11] chore: review comments --- app/controllers/api/projects.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 6f930c8c66..1060bc97f3 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -102,7 +102,7 @@ App::post('/v1/projects') if (count($databases) > 1) { $now = new \DateTime(); - foreach ($databases as $pos => $database) { + foreach ($databases as $index => $database) { if (empty($backups[$database])) { continue; } @@ -110,7 +110,7 @@ App::post('/v1/projects') $from = DateTime::createFromFormat('H:i', $backup['from']); $to = DateTime::createFromFormat('H:i', $backup['to']); if ($now >= $from && $now <= $to) { - unset($databases[$pos]); + unset($databases[$index]); break; } } From 8fdb9e6592d6c8f9c862eaed981bf2439ae9b32f Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 6 Jun 2023 17:51:42 +0530 Subject: [PATCH 11/11] Update app/controllers/api/projects.php --- app/controllers/api/projects.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 1060bc97f3..c68ce17b59 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -114,7 +114,6 @@ App::post('/v1/projects') break; } } - $databases = array_values($databases); } $database = $databases[array_rand($databases)];