diff --git a/src/Dev/AT4xMigrationTask.php b/src/Dev/AT4xMigrationTask.php index 05d4ca7..09169e1 100644 --- a/src/Dev/AT4xMigrationTask.php +++ b/src/Dev/AT4xMigrationTask.php @@ -52,7 +52,17 @@ public function run($request) // Safety net if (!($baseObjectTable && $baseTermTable && $termTable)) { - throw new Exception(sprintf("One of the required db tables (%s, %s, %s) doesn't exist, did you run dev/build with a flush param?", $baseObjectTable, $baseTermTable, $termTable)); + throw new Exception(sprintf("One of the required db tables (%s, %s, %s) doesn't exist, did you run dev/build with the flush param?", $baseObjectTable, $baseTermTable, $termTable)); + } + + // Get row numbers for all models + $termsCount = DB::query(sprintf('SELECT COUNT(1) FROM "%s"', $termTable))->value(); + $baseObjectsCount = DB::query(sprintf('SELECT COUNT(1) FROM "%s"', $baseObjectTable))->value(); + $baseTermsCount = DB::query(sprintf('SELECT COUNT(1) FROM "%s"', $baseTermTable))->value(); + + // Skip migration if all tables have the same number of records + if (($termsCount === $baseObjectsCount) && ($termsCount == $baseTermsCount)) { + return; } $versionedFields = array_keys(Config::inst()->get(Versioned::class, 'db_for_versions_table'));