Merge pull request #9687 from annando/drop-unused

Drop unused friendica tables
2022.09-rc
Hypolite Petovan 2020-12-20 19:11:45 -05:00 zatwierdzone przez GitHub
commit c8476f6838
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 62 dodań i 12 usunięć

Wyświetl plik

@ -48,21 +48,25 @@ class DatabaseStructure extends \Asika\SimpleConsole\Console
$help = <<<HELP $help = <<<HELP
console dbstructure - Performs database updates console dbstructure - Performs database updates
Usage Usage
bin/console dbstructure <command> [-h|--help|-?] |-f|--force] [-v] bin/console dbstructure <command> [options]
Commands Commands
dryrun Show database update schema queries without running them drop Show tables that aren't in use by Friendica anymore and can be dropped
-e|--execute Execute the dropping
update Update database schema update Update database schema
-f|--force Force the update command (Even if the database structure matches)
-o|--override Override running or stalling updates
dryrun Show database update schema queries without running them
dumpsql Dump database schema dumpsql Dump database schema
toinnodb Convert all tables from MyISAM or InnoDB in the Antelope file format to InnoDB in the Barracuda file format toinnodb Convert all tables from MyISAM or InnoDB in the Antelope file format to InnoDB in the Barracuda file format
initial Set needed initial values in the tables initial Set needed initial values in the tables
version Set the database to a given number version Set the database to a given number
Options General Options
-h|--help|-? Show help information -h|--help|-? Show help information
-v Show more debug information. -v Show more debug information.
-f|--force Force the update command (Even if the database structure matches)
-o|--override Override running or stalling updates
HELP; HELP;
return $help; return $help;
} }
@ -109,6 +113,12 @@ HELP;
$override = $this->getOption(['o', 'override'], false); $override = $this->getOption(['o', 'override'], false);
$output = Update::run($basePath, $force, $override,true, false); $output = Update::run($basePath, $force, $override,true, false);
break; break;
case "drop":
$execute = $this->getOption(['e', 'execute'], false);
ob_start();
DBStructure::dropTables($execute);
$output = ob_get_clean();
break;
case "dumpsql": case "dumpsql":
ob_start(); ob_start();
DBStructure::printStructure($basePath); DBStructure::printStructure($basePath);
@ -133,7 +143,7 @@ HELP;
$output = 'Unknown command: ' . $this->getArgument(0); $output = 'Unknown command: ' . $this->getArgument(0);
} }
$this->out($output); $this->out(trim($output));
return 0; return 0;
} }

Wyświetl plik

@ -64,6 +64,46 @@ class DBStructure
echo DI::l10n()->t('The database version had been set to %s.', $version); echo DI::l10n()->t('The database version had been set to %s.', $version);
} }
/**
* Drop unused tables
*
* @param boolean $execute
* @return void
*/
public static function dropTables(bool $execute)
{
$old_tables = ['fserver', 'gcign', 'gcontact', 'gcontact-relation', 'gfollower' ,'glink', 'item-delivery-data',
'item_id', 'poll', 'poll_result', 'queue', 'retriever_rule', 'sign', 'spam', 'term'];
$tables = DBA::selectToArray(['INFORMATION_SCHEMA' => 'TABLES'], ['TABLE_NAME'],
['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_TYPE' => 'BASE TABLE']);
if (empty($tables)) {
echo DI::l10n()->t('No unused tables found.');
return;
}
if (!$execute) {
echo DI::l10n()->t('These tables are not used for friendica and will be deleted when you execute "dbstructure drop -e":') . "\n\n";
}
foreach ($tables as $table) {
if (in_array($table['TABLE_NAME'], $old_tables)) {
if ($execute) {
$sql = 'DROP TABLE ' . DBA::quoteIdentifier($table['TABLE_NAME']) . ';';
echo $sql . "\n";
$result = DBA::e($sql);
if (!DBA::isResult($result)) {
self::printUpdateError($sql);
}
} else {
echo $table['TABLE_NAME'] . "\n";
}
}
}
}
/** /**
* Converts all tables from MyISAM/InnoDB Antelope to InnoDB Barracuda * Converts all tables from MyISAM/InnoDB Antelope to InnoDB Barracuda
*/ */

Wyświetl plik

@ -158,7 +158,7 @@ class View
} }
/** /**
* Check if the given table/view is a view * Check if the given table/view is a table
* *
* @param string $table * @param string $table
* @return boolean "true" if it's a table * @return boolean "true" if it's a table