Skip to content

Commit

Permalink
Update duplicated migrations not to execute if the changes already ex…
Browse files Browse the repository at this point in the history
…ists in db
  • Loading branch information
GSadee committed Feb 16, 2021
1 parent 853f9ff commit 5519cf9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 50 deletions.
15 changes: 1 addition & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,10 @@ jobs:
name: Install JS dependencies
run: (cd tests/Application && yarn install)

-
name: Create test application database
run: |
(cd tests/Application && bin/console doctrine:database:create -vvv)
-
name: Exclude duplicated migrations
if: matrix.sylius != '~1.8.0'
run: |
(cd tests/Application && bin/console doctrine:migration:sync-metadata-storage)
(cd tests/Application && bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201130071338' --add)
(cd tests/Application && bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201204071301' --add)
(cd tests/Application && bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201208105207' --add)
-
name: Prepare test application database
run: |
(cd tests/Application && bin/console doctrine:database:create -vvv)
(cd tests/Application && bin/console doctrine:migrations:migrate -n -vvv -q)
-
Expand Down
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,13 @@ It is used by `KnpSnappyBundle` and can be configured according to [their documm

> Remember to allow community recipes with `composer config extra.symfony.allow-contrib true` or during plugin installation process

2. If you install the plugin on Sylius 1.9 or higher, exclude duplicated migrations:

```bash
bin/console doctrine:migration:sync-metadata-storage
bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201130071338' --add
bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201204071301' --add
bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201208105207' --add
```

3. Apply migration to your database:
2. Apply migration to your database:

```bash
bin/console doctrine:migrations:migrate
```

4. Copy Sylius templates overridden in plugin to your templates directory (e.g `templates/bundles/`):
3. Copy Sylius templates overridden in plugin to your templates directory (e.g `templates/bundles/`):

```bash
mkdir -p templates/bundles/SyliusAdminBundle/
Expand Down
9 changes: 0 additions & 9 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@
bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201208105207' --add
```

1. If you upgrade also Sylius to 1.9 version, exclude duplicated migrations:

```bash
bin/console doctrine:migration:sync-metadata-storage
bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201130071338' --add
bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201204071301' --add
bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201208105207' --add
```

1. Add traits that enhance Adjustment and Shipment models from Sylius. These traits are not covered by
the backward compatibility promise and it will be removed after update Sylius to 1.9. It is a duplication of a logic
from Sylius to provide proper adjustments handling.
Expand Down
23 changes: 7 additions & 16 deletions docs/legacy_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
composer require sylius/refund-plugin
```

2. Add plugin class and other required bundles to your `AppKernel`:
1. Add plugin class and other required bundles to your `AppKernel`:

```php
$bundles = [
Expand All @@ -15,20 +15,20 @@
];
```

3. Import configuration:
1. Import configuration:

```yaml
imports:
- { resource: "@SyliusRefundPlugin/Resources/config/app/config.yml" }
```
4. Import routing:
1. Import routing:
````yaml
sylius_refund:
resource: "@SyliusRefundPlugin/Resources/config/routing.yml"
````
5. Configure `KnpSnappyBundle` (if you don't have it configured yet):
1. Configure `KnpSnappyBundle` (if you don't have it configured yet):
````yaml
knp_snappy:
Expand All @@ -38,29 +38,20 @@
options: []
````
6. If you install the plugin on Sylius 1.9 or higher, exclude duplicated migrations:
```bash
bin/console doctrine:migration:sync-metadata-storage
bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201130071338' --add
bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201204071301' --add
bin/console doctrine:migrations:version 'Sylius\RefundPlugin\Migrations\Version20201208105207' --add
```
7. Apply migrations to your database:
1. Apply migrations to your database:
```bash
bin/console doctrine:migrations:migrate
```
8. Copy Sylius templates overridden in plugin to your templates directory (e.g `templates/bundles/`):
1. Copy Sylius templates overridden in plugin to your templates directory (e.g `templates/bundles/`):
```bash
mkdir -p templates/bundles/SyliusAdminBundle/
cp -R vendor/sylius/refund-plugin/src/Resources/views/SyliusAdminBundle/* templates/bundles/SyliusAdminBundle/
```
9. Clear cache:
1. Clear cache:
```bash
bin/console cache:clear
Expand Down
5 changes: 5 additions & 0 deletions src/Migrations/Version20201130071338.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public function getDescription(): string

public function up(Schema $schema): void
{
$adjustmentTable = $schema->getTable('sylius_adjustment');
if ($adjustmentTable->hasColumn('shipment_id')) {
return;
}

$this->addSql('ALTER TABLE sylius_adjustment ADD shipment_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE sylius_adjustment ADD CONSTRAINT FK_ACA6E0F27BE036FC FOREIGN KEY (shipment_id) REFERENCES sylius_shipment (id) ON DELETE CASCADE');
$this->addSql('CREATE INDEX IDX_ACA6E0F27BE036FC ON sylius_adjustment (shipment_id)');
Expand Down
5 changes: 5 additions & 0 deletions src/Migrations/Version20201204071301.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public function getDescription(): string

public function up(Schema $schema): void
{
$adjustmentTable = $schema->getTable('sylius_adjustment');
if ($adjustmentTable->hasColumn('details')) {
return;
}

$this->addSql('ALTER TABLE sylius_adjustment ADD details JSON NOT NULL');
}

Expand Down

0 comments on commit 5519cf9

Please sign in to comment.