Skip to content

Commit

Permalink
FIX Handle missing tables in postgres on flush
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jul 6, 2022
1 parent 608c8d8 commit 78749eb
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function index(HTTPRequest $request)
Versioned::set_stage($stage);
}
}

// Check for a possible CORS preflight request and handle if necessary
// Refer issue 66: https://github.com/silverstripe/silverstripe-graphql/issues/66
if ($request->httpMethod() === 'OPTIONS') {
Expand Down Expand Up @@ -524,13 +524,9 @@ public static function flush()
}
} catch (DatabaseException $e) {
// Allow failures on table doesn't exist or no database selected as we're flushing in first DB build
$messageByLine = explode(PHP_EOL, $e->getMessage());

// Get the last line
$last = array_pop($messageByLine);

if (strpos($last, 'No database selected') === false
&& !preg_match('/\s*(table|relation) .* does(n\'t| not) exist/i', $last)
$message = $e->getMessage();
if (strpos($message, 'No database selected') === false
&& !preg_match('/\s*(table|relation) .* does(n\'t| not) exist/i', $message)
) {
throw $e;
}
Expand Down

0 comments on commit 78749eb

Please sign in to comment.