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

Version20160303110805::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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