Completed
Push — master ( 616c5a...7fc704 )
by Paweł
18:48 queued 03:45
created

Version20160516131553::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Migrations;
13
14
use Doctrine\DBAL\Migrations\AbstractMigration;
15
use Doctrine\DBAL\Schema\Schema;
16
17
/**
18
 * Auto-generated Migration: Please modify to your needs!
19
 */
20
class Version20160516131553 extends AbstractMigration
21
{
22
    /**
23
     * @param Schema $schema
24
     */
25
    public function up(Schema $schema)
26
    {
27
        // this up() migration is auto-generated, please modify it to your needs
28
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
29
30
        $this->addSql('ALTER TABLE sylius_product ADD code VARCHAR(255) NOT NULL');
31
        $this->addSql('UPDATE sylius_product s,
32
                           (SELECT @n := 0) m
33
                           SET s.`code` = CONCAT("PR", @n := @n + 1)         
34
                      ');
35
        $this->addSql('CREATE UNIQUE INDEX UNIQ_677B9B7477153098 ON sylius_product (code)');
36
    }
37
38
    /**
39
     * @param Schema $schema
40
     */
41
    public function down(Schema $schema)
42
    {
43
        // this down() migration is auto-generated, please modify it to your needs
44
        $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
45
46
        $this->addSql('DROP INDEX UNIQ_677B9B7477153098 ON sylius_product');
47
        $this->addSql('ALTER TABLE sylius_product DROP code');
48
    }
49
}
50