TSP Posted June 29, 2018 Posted June 29, 2018 Hi, I made a script to list up any tables I have in the database that is not listed in any of the installed applications schema.json-files. There are some tables I found that in an earlier upgrade have code to drop the table, but I've also found some tables referred to in old upgrade files, but doesn't seem to be in use by any code. These are some of them: core_archive_log core_archive_restore core_hooks_files core_inline_messages core_like_cache core_login_handlers core_rss_imported core_sys_login core_sys_settings_titles Any particular reason these are still part of upgrade scripts for IPS 4 (where the tables are created), but they have never actually been removed in any version after this, even though they are not in use by any code? At least it doesn't seem like it. Some of these tables that are actually in use?
bfarber Posted June 29, 2018 Posted June 29, 2018 Thanks, I'll take a look at cleaning up those tables in a future update.
TSP Posted June 29, 2018 Author Posted June 29, 2018 15 minutes ago, bfarber said: Thanks, I'll take a look at cleaning up those tables in a future update. Sounds good. Here is the script I made. If you would like to run it on some installations you have access to and see if you find something else. <?php require_once(__DIR__ . '/../www/init.php'); $apps = \IPS\Application::applications(); $installedAppTables = []; foreach ($apps as $app) { foreach( json_decode( file_get_contents( \IPS\ROOT_PATH . "/applications/{$app->directory}/data/schema.json" ), TRUE ) as $tableName => $tableDefinition ) { $installedAppTables[] = \IPS\Db::i()->prefix . $tableName; } } if (\IPS\Db::i()->checkForTable('cms_databases')) { // ibf_cms_custom_database_1 $customDatabases = \IPS\Db::i()->select('database_id', 'cms_databases'); foreach ($customDatabases as $databaseId) { $installedAppTables[] = \IPS\Db::i()->prefix . "cms_custom_database_{$databaseId}"; } } $inDatabaseTables = \IPS\Db::i()->getTables(''); $tablesForManualReview = array_diff($inDatabaseTables, $installedAppTables); echo "Tables for review (may be unused/deprecated tables):\n"; echo implode("\n", $tablesForManualReview); echo "\n\nPlease note: Tables may still be in use. Some of the tables may belong to plugins or applications you no longer have installed.\n"; (You will most likely need to change the require path)
Recommended Posts
Archived
This topic is now archived and is closed to further replies.