Merge pull request #12824 from nextcloud/feature/12763/add-setup-check-for-bigint-conversion

Add setup check for pending bigint conversion
This commit is contained in:
Morris Jobke 2018-12-05 18:52:56 +01:00 committed by GitHub
commit fe5813783b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 15 deletions

View file

@ -23,6 +23,7 @@
namespace OC\Core\Command\Db;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Types\Type;
use OC\DB\SchemaWrapper;
use OCP\IDBConnection;
@ -51,6 +52,7 @@ class ConvertFilecacheBigInt extends Command {
}
protected function getColumnsByTable() {
// also update in CheckSetupController::hasBigIntConversionPendingColumns()
return [
'activity' => ['activity_id', 'object_id'],
'activity_mq' => ['mail_id'],
@ -63,6 +65,7 @@ class ConvertFilecacheBigInt extends Command {
protected function execute(InputInterface $input, OutputInterface $output) {
$schema = new SchemaWrapper($this->connection);
$isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform;
$updates = [];
$tables = $this->getColumnsByTable();
@ -75,11 +78,13 @@ class ConvertFilecacheBigInt extends Command {
foreach ($columns as $columnName) {
$column = $table->getColumn($columnName);
if ($column->getType()->getName() !== Type::BIGINT) {
$isAutoIncrement = $column->getAutoincrement();
$isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
if ($column->getType()->getName() !== Type::BIGINT && !$isAutoIncrementOnSqlite) {
$column->setType(Type::getType(Type::BIGINT));
$column->setOptions(['length' => 20]);
$updates[] = $tableName . '.' . $columnName;
$updates[] = '* ' . $tableName . '.' . $columnName;
}
}
}
@ -89,6 +94,10 @@ class ConvertFilecacheBigInt extends Command {
return 0;
}
$output->writeln('<comment>Following columns will be updated:</comment>');
$output->writeln('');
$output->writeln($updates);
$output->writeln('');
$output->writeln('<comment>This can take up to hours, depending on the number of files in your instance!</comment>');
if ($input->isInteractive()) {

View file

@ -337,6 +337,22 @@
type: OC.SetupChecks.MESSAGE_TYPE_INFO
})
}
if (data.pendingBigIntConversionColumns.length > 0) {
var listOfPendingBigIntConversionColumns = "";
data.pendingBigIntConversionColumns.forEach(function(element){
listOfPendingBigIntConversionColumns += "<li>" + element + "</li>";
});
messages.push({
msg: t(
'core',
'Some columns in the database are missing a conversion to big int. Due to the fact that changing column types on big tables could take some time they were not changed automatically. By running \'occ db:convert-filecache-bigint\' those pending changes could be applied manually. This operation needs to be made while the instance is offline. For further details read <a target="_blank" rel="noreferrer noopener" href="{docLink}">the documentation page about this</a>.',
{
docLink: oc_defaults.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-bigint-conversion'),
}
) + "<ul>" + listOfPendingBigIntConversionColumns + "</ul>",
type: OC.SetupChecks.MESSAGE_TYPE_INFO
})
}
if (data.isSqliteUsed) {
messages.push({
msg: t(

View file

@ -211,7 +211,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);
@ -261,7 +262,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);
@ -312,7 +314,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);
@ -361,7 +364,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);
@ -408,7 +412,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);
@ -457,7 +462,8 @@ describe('OC.SetupChecks tests', function() {
appDirsWithDifferentOwner: [
'/some/path'
],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);
@ -504,7 +510,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);
@ -551,7 +558,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);
@ -596,9 +604,10 @@ describe('OC.SetupChecks tests', function() {
cronInfo: {
diffInSeconds: 0
},
isMemoryLimitSufficient: false,
appDirsWithDifferentOwner: [],
recommendedPHPModules: [],
isMemoryLimitSufficient: false
pendingBigIntConversionColumns: []
})
);
@ -666,7 +675,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);
@ -714,7 +724,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);
@ -762,7 +773,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);
@ -810,7 +822,8 @@ describe('OC.SetupChecks tests', function() {
},
isMemoryLimitSufficient: true,
appDirsWithDifferentOwner: [],
recommendedPHPModules: []
recommendedPHPModules: [],
pendingBigIntConversionColumns: []
})
);

View file

@ -34,11 +34,13 @@ use bantu\IniGetWrapper\IniGetWrapper;
use DirectoryIterator;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Types\Type;
use GuzzleHttp\Exception\ClientException;
use OC;
use OC\AppFramework\Http;
use OC\DB\Connection;
use OC\DB\MissingIndexInformation;
use OC\DB\SchemaWrapper;
use OC\IntegrityCheck\Checker;
use OC\Lock\NoopLockingProvider;
use OC\MemoryInfo;
@ -603,6 +605,39 @@ Raw output
return $recommendedPHPModules;
}
protected function hasBigIntConversionPendingColumns(): array {
// copy of ConvertFilecacheBigInt::getColumnsByTable()
$tables = [
'activity' => ['activity_id', 'object_id'],
'activity_mq' => ['mail_id'],
'filecache' => ['fileid', 'storage', 'parent', 'mimetype', 'mimepart', 'mtime', 'storage_mtime'],
'mimetypes' => ['id'],
'storages' => ['numeric_id'],
];
$schema = new SchemaWrapper($this->db);
$isSqlite = $this->db->getDatabasePlatform() instanceof SqlitePlatform;
$pendingColumns = [];
foreach ($tables as $tableName => $columns) {
if (!$schema->hasTable($tableName)) {
continue;
}
$table = $schema->getTable($tableName);
foreach ($columns as $columnName) {
$column = $table->getColumn($columnName);
$isAutoIncrement = $column->getAutoincrement();
$isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement;
if ($column->getType()->getName() !== Type::BIGINT && !$isAutoIncrementOnSqlite) {
$pendingColumns[] = $tableName . '.' . $columnName;
}
}
}
return $pendingColumns;
}
/**
* @return DataResponse
*/
@ -643,6 +678,7 @@ Raw output
'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(),
'recommendedPHPModules' => $this->hasRecommendedPHPModules(),
'pendingBigIntConversionColumns' => $this->hasBigIntConversionPendingColumns(),
]
);
}

View file

@ -159,6 +159,7 @@ class CheckSetupControllerTest extends TestCase {
'hasOpcacheLoaded',
'getAppDirsWithDifferentOwner',
'hasRecommendedPHPModules',
'hasBigIntConversionPendingColumns',
])->getMock();
}
@ -493,6 +494,11 @@ class CheckSetupControllerTest extends TestCase {
->method('hasRecommendedPHPModules')
->willReturn([]);
$this->checkSetupController
->expects($this->once())
->method('hasBigIntConversionPendingColumns')
->willReturn([]);
$expected = new DataResponse(
[
'isGetenvServerWorking' => true,
@ -536,6 +542,7 @@ class CheckSetupControllerTest extends TestCase {
'isMemoryLimitSufficient' => true,
'appDirsWithDifferentOwner' => [],
'recommendedPHPModules' => [],
'pendingBigIntConversionColumns' => [],
]
);
$this->assertEquals($expected, $this->checkSetupController->check());