Completed
Push — master ( 751246...4d4e9b )
by Lucas
10:58
created

Version20160303110805   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 4 1
A up() 0 5 1
A down() 0 5 1
1
<?php
2
/**
3
 * Index migration
4
 */
5
6
namespace Graviton\I18nBundle\Migrations\MongoDB;
7
8
use AntiMattr\MongoDB\Migrations\AbstractMigration;
9
use Doctrine\MongoDB\Database;
10
use MongoDB;
11
use MongoCollection;
12
13
/**
14
 * Migrate domain_1_locale_1_original_1 index
15
 *
16
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
17
 * @license  http://opensource.org/licenses/MIT MIT License
18
 * @link     http://swisscom.ch
19
 */
20
class Version20160303110805 extends AbstractMigration
21
{
22
    /**
23
     * @var string
24
     */
25
    private $collection = 'Translatable';
26
27
    /**
28
     * @var array
29
     */
30
    private $index = ['domain' => 1, 'locale' => 1, 'original' => 1];
31
32
    /**
33
     * @return string
34
     */
35
    public function getDescription()
36
    {
37
        return 'drop the uniqueness of the domain_1_locale_1_original_1 index';
38
    }
39
40
    /**
41
     * recreate index without unique flag
42
     *
43
     * @param Database $db database to migrate
44
     *
45
     * @return void
46
     */
47
    public function up(Database $db)
48
    {
49
        $db->createCollection($this->collection)->deleteIndex($this->index);
50
        $db->createCollection($this->collection)->ensureIndex($this->index);
51
    }
52
53
    /**
54
     * re-add unique flag to index
55
     *
56
     * @param Database $db database to migrate
57
     *
58
     * @return void
59
     */
60
    public function down(Database $db)
61
    {
62
        $db->createCollection($this->collection)->deleteIndex($this->index);
63
        $db->createCollection($this->collection)->ensureIndex($this->index, ['unique' => true]);
64
    }
65
}
66