CreateMetaAttributesTable::up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Sofa\Eloquence\Metable;
4
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Database\Migrations\Migration;
7
8
/**
9
 * @codeCoverageIgnore
10
 */
11
class CreateMetaAttributesTable extends Migration
12
{
13
    /**
14
     * Meta attributes table name.
15
     *
16
     * @todo allow table name customization via config
17
     *
18
     * @var string
19
     */
20
    protected $table = 'meta_attributes';
21
22
    /**
23
     * Run the migrations.
24
     *
25
     * @return void
26
     */
27
    public function up()
28
    {
29
        \Schema::create($this->table, function (Blueprint $table) {
30
            $table->increments('meta_id');
31
            $table->string('meta_key');
32
            $table->longText('meta_value');
33
            $table->string('meta_type')->default('string');
34
            $table->string('meta_group')->nullable();
35
            $table->morphs('metable');
36
37
            $table->index('meta_key');
38
39
            // Laravel doesn't handle index length, so we need raw statement for this one
40
            \Schema::getConnection()->statement(
41
                'create index meta_attributes_index_value on meta_attributes (meta_key, meta_value(20))'
42
            );
43
        });
44
    }
45
46
    /**
47
     * Reverse the migrations.
48
     *
49
     * @return void
50
     */
51
    public function down()
52
    {
53
        \Schema::drop($this->table);
54
    }
55
}
56