|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Sylius package. |
| 5 | + * |
| 6 | + * (c) Sylius Sp. z o.o. |
| 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 | +declare(strict_types=1); |
| 13 | + |
| 14 | + |
| 15 | +namespace Sylius\InvoicingPlugin\Migrations; |
| 16 | + |
| 17 | +use Doctrine\DBAL\ArrayParameterType; |
| 18 | +use Doctrine\DBAL\Schema\Schema; |
| 19 | +use Doctrine\DBAL\Types\Types; |
| 20 | +use Sylius\Bundle\CoreBundle\Doctrine\Migrations\AbstractMigration; |
| 21 | + |
| 22 | +final class Version20180625120743 extends AbstractMigration |
| 23 | +{ |
| 24 | + public function getDescription(): string |
| 25 | + { |
| 26 | + return 'Regenerated Sylius Invoicing migrations from 1.X'; |
| 27 | + } |
| 28 | + |
| 29 | + public function postUp(Schema $schema): void |
| 30 | + { |
| 31 | + $this->cleanMigrationsTable(); |
| 32 | + } |
| 33 | + |
| 34 | + public function up(Schema $schema): void |
| 35 | + { |
| 36 | + if ($schema->hasTable('sylius_invoicing_plugin_invoice')) { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + $this->addSql('CREATE TABLE sylius_invoicing_plugin_billing_data (id INT AUTO_INCREMENT NOT NULL, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, company VARCHAR(255) DEFAULT NULL, street VARCHAR(255) NOT NULL, city VARCHAR(255) NOT NULL, postcode VARCHAR(255) NOT NULL, country_code VARCHAR(255) NOT NULL, province_code VARCHAR(255) DEFAULT NULL, province_name VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE `UTF8_unicode_ci` ENGINE = InnoDB'); |
| 41 | + $this->addSql('CREATE TABLE sylius_invoicing_plugin_invoice (id VARCHAR(255) NOT NULL, billing_data_id INT DEFAULT NULL, shop_billing_data_id INT DEFAULT NULL, channel_id INT DEFAULT NULL, order_id INT DEFAULT NULL, number VARCHAR(255) NOT NULL, issued_at DATETIME NOT NULL, currency_code VARCHAR(3) NOT NULL, locale_code VARCHAR(255) NOT NULL, total INT NOT NULL, payment_state VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_3AA279BF5CDB2AEB (billing_data_id), UNIQUE INDEX UNIQ_3AA279BFB5282EDF (shop_billing_data_id), INDEX IDX_3AA279BF72F5A1AA (channel_id), INDEX IDX_3AA279BF8D9F6D38 (order_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE `UTF8_unicode_ci` ENGINE = InnoDB'); |
| 42 | + $this->addSql('CREATE TABLE sylius_invoicing_plugin_line_item (id INT AUTO_INCREMENT NOT NULL, invoice_id VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, quantity INT NOT NULL, unit_price INT NOT NULL, discounted_unit_net_price INT DEFAULT NULL, subtotal INT NOT NULL, tax_total INT NOT NULL, total INT NOT NULL, variant_code VARCHAR(255) DEFAULT NULL, variant_name VARCHAR(255) DEFAULT NULL, tax_rate VARCHAR(255) DEFAULT NULL, INDEX IDX_C91408292989F1FD (invoice_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE `UTF8_unicode_ci` ENGINE = InnoDB'); |
| 43 | + $this->addSql('CREATE TABLE sylius_invoicing_plugin_sequence (id INT AUTO_INCREMENT NOT NULL, idx INT NOT NULL, version INT DEFAULT 1 NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE `UTF8_unicode_ci` ENGINE = InnoDB'); |
| 44 | + $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, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE `UTF8_unicode_ci` ENGINE = InnoDB'); |
| 45 | + $this->addSql('CREATE TABLE sylius_invoicing_plugin_tax_item (id INT AUTO_INCREMENT NOT NULL, invoice_id VARCHAR(255) NOT NULL, label VARCHAR(255) NOT NULL, amount INT NOT NULL, INDEX IDX_2951C61C2989F1FD (invoice_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE `UTF8_unicode_ci` ENGINE = InnoDB'); |
| 46 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice ADD CONSTRAINT FK_3AA279BF5CDB2AEB FOREIGN KEY (billing_data_id) REFERENCES sylius_invoicing_plugin_billing_data (id)'); |
| 47 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice ADD CONSTRAINT FK_3AA279BFB5282EDF FOREIGN KEY (shop_billing_data_id) REFERENCES sylius_invoicing_plugin_shop_billing_data (id)'); |
| 48 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice ADD CONSTRAINT FK_3AA279BF72F5A1AA FOREIGN KEY (channel_id) REFERENCES sylius_channel (id)'); |
| 49 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice ADD CONSTRAINT FK_3AA279BF8D9F6D38 FOREIGN KEY (order_id) REFERENCES sylius_order (id)'); |
| 50 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_line_item ADD CONSTRAINT FK_C91408292989F1FD FOREIGN KEY (invoice_id) REFERENCES sylius_invoicing_plugin_invoice (id) ON DELETE CASCADE'); |
| 51 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_tax_item ADD CONSTRAINT FK_2951C61C2989F1FD FOREIGN KEY (invoice_id) REFERENCES sylius_invoicing_plugin_invoice (id) ON DELETE CASCADE'); |
| 52 | + } |
| 53 | + |
| 54 | + public function down(Schema $schema): void |
| 55 | + { |
| 56 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice DROP FOREIGN KEY FK_3AA279BF5CDB2AEB'); |
| 57 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice DROP FOREIGN KEY FK_3AA279BFB5282EDF'); |
| 58 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice DROP FOREIGN KEY FK_3AA279BF72F5A1AA'); |
| 59 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_invoice DROP FOREIGN KEY FK_3AA279BF8D9F6D38'); |
| 60 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_line_item DROP FOREIGN KEY FK_C91408292989F1FD'); |
| 61 | + $this->addSql('ALTER TABLE sylius_invoicing_plugin_tax_item DROP FOREIGN KEY FK_2951C61C2989F1FD'); |
| 62 | + $this->addSql('DROP TABLE sylius_invoicing_plugin_billing_data'); |
| 63 | + $this->addSql('DROP TABLE sylius_invoicing_plugin_invoice'); |
| 64 | + $this->addSql('DROP TABLE sylius_invoicing_plugin_line_item'); |
| 65 | + $this->addSql('DROP TABLE sylius_invoicing_plugin_sequence'); |
| 66 | + $this->addSql('DROP TABLE sylius_invoicing_plugin_shop_billing_data'); |
| 67 | + $this->addSql('DROP TABLE sylius_invoicing_plugin_tax_item'); |
| 68 | + } |
| 69 | + |
| 70 | + private function cleanMigrationsTable(): void |
| 71 | + { |
| 72 | + $this->connection->executeStatement('DELETE FROM sylius_migrations WHERE version LIKE :version AND version NOT IN (:current)', [ |
| 73 | + 'version' => 'Sylius\\\\InvoicingPlugin\\\\Migrations\\\\Version%', |
| 74 | + 'current' => [ |
| 75 | + 'Sylius\\InvoicingPlugin\\Migrations\\Version20241121125624', |
| 76 | + self::class, |
| 77 | + ], |
| 78 | + ], [ |
| 79 | + 'version' => Types::STRING, |
| 80 | + 'current' => ArrayParameterType::STRING, |
| 81 | + ]); |
| 82 | + } |
| 83 | +} |
0 commit comments