1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sylius\Migrations; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Migrations\AbstractMigration; |
6
|
|
|
use Doctrine\DBAL\Schema\Schema; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Auto-generated Migration: Please modify to your needs! |
10
|
|
|
*/ |
11
|
|
|
class Version20170223071604 extends AbstractMigration |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param Schema $schema |
15
|
|
|
*/ |
16
|
|
|
public function up(Schema $schema) |
17
|
|
|
{ |
18
|
|
|
// this up() migration is auto-generated, please modify it to your needs |
19
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
20
|
|
|
|
21
|
|
|
$this->addSql('ALTER TABLE sylius_channel_pricing ADD channel_code VARCHAR(255) NOT NULL;'); |
22
|
|
|
$this->addSql('UPDATE sylius_channel_pricing, sylius_channel SET sylius_channel_pricing.channel_code = sylius_channel.code WHERE sylius_channel.id = sylius_channel_pricing.channel_id'); |
23
|
|
|
|
24
|
|
|
$this->addSql('ALTER TABLE sylius_channel_pricing DROP FOREIGN KEY FK_7801820C72F5A1AA'); |
25
|
|
|
$this->addSql('DROP INDEX IDX_7801820C72F5A1AA ON sylius_channel_pricing'); |
26
|
|
|
$this->addSql('DROP INDEX product_variant_channel_idx ON sylius_channel_pricing'); |
27
|
|
|
$this->addSql('ALTER TABLE sylius_channel_pricing DROP channel_id'); |
28
|
|
|
$this->addSql('CREATE UNIQUE INDEX product_variant_channel_idx ON sylius_channel_pricing (product_variant_id, channel_code)'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param Schema $schema |
33
|
|
|
*/ |
34
|
|
|
public function down(Schema $schema) |
35
|
|
|
{ |
36
|
|
|
// this down() migration is auto-generated, please modify it to your needs |
37
|
|
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); |
38
|
|
|
|
39
|
|
|
$this->addSql('DROP INDEX product_variant_channel_idx ON sylius_channel_pricing'); |
40
|
|
|
$this->addSql('ALTER TABLE sylius_channel_pricing ADD channel_id INT NOT NULL'); |
41
|
|
|
$this->addSql('UPDATE sylius_channel_pricing, sylius_channel SET sylius_channel_pricing.channel_id = sylius_channel.id WHERE sylius_channel.code = sylius_channel_pricing.channel_code'); |
42
|
|
|
|
43
|
|
|
$this->addSql('ALTER TABLE sylius_channel_pricing DROP channel_code'); |
44
|
|
|
$this->addSql('ALTER TABLE sylius_channel_pricing ADD CONSTRAINT FK_7801820C72F5A1AA FOREIGN KEY (channel_id) REFERENCES sylius_channel (id) ON DELETE CASCADE'); |
45
|
|
|
$this->addSql('CREATE INDEX IDX_7801820C72F5A1AA ON sylius_channel_pricing (channel_id)'); |
46
|
|
|
$this->addSql('CREATE UNIQUE INDEX product_variant_channel_idx ON sylius_channel_pricing (product_variant_id, channel_id)'); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|