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 Version20161219160441 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('CREATE TABLE sylius_product_association_type_translation (id INT AUTO_INCREMENT NOT NULL, translatable_id INT NOT NULL, name VARCHAR(255) DEFAULT NULL, locale VARCHAR(255) NOT NULL, INDEX IDX_4F618E52C2AC5D3 (translatable_id), UNIQUE INDEX sylius_product_association_type_translation_uniq_trans (translatable_id, locale), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'); |
38
|
|
|
$this->addSql('ALTER TABLE sylius_product_association_type_translation ADD CONSTRAINT FK_4F618E52C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES sylius_product_association_type (id) ON DELETE CASCADE'); |
39
|
|
|
$this->addSql('INSERT INTO sylius_product_association_type_translation (translatable_id, name, locale) SELECT id, name, "'.$defaultLocale.'" from sylius_product_association_type WHERE sylius_product_association_type.name IS NOT null'); |
40
|
|
|
$this->addSql('ALTER TABLE sylius_product_association_type DROP name'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param Schema $schema |
45
|
|
|
*/ |
46
|
|
|
public function down(Schema $schema) |
47
|
|
|
{ |
48
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
49
|
|
|
|
50
|
|
|
$defaultLocale = $this->container->getParameter('locale'); |
51
|
|
|
|
52
|
|
|
$this->addSql('ALTER TABLE sylius_product_association_type ADD name VARCHAR(255) NOT NULL COLLATE utf8_unicode_ci'); |
53
|
|
|
$this->addSql('UPDATE sylius_product_association_type SET name = (SELECT name FROM sylius_product_association_type_translation WHERE sylius_product_association_type_translation.translatable_id = sylius_product_association_type.id AND sylius_product_association_type_translation.locale = "'.$defaultLocale.'")'); |
54
|
|
|
$this->addSql('DROP TABLE sylius_product_association_type_translation'); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|