Completed
Push — master ( 0891d0...500833 )
by Paweł
48:22 queued 28:23
created

Version20170109143010::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace Sylius\Migrations;
4
5
use Doctrine\DBAL\Migrations\AbstractMigration;
6
use Doctrine\DBAL\Schema\Schema;
7
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
10
/**
11
 * @author Grzegorz Sadowski <[email protected]>
12
 */
13
class Version20170109143010 extends AbstractMigration implements ContainerAwareInterface
14
{
15
    /**
16
     * @var ContainerInterface
17
     */
18
    private $container;
19
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function setContainer(ContainerInterface $container = null)
24
    {
25
        $this->container = $container;
26
    }
27
28
    /**
29
     * @param Schema $schema
30
     */
31
    public function up(Schema $schema)
32
    {
33
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
34
35
        $defaultLocale = $this->container->getParameter('locale');
36
37
        $this->addSql('ALTER TABLE sylius_product_attribute_value ADD locale_code VARCHAR(255) NOT NULL');
38
        $this->addSql('UPDATE sylius_product_attribute_value SET locale_code = "'.$defaultLocale.'"');
39
    }
40
41
    /**
42
     * @param Schema $schema
43
     */
44
    public function down(Schema $schema)
45
    {
46
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
47
48
        $this->addSql('ALTER TABLE sylius_product_attribute_value DROP locale_code');
49
    }
50
}
51