Passed
Push — master ( 67253e...1a1f73 )
by Arthur
04:53 queued 11s
created

MongoMigration::down()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 0
b 0
f 0
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 17
    public function __construct()
25
    {
26 17
        if (!isset($this->collection) || $this->collection === '') {
27
            throw new InternalErrorException('Collection name must be specified on migration: '.get_called_class());
28
        }
29 17
    }
30
31
    abstract protected function migrate(Blueprint $collection);
32
33
    /**
34
     * Run the migrations.
35
     *
36
     * @return void
37
     */
38 17
    final public function up()
39
    {
40 17
        if (!Schema::connection($this->connection)->hasTable($this->collection)) {
41
            Schema::connection($this->connection)->create($this->collection, function (Blueprint $collection) {
42 17
                $this->migrate($collection);
43 17
            });
44
        }
45 17
    }
46
47
    /**
48
     * Reverse the migrations.
49
     *
50
     * @return void
51
     */
52 17
    final public function down()
53
    {
54 17
        if (Schema::connection($this->connection)->hasTable($this->collection)) {
55 17
            Schema::connection($this->connection)->drop($this->collection);
56
        }
57 17
    }
58
}
59