function getDiff() { $diffSequence = []; // Tables $tableData = new TableData($this->manager); $sourceTables = $this->manager->getTables('source'); $targetTables = $this->manager->getTables('target'); $commonTables = array_intersect($sourceTables, $targetTables); foreach ($commonTables as $table) { try { $diffs = $tableData->getDiff($table); $diffSequence = array_merge($diffSequence, $diffs); } catch (DataException $e) { Logger::error($e->getMessage()); } } $addedTables = array_diff($sourceTables, $targetTables); foreach ($addedTables as $table) { $diffs = $tableData->getNewData($table); $diffSequence = array_merge($diffSequence, $diffs); } $deletedTables = array_diff($targetTables, $sourceTables); foreach ($deletedTables as $table) { $diffs = $tableData->getOldData($table); $diffSequence = array_merge($diffSequence, $diffs); } return $diffSequence; }
public function run() { // Increase memory limit ini_set('memory_limit', '512M'); try { // Params $paramsFactory = new ParamsFactory(); $params = $paramsFactory->get(); // Diff $diffCalculator = new DiffCalculator(); $diff = $diffCalculator->getDiff($params); // Empty diff if (empty($diff['schema']) && empty($diff['data'])) { Logger::info("Identical resources"); } else { // SQL $sqlGenerator = new SQLGenerator($diff); $up = ''; $down = ''; if ($params->include !== 'down') { $up = $sqlGenerator->getUp(); } if ($params->include !== 'up') { $down = $sqlGenerator->getDown(); } // Generate $templater = new Templater($params, $up, $down); $templater->output(); } Logger::success("Completed"); } catch (\Exception $e) { if ($e instanceof BaseException) { Logger::error($e->getMessage(), true); } else { Logger::error("Unexpected error: "); throw $e; } } }