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

Draft for an event with all information after schema change was perfomed #11409

Draft
wants to merge 5 commits into
base: 3.2.x
Choose a base branch
from

Conversation

beberlei
Copy link
Member

@beberlei beberlei commented Apr 5, 2024

$eventManager = $this->em->getEventManager();
$eventManager->dispatchEvent(
ToolEvents::postSchemaChanged,
new SchemaChangedEventArgs($this->em, $schema, new Schema(), $createSchemaSql),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for looking into this. so the idea would be that e.g. symfony messsenger could listen to this, inspect the changes and fire its own sql statements against the connection if it sees that something was done which it wants to alter?

is this event also useful when doctrine migrations are used rather than database updated on the fly?

with dbal 3, symfony was adding extra sql in https://github.com/symfony/symfony/blob/73f8713e143c64dc5f045dcdee7d5e893cccfcd8/src/Symfony/Bridge/Doctrine/SchemaListener/MessengerTransportDoctrineSchemaListener.php#L76C1-L76C38 (and that sql afaik can not be represented in the doctrine schema models.
that sql got saved to the migration file, which was quite nice to review it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, something like:

public function onPostSchemaChanged($event)
{
    if (!$this->hasMessengerTable($event)) {
        $event->getEntityManage()->getConnection()->executeStatement($this->getMessengerTableSql());
    }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and how can this be integrated with the doctrine migrations? could the listener also add sql into a migration?

@greg0ire
Copy link
Member

Cc @wmouwen

@beberlei
Copy link
Member Author

beberlei commented Apr 27, 2024

Just to make it clear, I would greenlight this approach, but I need someone else to take over and finish this:

  • getters on the event
  • tests
  • integrate into dropSchema/getDropSchemaSql
  • documentation
  • end to end test: Does this really work when executing multiple times

For now, that test only works with DBAL 3, but hopefully that's only
because of the test mocking system rather than the code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants