forked from tempestphp/tempest-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
238 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Database\Migrations; | ||
|
||
use Throwable; | ||
|
||
final readonly class FreshMigrationFailed | ||
{ | ||
public function __construct(public Throwable $throwable) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Database\Migrations; | ||
|
||
final class TableDefinition | ||
{ | ||
public function __construct( | ||
public string $name, | ||
public string $type = 'table', | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Database\Migrations; | ||
|
||
final readonly class TableDropped | ||
{ | ||
public function __construct(public string $name) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Database; | ||
|
||
use Exception; | ||
|
||
final class UnsupportedDialect extends Exception | ||
{ | ||
public function __construct() | ||
{ | ||
parent::__construct('Unsupported dialect'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tempest\Framework\Commands; | ||
|
||
use Tempest\Console\Console; | ||
use Tempest\Console\ConsoleCommand; | ||
use Tempest\Console\ExitCode; | ||
use Tempest\Console\Middleware\CautionMiddleware; | ||
use Tempest\Console\Middleware\ForceMiddleware; | ||
use Tempest\Container\Singleton; | ||
use Tempest\Database\Migrations\FreshMigrationFailed; | ||
use Tempest\Database\Migrations\MigrationManager; | ||
use Tempest\Database\Migrations\TableDropped; | ||
use Tempest\EventBus\EventHandler; | ||
|
||
#[Singleton] | ||
final class MigrateFreshCommand | ||
{ | ||
private int $count = 0; | ||
|
||
public function __construct( | ||
private readonly Console $console, | ||
private readonly MigrationManager $migrationManager, | ||
) { | ||
} | ||
|
||
#[ConsoleCommand( | ||
name: 'migrate:fresh', | ||
description: 'Drop all tables and rerun migrations from scratch', | ||
middleware: [ForceMiddleware::class, CautionMiddleware::class], | ||
)] | ||
public function __invoke(): ExitCode | ||
{ | ||
$this->console->info('Dropping tables…'); | ||
|
||
$this->migrationManager->dropAll(); | ||
|
||
$this->console | ||
->success(sprintf("Dropped %s tables", $this->count)) | ||
->writeln(); | ||
|
||
$this->console->info('Migrate up…'); | ||
|
||
return $this->console->call('migrate:up'); | ||
} | ||
|
||
#[EventHandler] | ||
public function onTableDropped(TableDropped $event): void | ||
{ | ||
$this->console->writeln("- Dropped {$event->name}"); | ||
$this->count += 1; | ||
} | ||
|
||
#[EventHandler] | ||
public function onFreshMigrationFailed(FreshMigrationFailed $event): void | ||
{ | ||
$this->console->error($event->throwable->getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.