1
|
|
|
<?php |
2
|
|
|
namespace SmoothPhp\LaravelAdapter\Console; |
3
|
|
|
|
4
|
|
|
use Illuminate\Console\Command; |
5
|
|
|
use Illuminate\Contracts\Config\Repository; |
6
|
|
|
use Illuminate\Database\Schema\Blueprint; |
7
|
|
|
use Schema; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class BuildLaravelEventStore |
11
|
|
|
* @package SmoothPhp\LaravelAdapter\Console |
12
|
|
|
* @author Simon Bennett <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
final class BuildLaravelEventStore extends Command |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The name and signature of the console command. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $signature = 'smoothphp:buildeventstore {--force=false}'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The console command description. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $description = 'Build the Laravel Event Store'; |
29
|
|
|
|
30
|
|
|
/** @var Repository */ |
31
|
|
|
private $config; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* BuildLaravelEventStore constructor. |
35
|
|
|
* @param Repository $config |
36
|
|
|
*/ |
37
|
|
|
public function __construct(Repository $config) |
38
|
|
|
{ |
39
|
|
|
parent::__construct(); |
40
|
|
|
$this->config = $config; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Execute the console command. |
45
|
|
|
* |
46
|
|
|
* @return mixed |
47
|
|
|
*/ |
48
|
|
|
public function handle() |
49
|
|
|
{ |
50
|
|
|
if ($this->option('force') == 'true' || $this->confirm("Are you sure you want to make a new table '{$this->config->get('cqrses.eventstore_table')}'" |
51
|
|
|
. " on connection '{$this->config->get('cqrses.eventstore_connection')}'" |
52
|
|
|
. " Do you wish to continue?") |
53
|
|
|
) { |
54
|
|
|
return $this->buildEventStoreTable(); |
55
|
|
|
} |
56
|
|
|
$this->line("Stopping"); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Build eventstore table |
61
|
|
|
*/ |
62
|
|
|
protected function buildEventStoreTable() |
63
|
|
|
{ |
64
|
|
|
Schema::connection($this->config->get('cqrses.eventstore_connection')) |
65
|
|
|
->create($this->config->get('cqrses.eventstore_table'), |
66
|
|
|
function (Blueprint $table) { |
67
|
|
|
$table->increments('id'); |
68
|
|
|
$table->string('uuid', 56); |
69
|
|
|
$table->integer('playhead')->unsigned(); |
70
|
|
|
$table->text('metadata'); |
71
|
|
|
$table->text('payload'); |
72
|
|
|
$table->string('recorded_on', 32); |
73
|
|
|
$table->text('type'); |
74
|
|
|
$table->unique(['uuid', 'playhead']); |
75
|
|
|
}); |
76
|
|
|
} |
77
|
|
|
} |