Skip to content

Commit

Permalink
Fix: #3685 - orphan records in placelocation break upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
fisharebest committed Jan 24, 2021
1 parent 60c799a commit 2939550
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions app/Schema/Migration44.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ public function upgrade(): void
'pl_long' => null,
]);

// Ideally, we would update the parent_id separately,
// Missing/invalid parents? Move them to the top level
DB::table('placelocation AS pl1')
->leftJoin('placelocation AS pl2', 'pl1.pl_parent_id', '=', 'pl2.pl_id')
->whereNull('pl2.pl_id')
->update([
'pl1.pl_parent_id' => 0,
]);

$select = DB::table('placelocation')
->leftJoin('place_location', 'id', '=', 'pl_id')
->whereNull('id')
Expand All @@ -87,13 +94,6 @@ public function upgrade(): void
DB::table('place_location')
->insertUsing(['id', 'parent_id', 'place', 'latitude', 'longitude'], $select);

//DB::table('place_location')
// ->join('placelocation', 'pl_id', '=', 'id')
// ->where('pl_parent_id', '<>', 0)
// ->update([
// 'parent_id' => new Expression('pl_parent_id'),
// ]);

DB::schema()->drop('placelocation');
}

Expand Down

0 comments on commit 2939550

Please sign in to comment.