MongoMigration   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 41
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 5 2
A __construct() 0 4 3
A down() 0 4 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 03.10.18
6
 * Time: 20:57.
7
 */
8
9
namespace Foundation\Abstracts\Migrations;
10
11
use Illuminate\Support\Facades\Schema;
12
use Jenssegers\Mongodb\Schema\Blueprint;
13
use Symfony\Component\CssSelector\Exception\InternalErrorException;
14
15
abstract class MongoMigration extends \Illuminate\Database\Migrations\Migration
16
{
17
    protected $connection = 'mongodb';
18
19
    protected $collection;
20
21
    /**
22
     * MongoMigration constructor.
23
     */
24
    public function __construct()
25
    {
26
        if (! isset($this->collection) || $this->collection === '') {
27
            throw new InternalErrorException('Collection name must be specified on migration: '.get_called_class());
28
        }
29
    }
30
31
    abstract protected function migrate(Blueprint $collection);
32
33
    /**
34
     * Run the migrations.
35
     *
36
     * @return void
37
     */
38
    final public function up()
39
    {
40
        if (! Schema::connection($this->connection)->hasTable($this->collection)) {
41
            Schema::connection($this->connection)->create($this->collection, function (Blueprint $collection) {
42
                $this->migrate($collection);
43
            });
44
        }
45
    }
46
47
    /**
48
     * Reverse the migrations.
49
     *
50
     * @return void
51
     */
52
    final public function down()
53
    {
54
        if (Schema::connection($this->connection)->hasTable($this->collection)) {
55
            Schema::connection($this->connection)->drop($this->collection);
56
        }
57
    }
58
}
59