Skip to content

Commit

Permalink
Merge pull request #16 from mad-coders/migrations
Browse files Browse the repository at this point in the history
Add Doctrine migrations
  • Loading branch information
bigboss86 authored Oct 13, 2021
2 parents 757e4c9 + 1bf6251 commit e38d560
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 0 additions & 1 deletion doc/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ odiseo_sylius_report_plugin_admin:
5. Finish the installation updating the database schema and installing assets
```
php bin/console doctrine:schema:update --force
php bin/console sylius:theme:assets:install
php bin/console cache:clear
```
26 changes: 25 additions & 1 deletion src/DependencyInjection/OdiseoSyliusReportExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
namespace Odiseo\SyliusReportPlugin\DependencyInjection;

use Exception;
use Sylius\Bundle\CoreBundle\DependencyInjection\PrependDoctrineMigrationsTrait;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Reference;

/**
* @author Diego D'amico <diego@odiseo.com.ar>
*/
final class OdiseoSyliusReportExtension extends AbstractResourceExtension
final class OdiseoSyliusReportExtension extends AbstractResourceExtension implements PrependExtensionInterface
{
use PrependDoctrineMigrationsTrait;

/**
* {@inheritdoc}
* @throws Exception
Expand Down Expand Up @@ -43,4 +47,24 @@ public function load(array $config, ContainerBuilder $container): void
->addArgument($config['data_fetcher_configuration_template'])
;
}

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

protected function getMigrationsNamespace(): string
{
return 'Odiseo\SyliusReportPlugin\Migrations';
}

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

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

declare(strict_types=1);

namespace Odiseo\SyliusReportPlugin\Migrations;

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

final class Version20211013183052 extends AbstractMigration
{
public function getDescription(): string
{
return 'Odiseo SyliusReportPlugin';
}

public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE IF NOT EXISTS odiseo_report (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) DEFAULT NULL, code VARCHAR(255) NOT NULL, renderer VARCHAR(255) NOT NULL, renderer_configuration LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\', data_fetcher VARCHAR(255) NOT NULL, data_fetcher_configuration LONGTEXT NOT NULL COMMENT \'(DC2Type:array)\', created_at DATETIME NOT NULL, updated_at DATETIME DEFAULT NULL, UNIQUE INDEX UNIQ_840BB13D77153098 (code), PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE `UTF8_unicode_ci` ENGINE = InnoDB');
}

public function down(Schema $schema): void
{
$this->addSql('DROP TABLE odiseo_report');
}
}

0 comments on commit e38d560

Please sign in to comment.