Skip to content

Commit

Permalink
Add migration and Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomanhez committed Oct 21, 2019
1 parent 544cd1c commit 9f7d32d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 4 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### UPGRADE FROM 0.9 TO 0.10.0

1. Removed `InvoicingChannel` and replaced by `Sylius\Component\Core\Model\ChannelInterface`.

2. Replaced `InvoiceShopBillingData` value object by entitie with `InvoiceShopBillingDataInterface` interface.
66 changes: 66 additions & 0 deletions migrations/Version20191016124548.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20191016124548 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('CREATE TABLE sylius_invoicing_plugin_shop_billing_data (id INT AUTO_INCREMENT NOT NULL, company VARCHAR(255) DEFAULT NULL, tax_id VARCHAR(255) DEFAULT NULL, street VARCHAR(255) DEFAULT NULL, city VARCHAR(255) DEFAULT NULL, postcode VARCHAR(255) DEFAULT NULL, country_code VARCHAR(255) DEFAULT NULL, representative VARCHAR(255) DEFAULT NULL, id_invoice VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB');

$this->addSql('CREATE TABLE sylius_invoicing_plugin_embeddable_backup(id INT AUTO_INCREMENT NOT NULL, id_invoice VARCHAR(255) NOT NULL, channel_code VARCHAR(255) NOT NULL, shop_billing_data_company VARCHAR(255) DEFAULT NULL, shop_billing_data_tax_id VARCHAR(255) DEFAULT NULL, shop_billing_data_street VARCHAR(255) DEFAULT NULL, shop_billing_data_city VARCHAR(255) DEFAULT NULL, shop_billing_data_postcode VARCHAR(255) DEFAULT NULL, shop_billing_data_country_code VARCHAR(255) DEFAULT NULL, shop_billing_data_representative VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE UTF8_unicode_ci ENGINE = InnoDB');
$this->addSql('
INSERT INTO sylius_invoicing_plugin_embeddable_backup (id_invoice, channel_code, shop_billing_data_company, shop_billing_data_tax_id, shop_billing_data_street, shop_billing_data_city, shop_billing_data_postcode, shop_billing_data_country_code, shop_billing_data_representative)
SELECT id, channel_code, shop_billing_data_company, shop_billing_data_tax_id, shop_billing_data_street, shop_billing_data_city, shop_billing_data_postcode, shop_billing_data_country_code, shop_billing_data_representative
FROM sylius_invoicing_plugin_invoice
');

$this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice ADD shop_billing_data_id INT DEFAULT NULL, ADD channel_id INT DEFAULT NULL, DROP channel_code, DROP channel_name, DROP shop_billing_data_company, DROP shop_billing_data_tax_id, DROP shop_billing_data_street, DROP shop_billing_data_city, DROP shop_billing_data_postcode, DROP shop_billing_data_country_code, DROP shop_billing_data_representative');
$this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice ADD CONSTRAINT FK_3AA279BFCFE4AA36 FOREIGN KEY (shop_billing_data_id) REFERENCES sylius_invoicing_plugin_shop_billing_data (id)');
$this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice ADD CONSTRAINT FK_3AA279BF72F5A1AA FOREIGN KEY (channel_id) REFERENCES sylius_channel (id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_3AA279BFCFE4AA36 ON sylius_invoicing_plugin_invoice (shop_billing_data_id)');
$this->addSql('CREATE INDEX IDX_3AA279BF72F5A1AA ON sylius_invoicing_plugin_invoice (channel_id)');

$this->addSql('
UPDATE sylius_invoicing_plugin_invoice
INNER JOIN sylius_channel
INNER JOIN sylius_invoicing_plugin_embeddable_backup
SET sylius_invoicing_plugin_invoice.channel_id = sylius_channel.id
WHERE sylius_channel.code = sylius_invoicing_plugin_embeddable_backup.channel_code
AND sylius_invoicing_plugin_invoice.id = sylius_invoicing_plugin_embeddable_backup.id_invoice
');
$this->addSql('
INSERT INTO sylius_invoicing_plugin_shop_billing_data (company, tax_id, street, city, postcode, country_code, representative, id_invoice)
SELECT shop_billing_data_company, shop_billing_data_tax_id, shop_billing_data_street, shop_billing_data_city, shop_billing_data_postcode, shop_billing_data_country_code, shop_billing_data_representative, id_invoice
FROM sylius_invoicing_plugin_embeddable_backup
');
$this->addSql('
UPDATE sylius_invoicing_plugin_invoice
INNER JOIN sylius_invoicing_plugin_shop_billing_data
SET sylius_invoicing_plugin_invoice.shop_billing_data_id = sylius_invoicing_plugin_shop_billing_data.id
WHERE sylius_invoicing_plugin_invoice.id = sylius_invoicing_plugin_shop_billing_data.id_invoice
');
$this->addSql('ALTER TABLE sylius_invoicing_plugin_shop_billing_data DROP COLUMN id_invoice');

$this->addSql('DROP TABLE sylius_invoicing_plugin_embeddable_backup');
}

public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice DROP FOREIGN KEY FK_3AA279BFCFE4AA36');
$this->addSql('DROP TABLE sylius_invoicing_plugin_shop_billing_data');
$this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice DROP FOREIGN KEY FK_3AA279BF72F5A1AA');
$this->addSql('DROP INDEX UNIQ_3AA279BFCFE4AA36 ON sylius_invoicing_plugin_invoice');
$this->addSql('DROP INDEX IDX_3AA279BF72F5A1AA ON sylius_invoicing_plugin_invoice');
$this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice ADD channel_code VARCHAR(255) NOT NULL COLLATE utf8_unicode_ci, ADD channel_name VARCHAR(255) NOT NULL COLLATE utf8_unicode_ci, ADD shop_billing_data_company VARCHAR(255) DEFAULT NULL COLLATE utf8_unicode_ci, ADD shop_billing_data_tax_id VARCHAR(255) DEFAULT NULL COLLATE utf8_unicode_ci, ADD shop_billing_data_street VARCHAR(255) DEFAULT NULL COLLATE utf8_unicode_ci, ADD shop_billing_data_city VARCHAR(255) DEFAULT NULL COLLATE utf8_unicode_ci, ADD shop_billing_data_postcode VARCHAR(255) DEFAULT NULL COLLATE utf8_unicode_ci, ADD shop_billing_data_country_code VARCHAR(255) DEFAULT NULL COLLATE utf8_unicode_ci, ADD shop_billing_data_representative VARCHAR(255) DEFAULT NULL COLLATE utf8_unicode_ci, DROP shop_billing_data_id, DROP channel_id');
}
}
4 changes: 2 additions & 2 deletions src/Resources/config/doctrine/Invoice.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
</one-to-many>

<many-to-one field="channel" target-entity="Sylius\Component\Core\Model\ChannelInterface">
<join-column name="channel_id" referenced-column-name="id" nullable="true" />
<join-column name="channel_id" />
</many-to-one>

<one-to-one field="shopBillingData" target-entity="Sylius\InvoicingPlugin\Entity\InvoiceShopBillingData">
<cascade>
<cascade-all />
</cascade>
<join-column name="shop_billing_data" referenced-column-name="id" />
<join-column name="shop_billing_data_id" referenced-column-name="id" />
</one-to-one>

<indexes>
Expand Down
9 changes: 7 additions & 2 deletions src/Resources/config/doctrine/InvoiceShopBillingData.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<embeddable name="Sylius\InvoicingPlugin\Entity\InvoiceShopBillingData">

<entity name="Sylius\InvoicingPlugin\Entity\InvoiceShopBillingData" table="sylius_invoicing_plugin_shop_billing_data">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>

<field name="company" nullable="true" />
<field name="taxId" column="tax_id" nullable="true" />
<field name="street" nullable="true" />
<field name="city" nullable="true" />
<field name="postcode" nullable="true" />
<field name="countryCode" column="country_code" nullable="true" />
<field name="representative" column="representative" nullable="true" />
</embeddable>
</entity>
</doctrine-mapping>

0 comments on commit 9f7d32d

Please sign in to comment.