CreateEventStoreTable::down()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Config;
6
use Illuminate\Support\Facades\Schema;
7
8
class CreateEventStoreTable extends Migration
9
{
10
    /**
11
     * @var string
12
     */
13
    private $eventStoreTableName;
14
15
    private $eventStoreConnection;
16
17
    public function __construct()
18
    {
19
        $this->eventStoreTableName = Config::get('broadway.event-store-table', 'event_store');
20
        $this->eventStoreConnection = Config::get('broadway.event-store.connection', 'default');
21
22
        if ($this->eventStoreConnection === 'default') {
23
            $this->eventStoreConnection = null;
24
        }
25
    }
26
27
    public function up()
28
    {
29
        Schema::connection($this->eventStoreConnection)->create($this->eventStoreTableName, function (Blueprint $table) {
30
            $table->increments('id');
31
32
            $table->char('uuid', 36);
33
            $table->integer('playhead')->unsigned();
34
            $table->text('metadata');
35
            $table->text('payload');
36
            $table->string('recorded_on', 32);
37
            $table->text('type');
38
39
            $table->unique(['uuid', 'playhead']);
40
        });
41
    }
42
43
    public function down()
44
    {
45
        Schema::drop($this->eventStoreTableName);
46
    }
47
}
48