Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-30057: Implemented Schema Exporter, Importer and Builder #1

Merged
merged 12 commits into from Mar 6, 2019

Conversation

@alongosz
Copy link
Member

commented Feb 22, 2019

Implements EZP-30057, needed for EZP-29938: PostgreSQL support.

This PR provides following features available via APIs:

  1. \EzSystems\DoctrineSchema\API\SchemaImporter which imports given Yaml source string or Yaml file into \Doctrine\DBAL\Schema object.
  2. \EzSystems\DoctrineSchema\API\SchemaExporter which exports given \Doctrine\DBAL\Schema object to the custom Yaml format.
  3. \EzSystems\DoctrineSchema\API\Builder\SchemaBuilder

SchemaBuilder is event-driven. To hook into the process of building schema, a custom EventSubscriber is required, e.g.

use EzSystems\DoctrineSchema\API\Event\SchemaBuilderEvent;
use EzSystems\DoctrineSchema\API\Event\SchemaBuilderEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class BuildSchemaSubscriber implements EventSubscriberInterface
{
    /**
     * @var string
     */
    private $schemaFilePath;

    public function __construct(string $schemaFilePath)
    {
        $this->schemaFilePath = $schemaFilePath;
    }

    /**
     * Returns an array of events this subscriber wants to listen to.
     *
     * @return string[]
     */
    public static function getSubscribedEvents()
    {
        return [
            SchemaBuilderEvents::BUILD_SCHEMA => ['onBuildSchema', 200],
        ];
    }

    /**
     * @param \EzSystems\DoctrineSchema\API\Builder\SchemaBuilderEvent $event
     */
    public function onBuildSchema(SchemaBuilderEvent $event)
    {
        $event
            ->getSchemaBuilder()
            ->importSchemaFromFile($this->schemaFilePath);
    }
}

Schema provided in this way can be imported into Schema object by e.g.:

    public function __construct(SchemaBuilder $schemaBuilder)
    {
        $this->schemaBuilder = $schemaBuilder;
    }

    public function importSchema()
    {
        $schema = $this->schemaBuilder->buildSchema();
        // ...
    }

All the described services are autowired, so injecting them into custom Symfony services is quite easy.

The documentation of the custom Yaml format will be provided shortly.

TODO:

  • Implement Schema Importer
  • Implement Schema Builder
  • Provide more detailed description for exposed APIs

@alongosz alongosz changed the title [WiP] EZP-30057: Implemented Schema Exporter/Importer EZP-30057: Implemented Schema Exporter/Importer Feb 22, 2019

@alongosz alongosz force-pushed the alongosz:ezp-30057-schema-export-import branch from 901ea34 to ee45803 Feb 22, 2019

@alongosz alongosz force-pushed the alongosz:ezp-30057-schema-export-import branch from ee45803 to 55c47d2 Feb 26, 2019

@alongosz alongosz changed the title EZP-30057: Implemented Schema Exporter/Importer EZP-30057: Implemented Schema Exporter, Importer and Builder Mar 4, 2019

@alongosz alongosz force-pushed the alongosz:ezp-30057-schema-export-import branch from dae47ce to 51c7c0b Mar 4, 2019

@alongosz alongosz marked this pull request as ready for review Mar 4, 2019

@alongosz alongosz force-pushed the alongosz:ezp-30057-schema-export-import branch from 51c7c0b to 997f91b Mar 4, 2019

@alongosz alongosz force-pushed the alongosz:ezp-30057-schema-export-import branch from 997f91b to 9ffa4d8 Mar 5, 2019

Show resolved Hide resolved src/lib/Database/DbPlatformFactory.php Outdated

@alongosz alongosz referenced this pull request Mar 5, 2019

Merged

EZP-29938: Modified CleanInstaller to use SchemaBuilder #2552

9 of 9 tasks complete
Show resolved Hide resolved src/lib/API/Builder/SchemaBuilder.php Outdated
Show resolved Hide resolved src/lib/API/Event/SchemaBuilderEvent.php
Show resolved Hide resolved src/lib/Database/DbPlatform/PostgreSqlDbPlatform.php Outdated
Show resolved Hide resolved src/lib/Database/DbPlatform/SqliteDbPlatform.php Outdated
Show resolved Hide resolved src/lib/Database/DbPlatform/SqliteDbPlatform.php Outdated

@alongosz alongosz force-pushed the alongosz:ezp-30057-schema-export-import branch from 17a52fd to 609f3df Mar 5, 2019

@mnocon

mnocon approved these changes Mar 6, 2019

Copy link
Member

left a comment

Tested together with: ezsystems/ezplatform#365 , look good 👍

@alongosz alongosz merged commit 7ee37ec into ezsystems:master Mar 6, 2019

@alongosz alongosz deleted the alongosz:ezp-30057-schema-export-import branch Mar 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.