Skip to content

Commit e80f3df

Browse files
committed
Idempotent migrations
1 parent 5c07f1a commit e80f3df

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

UPGRADE.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Upgrade plugin guide
22

3-
## Upgrade from version 1.x to 2.x
3+
## Upgrade from version v0.x to v1.x
4+
5+
The v2 is now compatible with Sylius 2.x, so you need to update your Sylius version to 2.x before upgrading the plugin. Some changes not listed here may be required, so please refer to the Sylius 2.x upgrade guide for more details.
6+
7+
- The route `@WebgriffeSyliusTableRateShippingPlugin/Resources/config/config.yml` has been renamed to `@WebgriffeSyliusTableRateShippingPlugin/config/config.yaml`.
8+
- The route `@WebgriffeSyliusTableRateShippingPlugin/Resources/config/admin_routing.yml` has been renamed to `@WebgriffeSyliusTableRateShippingPlugin/config/routes/admin.yaml`.
9+
- The route `webgriffe_sylius_table_rate_shipping_plugin_shop` has been removed as it was unnecessary
10+
- The migrations are now stored inside the plugin in `src/Migrations`. These should be idempotent, so if the changes made by these migrations are already present, they will do nothing.
11+
12+
## Upgrade from version v1.x to v2.x
413

514
- The service `app.taxation.italian_tax_calculation_strategy` has been renamed to `webgriffe_sylius_italian_invoiceable_order.strategy.taxation.tax_calculation.italian_tax_calculation_strategy`.
615
- The class `Webgriffe\SyliusItalianInvoiceableOrderPlugin\Model\ItalianTaxCalculationStrategy` has been moved to `Webgriffe\SyliusItalianInvoiceableOrderPlugin\Taxation\ItalianTaxCalculationStrategy`.

src/Migrations/Version20260109151240.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,52 @@ final class Version20260109151240 extends AbstractMigration
1515
#[\Override]
1616
public function up(Schema $schema): void
1717
{
18-
$this->addSql('ALTER TABLE sylius_address ADD billing_recipient_type VARCHAR(255) DEFAULT NULL, ADD tax_code VARCHAR(255) DEFAULT NULL, ADD vat_number VARCHAR(255) DEFAULT NULL, ADD sdi_code VARCHAR(255) DEFAULT NULL, ADD pec_address VARCHAR(255) DEFAULT NULL');
18+
$table = $schema->getTable('sylius_address');
19+
20+
if (!$table->hasColumn('billing_recipient_type')) {
21+
$this->addSql('ALTER TABLE sylius_address ADD billing_recipient_type VARCHAR(255) DEFAULT NULL');
22+
}
23+
24+
if (!$table->hasColumn('tax_code')) {
25+
$this->addSql('ALTER TABLE sylius_address ADD tax_code VARCHAR(255) DEFAULT NULL');
26+
}
27+
28+
if (!$table->hasColumn('vat_number')) {
29+
$this->addSql('ALTER TABLE sylius_address ADD vat_number VARCHAR(255) DEFAULT NULL');
30+
}
31+
32+
if (!$table->hasColumn('sdi_code')) {
33+
$this->addSql('ALTER TABLE sylius_address ADD sdi_code VARCHAR(255) DEFAULT NULL');
34+
}
35+
36+
if (!$table->hasColumn('pec_address')) {
37+
$this->addSql('ALTER TABLE sylius_address ADD pec_address VARCHAR(255) DEFAULT NULL');
38+
}
1939
}
2040

2141
#[\Override]
2242
public function down(Schema $schema): void
2343
{
24-
$this->addSql('ALTER TABLE sylius_address DROP billing_recipient_type, DROP tax_code, DROP vat_number, DROP sdi_code, DROP pec_address');
44+
$table = $schema->getTable('sylius_address');
45+
46+
if ($table->hasColumn('pec_address')) {
47+
$this->addSql('ALTER TABLE sylius_address DROP pec_address');
48+
}
49+
50+
if ($table->hasColumn('sdi_code')) {
51+
$this->addSql('ALTER TABLE sylius_address DROP sdi_code');
52+
}
53+
54+
if ($table->hasColumn('vat_number')) {
55+
$this->addSql('ALTER TABLE sylius_address DROP vat_number');
56+
}
57+
58+
if ($table->hasColumn('tax_code')) {
59+
$this->addSql('ALTER TABLE sylius_address DROP tax_code');
60+
}
61+
62+
if ($table->hasColumn('billing_recipient_type')) {
63+
$this->addSql('ALTER TABLE sylius_address DROP billing_recipient_type');
64+
}
2565
}
2666
}

0 commit comments

Comments
 (0)