Skip to content

Commit 1ea8e6a

Browse files
committed
feat(setupchecks): add row format setup check for MySQL databases
Signed-off-by: Benjamin Gaussorgues <[email protected]>
1 parent 6c14c93 commit 1ea8e6a

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => $baseDir . '/../lib/SetupChecks/MaintenanceWindowStart.php',
105105
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => $baseDir . '/../lib/SetupChecks/MemcacheConfigured.php',
106106
'OCA\\Settings\\SetupChecks\\MimeTypeMigrationAvailable' => $baseDir . '/../lib/SetupChecks/MimeTypeMigrationAvailable.php',
107+
'OCA\\Settings\\SetupChecks\\MysqlRowFormat' => $baseDir . '/../lib/SetupChecks/MysqlRowFormat.php',
107108
'OCA\\Settings\\SetupChecks\\MysqlUnicodeSupport' => $baseDir . '/../lib/SetupChecks/MysqlUnicodeSupport.php',
108109
'OCA\\Settings\\SetupChecks\\OcxProviders' => $baseDir . '/../lib/SetupChecks/OcxProviders.php',
109110
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => $baseDir . '/../lib/SetupChecks/OverwriteCliUrl.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class ComposerStaticInitSettings
119119
'OCA\\Settings\\SetupChecks\\MaintenanceWindowStart' => __DIR__ . '/..' . '/../lib/SetupChecks/MaintenanceWindowStart.php',
120120
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => __DIR__ . '/..' . '/../lib/SetupChecks/MemcacheConfigured.php',
121121
'OCA\\Settings\\SetupChecks\\MimeTypeMigrationAvailable' => __DIR__ . '/..' . '/../lib/SetupChecks/MimeTypeMigrationAvailable.php',
122+
'OCA\\Settings\\SetupChecks\\MysqlRowFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/MysqlRowFormat.php',
122123
'OCA\\Settings\\SetupChecks\\MysqlUnicodeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/MysqlUnicodeSupport.php',
123124
'OCA\\Settings\\SetupChecks\\OcxProviders' => __DIR__ . '/..' . '/../lib/SetupChecks/OcxProviders.php',
124125
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => __DIR__ . '/..' . '/../lib/SetupChecks/OverwriteCliUrl.php',

apps/settings/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
use OCA\Settings\SetupChecks\MaintenanceWindowStart;
4848
use OCA\Settings\SetupChecks\MemcacheConfigured;
4949
use OCA\Settings\SetupChecks\MimeTypeMigrationAvailable;
50+
use OCA\Settings\SetupChecks\MysqlRowFormat;
5051
use OCA\Settings\SetupChecks\MysqlUnicodeSupport;
5152
use OCA\Settings\SetupChecks\OcxProviders;
5253
use OCA\Settings\SetupChecks\OverwriteCliUrl;
@@ -181,6 +182,7 @@ public function register(IRegistrationContext $context): void {
181182
$context->registerSetupCheck(MaintenanceWindowStart::class);
182183
$context->registerSetupCheck(MemcacheConfigured::class);
183184
$context->registerSetupCheck(MimeTypeMigrationAvailable::class);
185+
$context->registerSetupCheck(MysqlRowFormat::class);
184186
$context->registerSetupCheck(MysqlUnicodeSupport::class);
185187
$context->registerSetupCheck(OcxProviders::class);
186188
$context->registerSetupCheck(OverwriteCliUrl::class);
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
namespace OCA\Settings\SetupChecks;
10+
11+
use Doctrine\DBAL\Platforms\MySQLPlatform;
12+
use OC\DB\Connection;
13+
use OCP\IConfig;
14+
use OCP\IL10N;
15+
use OCP\IURLGenerator;
16+
use OCP\SetupCheck\ISetupCheck;
17+
use OCP\SetupCheck\SetupResult;
18+
19+
class MysqlRowFormat implements ISetupCheck {
20+
public function __construct(
21+
private IL10N $l10n,
22+
private IConfig $config,
23+
private Connection $connection,
24+
private IURLGenerator $urlGenerator,
25+
) {
26+
}
27+
28+
public function getName(): string {
29+
return $this->l10n->t('MySQL row format');
30+
}
31+
32+
public function getCategory(): string {
33+
return 'database';
34+
}
35+
36+
public function run(): SetupResult {
37+
if (!$this->connection->getDatabasePlatform() instanceof MySQLPlatform) {
38+
return SetupResult::success($this->l10n->t('You are not using MySQL'));
39+
}
40+
41+
$compressedRowTables = $this->getRowCompressedTables();
42+
if (empty($compressedRowTables)) {
43+
return SetupResult::success($this->l10n->t('None of your table use ROW_FORMAT=Compressed'));
44+
}
45+
46+
return SetupResult::warning(
47+
$this->l10n->t(
48+
'Some tables are using ROW_FORMAT=Compressed. This format is known to hurt performances. Please fix the following tables: %s',
49+
implode(', ', $compressedRowTables),
50+
),
51+
'https://dev.mysql.com/doc/refman/en/innodb-row-format.html',
52+
);
53+
}
54+
55+
/**
56+
* @return string[]
57+
*/
58+
private function getRowCompressedTables(): array {
59+
$sql = 'SELECT table_name
60+
FROM information_schema.tables
61+
WHERE table_schema = ?
62+
AND table_name LIKE "*PREFIX*%"
63+
AND row_format = "Compressed";';
64+
65+
return $this->connection->executeQuery(
66+
$sql,
67+
[$this->config->getSystemValueString('dbname')],
68+
)->fetchFirstColumn();
69+
}
70+
}

0 commit comments

Comments
 (0)