Skip to content

Commit

Permalink
Skip migration when all model tables continue same amount of records
Browse files Browse the repository at this point in the history
Please note this is based on a simple assumption using the base tables,
disregarding number of records in _Live and _Versions tables.
  • Loading branch information
michalkleiner committed Mar 15, 2021
1 parent 9b4954b commit 254f447
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Dev/AT4xMigrationTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit 254f447

Please sign in to comment.