Skip to content

Commit

Permalink
Merge pull request #36 from delyriand/feature/improve-migration-depen…
Browse files Browse the repository at this point in the history
…dencies

Improve migration dependencies
  • Loading branch information
delyriand authored Mar 29, 2024
2 parents ffd3897 + bcfa7a9 commit 5b63484
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export COMPOSE_PROJECT_NAME=anti-spam
PLUGIN_NAME=sylius-${COMPOSE_PROJECT_NAME}-plugin
COMPOSE=docker-compose
YARN=yarn
DOCTRINE_MIGRATIONS_NAMESPACE=MonsieurBiz\SyliusAntiSpamPlugin\Migrations

###
### DEVELOPMENT
Expand Down Expand Up @@ -142,6 +143,14 @@ test.schema: ## Validate MySQL Schema
test.twig: ## Validate Twig templates
${CONSOLE} lint:twig --no-debug templates/ ../../src/Resources/views/

###
### MIGRATIONS
### ¯¯¯¯¯¯¯¯¯¯

doctrine.migration.diff: ## create a diff migration file for the plugin
${CONSOLE} doctrine:migrations:diff --namespace="${DOCTRINE_MIGRATIONS_NAMESPACE}"
.PHONY: doctrine.migration.diff

###
### SYLIUS
### ¯¯¯¯¯¯
Expand Down

This file was deleted.

28 changes: 27 additions & 1 deletion src/DependencyInjection/MonsieurBizSyliusAntiSpamExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
namespace MonsieurBiz\SyliusAntiSpamPlugin\DependencyInjection;

use MonsieurBiz\SyliusAntiSpamPlugin\Validator\ValidatorInterface;
use Sylius\Bundle\CoreBundle\DependencyInjection\PrependDoctrineMigrationsTrait;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

final class MonsieurBizSyliusAntiSpamExtension extends Extension
final class MonsieurBizSyliusAntiSpamExtension extends Extension implements PrependExtensionInterface
{
use PrependDoctrineMigrationsTrait;

/**
* @inheritdoc
*/
Expand All @@ -47,4 +51,26 @@ public function getAlias(): string
{
return str_replace('monsieur_biz', 'monsieurbiz', parent::getAlias());
}

public function prepend(ContainerBuilder $container): void
{
$this->prependDoctrineMigrations($container);
}

protected function getMigrationsNamespace(): string
{
return 'MonsieurBiz\SyliusAntiSpamPlugin\Migrations';
}

protected function getMigrationsDirectory(): string
{
return '@MonsieurBizSyliusAntiSpamPlugin/Migrations';
}

protected function getNamespacesOfMigrationsExecutedBefore(): array
{
return [
'Sylius\Bundle\CoreBundle\Migrations',
];
}
}
37 changes: 37 additions & 0 deletions src/Migrations/Version20240329131510.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of Monsieur Biz' Anti Spam plugin for Sylius.
*
* (c) Monsieur Biz <sylius@monsieurbiz.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace MonsieurBiz\SyliusAntiSpamPlugin\Migrations;

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

final class Version20240329131510 extends AbstractMigration
{
public function getDescription(): string
{
return 'Change json_array(deprecated) to json type';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE monsieurbiz_anti_spam_quarantine_item CHANGE reason_codes reason_codes JSON NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE monsieurbiz_anti_spam_quarantine_item CHANGE reason_codes reason_codes LONGTEXT NOT NULL COMMENT \'(DC2Type:json_array)\'');
}
}

0 comments on commit 5b63484

Please sign in to comment.