Skip to content

Commit

Permalink
64 run migrations on index (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjurstrom authored Sep 8, 2024
1 parent 8675bab commit bcb2d6e
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/Actions/UpdateIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
use BenBjurstrom\Prezet\Models\Document;
use BenBjurstrom\Prezet\Models\Heading;
use BenBjurstrom\Prezet\Models\Tag;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Schema;

class UpdateIndex
{
public static function handle(): void
{

self::runMigrations();
$docs = GetAllFrontmatter::handle();
$docs->each(function (FrontmatterData $doc) {
Expand Down Expand Up @@ -76,19 +75,15 @@ protected static function setTags(Document $d, array $tags): void

protected static function runMigrations(): void
{
try {
Artisan::call('migrate:rollback', [
'--path' => base_path('vendor/benbjurstrom/prezet/database/migrations'),
'--database' => 'prezet',
'--realpath' => true,
'--no-interaction' => true,
]);
} catch (QueryException $e) {
// either file does not exist or
// migrations table does not exist
if (! Schema::connection('prezet')->hasTable('migrations')) {
Schema::connection('prezet')->create('migrations', function ($table) {
$table->increments('id');
$table->string('migration');
$table->integer('batch');
});
}

Artisan::call('migrate', [
Artisan::call('migrate:fresh', [
'--path' => base_path('vendor/benbjurstrom/prezet/database/migrations'),
'--database' => 'prezet',
'--realpath' => true,
Expand Down

0 comments on commit bcb2d6e

Please sign in to comment.