From 2bbfa722889c232f634a296a7c1ae8577d901d0b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 9 Jun 2021 13:47:26 +1000 Subject: [PATCH] Console command to check Multi DB --- app/Console/Commands/CheckDb.php | 153 +++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 app/Console/Commands/CheckDb.php diff --git a/app/Console/Commands/CheckDb.php b/app/Console/Commands/CheckDb.php new file mode 100644 index 000000000000..6885c7585ec2 --- /dev/null +++ b/app/Console/Commands/CheckDb.php @@ -0,0 +1,153 @@ +entities as $entity) { + + + $count_db_1 = $entity::on('db-ninja-01')->count(); + $count_db_2 = $entity::on('db-ninja-02')->count(); + + $diff = $count_db_1 - $count_db_2; + + $this->logMessage("{$entity} DB1: {$count_db_1} - DB2: {$count_db_2} - diff = {$diff}"); + + if($diff != 0) + $this->logMessage("{$entity} out of sync!!!!!"); + + } + + } + + private function logMessage($str) + { + $str = date('Y-m-d h:i:s').' '.$str; + $this->info($str); + $this->log .= $str."\n"; + } + +}