Completed
Push — master ( c9b1f2...7edc4b )
by Gino
02:53 queued 01:13
created

DropDeprecatedPostTagTable::up()   A

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
namespace GinoPane\BlogTaxonomy\Updates;
4
5
use Schema;
6
use GinoPane\BlogTaxonomy\Models\Tag;
7
use October\Rain\Database\Updates\Migration;
8
9
/**
10
 * Class DropDeprecatedPostTagTable
11
 *
12
 * @package GinoPane\BlogTaxonomy\Updates
13
 */
14
class DropDeprecatedPostTagTable extends Migration
15
{
16
    /**
17
     * Execute migrations
18
     */
19
    public function up()
20
    {
21
        Schema::dropIfExists('ginopane_blogtaxonomy_post_tag');
22
    }
23
24
    /**
25
     * Rollback migrations
26
     */
27
    public function down()
28
    {
29
        if (!Schema::hasTable('ginopane_blogtaxonomy_post_tag')) {
30
            Schema::create(
31
                'ginopane_blogtaxonomy_post_tag',
32 View Code Duplication
                static function ($table) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
                    $table->engine = 'InnoDB';
34
35
                    $table->integer('tag_id')->unsigned()->nullable()->default(null);
36
                    $table->integer('post_id')->unsigned()->nullable()->default(null);
37
                    $table->index(['tag_id', 'post_id']);
38
                    $table->foreign('tag_id')->references('id')->on(Tag::TABLE_NAME)->onDelete('cascade');
39
                    $table->foreign('post_id')->references('id')->on('rainlab_blog_posts')->onDelete('cascade');
40
                }
41
            );
42
        }
43
    }
44
}
45