Last active
November 9, 2022 07:46
-
-
Save peterjaap/fd0375a55245df7052dd77caf093db9d to your computer and use it in GitHub Desktop.
Quick & dirty script to check for existence of Magento (2) table names in codebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$tables = shell_exec('magerun2 db:query "SHOW TABLES"'); | |
$tables = array_filter(explode(PHP_EOL, $tables), function ($table) { | |
if (empty($table)) return false; | |
if (substr($table, -3) === '_cl') return false; | |
if (substr($table, -8) === '_replica') return false; | |
if (stripos($table, '_flat_') !== false) return false; | |
if (stripos($table, '_fulltext_') !== false) return false; | |
if (stripos($table, 'sequence_') !== false) return false; | |
return true; | |
}); | |
$tables = array_slice($tables, 1); | |
foreach ($tables as $table) { | |
$appCodeResult = (int) trim(shell_exec('find app/code -type f -print0 | xargs -0 grep ' . $table . ' | wc -l')); | |
$vendorResult = (int) trim(shell_exec('find vendor -type f -print0 | xargs -0 grep ' . $table . ' | wc -l')); | |
$results = $appCodeResult + $vendorResult; | |
if ($results === 0) { | |
echo $table . ' was not found in the codebase' . PHP_EOL; | |
echo 'DROP TABLE IF EXISTS ' . $table . ';' . PHP_EOL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment