Merge pull request #372 from wrongecho/diff

Show diff between current DB structure and the latest DB structure
This commit is contained in:
Johnny
2022-02-22 18:20:00 -05:00
committed by GitHub

View File

@@ -55,8 +55,33 @@ $git_log = shell_exec("git log master..origin/master --pretty=format:'<tr><td>%h
</table> </table>
<?php <?php
} }
// Display a diff between the current DB structure and the latest DB structure, *NIX only
if((strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')){
// Get DB structure as it is
exec("mysqldump --user=$dbusername --password=$dbpassword --skip-extended-insert -d --no-data $database | sed 's/ AUTO_INCREMENT=[0-9]*//g' | egrep -v 'MariaDB dump|Host:|Server version|Dump completed' > /tmp/current-structure.sql");
// Get the new structure from db.sql
exec("egrep -v 'MariaDB dump|Host:|Server version|Dump completed' db.sql > /tmp/new-structure.sql");
// Compare
exec("diff /tmp/current-structure.sql /tmp/new-structure.sql > /tmp/diff.txt");
$diff = file_get_contents("/tmp/diff.txt");
// Display, if there is a difference
if(!empty($diff)){
echo "<br><br><h2>Diff between your database structure and db.sql</h2>";
echo "<div style=\"white-space: pre-line\"> $diff </div>";
}
}
?> ?>
</div> </div>
</div> </div>
<?php include("footer.php"); <?php
include("footer.php");