Completed
Push — master ( 8e32ae...77800d )
by Yangsin
100:37 queued 95:24
created

Version20161219135621::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace DoctrineMigrations;
4
5
use Doctrine\DBAL\Migrations\AbstractMigration;
6
use Doctrine\DBAL\Schema\Schema;
7
8
/**
9
 * Auto-generated Migration: Please modify to your needs!
10
 */
11
class Version20161219135621 extends AbstractMigration
12
{
13
    /**
14
     * @param Schema $schema
15
     */
16
    public function up(Schema $schema)
17
    {
18
        // 後続の Version20161108095350.php でインデックスを再作成するため一旦削除する
19
        // 同一マイグレーションファイル内でインデックスの drop/create をしようとするとエラーになるため
20
        $this->dropIndex($schema, 'dtb_customer', 'dtb_customer_email_idx');
21
        $this->dropIndex($schema, 'dtb_order', 'dtb_order_order_email_idx');
22
    }
23
24
    /**
25
     * @param Schema $schema
26
     */
27
    public function down(Schema $schema)
28
    {
29
        // XXX 前回のインデックスサイズを記憶しておくのは難しいため削除のみ
30
        $this->dropIndex($schema, 'dtb_customer', 'dtb_customer_email_idx');
31
        $this->dropIndex($schema, 'dtb_order', 'dtb_order_order_email_idx');
32
    }
33
34
    /**
35
     * @param Schema $schema
36
     * @param string $tableName
37
     * @param string $indexName
38
     */
39 View Code Duplication
    protected function dropIndex(Schema $schema, $tableName, $indexName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
40
    {
41
        if (!$schema->hasTable($tableName)) {
42
            return false;
43
        }
44
        $table = $schema->getTable($tableName);
45
        if ($table->hasIndex($indexName)) {
46
            $table->dropIndex($indexName);
47
            return true;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
48
        }
49
        return false;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
50
    }
51
}
52