-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] [Doctrine] Cannot generate migration, if no entity nor mapping infos available #39928
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
Comments
If I look at the stack trace I can't see any "Symfony-Doctrine" related code:
So I think the |
I found 2 ways to fix this "There is no active transaction" error: Solution 1: remove the final <?php
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20210121205631 extends AbstractMigration
{
public function up(Schema $schema) : void
{
$this->addSql('CREATE TABLE messenger_messages (id BIGSERIAL NOT NULL, body TEXT NOT NULL, headers TEXT NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, available_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, delivered_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_75EA56E0FB7336F0 ON messenger_messages (queue_name)');
$this->addSql('CREATE INDEX IDX_75EA56E0E3BD61CE ON messenger_messages (available_at)');
$this->addSql('CREATE INDEX IDX_75EA56E016BA31DB ON messenger_messages (delivered_at)');
$this->addSql('BEGIN;');
$this->addSql('LOCK TABLE messenger_messages;');
$this->addSql('CREATE OR REPLACE FUNCTION notify_messenger_messages() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify(\'messenger_messages\', NEW.queue_name::text);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;');
$this->addSql('DROP TRIGGER IF EXISTS notify_trigger ON messenger_messages;');
$this->addSql('CREATE TRIGGER notify_trigger AFTER INSERT ON messenger_messages FOR EACH ROW EXECUTE PROCEDURE notify_messenger_messages();');
- $this->addSql('COMMIT;');
}
public function down(Schema $schema) : void
{
$this->addSql('CREATE SCHEMA public');
$this->addSql('DROP TABLE messenger_messages');
}
} Solution 2: start a new transaction by adding <?php
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20210121205631 extends AbstractMigration
{
public function up(Schema $schema) : void
{
$this->addSql('CREATE TABLE messenger_messages (id BIGSERIAL NOT NULL, body TEXT NOT NULL, headers TEXT NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, available_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, delivered_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_75EA56E0FB7336F0 ON messenger_messages (queue_name)');
$this->addSql('CREATE INDEX IDX_75EA56E0E3BD61CE ON messenger_messages (available_at)');
$this->addSql('CREATE INDEX IDX_75EA56E016BA31DB ON messenger_messages (delivered_at)');
$this->addSql('BEGIN;');
$this->addSql('LOCK TABLE messenger_messages;');
$this->addSql('CREATE OR REPLACE FUNCTION notify_messenger_messages() RETURNS TRIGGER AS $$
BEGIN
PERFORM pg_notify(\'messenger_messages\', NEW.queue_name::text);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;');
$this->addSql('DROP TRIGGER IF EXISTS notify_trigger ON messenger_messages;');
$this->addSql('CREATE TRIGGER notify_trigger AFTER INSERT ON messenger_messages FOR EACH ROW EXECUTE PROCEDURE notify_messenger_messages();');
$this->addSql('COMMIT;');
+ $this->addSql('BEGIN;');
}
public function down(Schema $schema) : void
{
$this->addSql('CREATE SCHEMA public');
$this->addSql('DROP TABLE messenger_messages');
}
} |
inserting a transaction inside the generated migration looks weird to me, as doctrine/migrations already manages a transaction (which might be the issue here) |
cc @weaverryan |
@OskarStark See #40055 for a fix. |
…pot) This PR was merged into the 5.2 branch. Discussion ---------- [Messenger] Fix Doctrine setup when using a migration | Q | A | ------------- | --- | Branch? | 5.2 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #39928 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | n/a #38136 fixed running `messenger:setup-transports` (issue reported in #37179), but it breaks usage with `make:migration` (reported in #39928) as code is already executed in a transaction. This PR fixes both use cases. Commits ------- 42eeb44 [Messenger] Fix Doctrine setup when using a migration
#40055 introduce regression (which had already been repaired in #38136):
|
The problem for me here is generating a migration for this table, there is no need for it. With the last fix, my app work it. https://github.com/symfony/symfony/pull/38136/files |
@GuigZ- Branches are merged up regularly. So fixes in |
Symfony version(s) affected: 5.1.10
PHP version:
Installed packages:
Description

I have a new project and required
symfony/doctrine-messenger
package. Afterwards I want to setup the migration viamake:migration
. The result is an error:The reason is, that I don't have any entites yet, so no mapping info available.
I created a new

Test
entity for testing purpose and run the command again... it works 🎉The result:
How to reproduce
I created a reproducer: https://github.com/OskarStark/reproducer-doctrine-messenger
Check the README 👀
Possible Solution
❓
Additional context
It works as long you have any mapping info available .... 🤔
EDIT
I also tried to add
auto_setup=false
to the DSN, same result...The text was updated successfully, but these errors were encountered: