CitiesMigration   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 13 1
A check() 0 7 2
A down() 0 4 1
1
<?php
2
3
4
namespace agoalofalife\database\migrations;
5
use agoalofalife\Contracts\Checker;
6
use agoalofalife\Contracts\ContractMigration;
7
use \Illuminate\Database\Capsule\Manager as Capsule;
8
9
class CitiesMigration implements ContractMigration, Checker
10
{
11
    public function execute()
12
    {
13
        Capsule::schema()->create('cities', function ($table) {
14
            $table->increments('id');
15
            $table->integer('region_id')->unsigned()->index()->nullable();
16
            $table->foreign('region_id')->references('id')->on('regions')->onDelete('cascade');
17
            $table->string('title', 100);
18
            $table->string('area', 100);
19
            $table->text('description')->nullable();
20
            $table->string('code')->nullable()->comments('unique value');
21
            $table->timestamps();
22
        });
23
    }
24
25
    public function check(callable $callback)
26
    {
27
        if ( Capsule::schema()->hasTable('cities') === false )
28
        {
29
            call_user_func($callback, $this);
30
        }
31
    }
32
33
    /**
34
     * Reverse the migrations.
35
     *
36
     * @return void
37
     */
38
    public function down()
39
    {
40
        Capsule::schema()->dropIfExists('cities');
41
    }
42
}