Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #17986 > unrolled thread
| Started by | Marek S <precz@spamowi.com> |
|---|---|
| First post | 2019-06-12 20:09 +0200 |
| Last post | 2019-06-17 00:18 +0200 |
| Articles | 10 — 2 participants |
Back to article view | Back to comp.lang.php
Symfony 4 - how to get to the documentation of setting up event subscribers? Marek S <precz@spamowi.com> - 2019-06-12 20:09 +0200
Re: Symfony 4 - how to get to the documentation of setting up event subscribers? Arno Welzel <usenet@arnowelzel.de> - 2019-06-13 14:50 +0200
Re: Symfony 4 - how to get to the documentation of setting up event subscribers? Marek S <precz@spamowi.com> - 2019-06-13 21:13 +0200
Re: Symfony 4 - how to get to the documentation of setting up event subscribers? Arno Welzel <usenet@arnowelzel.de> - 2019-06-14 13:16 +0200
Re: Symfony 4 - how to get to the documentation of setting up event subscribers? Marek S <precz@spamowi.com> - 2019-06-14 20:30 +0200
Re: Symfony 4 - how to get to the documentation of setting up event subscribers? Arno Welzel <usenet@arnowelzel.de> - 2019-06-15 18:00 +0200
Re: Symfony 4 - how to get to the documentation of setting up event subscribers? Marek S <precz@spamowi.com> - 2019-06-15 22:57 +0200
Re: Symfony 4 - how to get to the documentation of setting up event subscribers? Arno Welzel <usenet@arnowelzel.de> - 2019-06-16 09:31 +0200
Re: Symfony 4 - how to get to the documentation of setting up event subscribers? Marek S <precz@spamowi.com> - 2019-06-16 14:29 +0200
Re: Symfony 4 - how to get to the documentation of setting up event subscribers? Arno Welzel <usenet@arnowelzel.de> - 2019-06-17 00:18 +0200
| From | Marek S <precz@spamowi.com> |
|---|---|
| Date | 2019-06-12 20:09 +0200 |
| Subject | Symfony 4 - how to get to the documentation of setting up event subscribers? |
| Message-ID | <qdrf5n$j7j$1@node2.news.atman.pl> |
Hi all,
I'm new in Symfony framework. I'm struggling now with Migrations event
subscriber. I can't find any documentation explaining how to configure
services. For this particular example I'm doing something like this:
//services.yaml
App\EventSubscribers\MigrationBugEvSubscriber:
tags:
- { name: ????, ????? }
Going through the Google, I tried to figure out how to get information
about tag content: name of the Doctrine Migrations Bundle events and all
other parameters. Official documentation says nothing:
https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html
https://www.doctrine-project.org/projects/doctrine-migrations/en/2.1/reference/events.html
In the future I will use much more bundles with its own events. Could
you explain how to generally make the events available and how to find
documentation?
...or maybe configuring events support via services.yaml is obsolete?
--
Regards,
Marek
[toc] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-06-13 14:50 +0200 |
| Message-ID | <gmev4hFi9soU1@mid.individual.net> |
| In reply to | #17986 |
On 12.06.19 20:09, Marek S wrote:
> Hi all,
>
> I'm new in Symfony framework. I'm struggling now with Migrations event
> subscriber. I can't find any documentation explaining how to configure
> services. For this particular example I'm doing something like this:
>
> //services.yaml
>
> App\EventSubscribers\MigrationBugEvSubscriber:
> tags:
> - { name: ????, ????? }
Migrations are a part of Doctrine and not Symfony:
<https://www.doctrine-project.org/projects/doctrine-migrations/en/2.1/reference/events.html#migrations-events>
--
Arno Welzel
https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Marek S <precz@spamowi.com> |
|---|---|
| Date | 2019-06-13 21:13 +0200 |
| Message-ID | <qdu78n$37q$1@node2.news.atman.pl> |
| In reply to | #17989 |
W dniu 2019-06-13 o 14:50, Arno Welzel pisze: Hi, > Migrations are a part of Doctrine and not Symfony: > > <https://www.doctrine-project.org/projects/doctrine-migrations/en/2.1/reference/events.html#migrations-events> > Yes, I know. But on the other hand, event subscribers are supported by Symfony: https://symfony.com/doc/current/event_dispatcher.html#creating-an-event-subscriber Also Symfony suggest, that Doctrine is a kind of part of the Symfony: https://symfony.com/doc/current/reference/dic_tags.html "doctrine.event_listener" "doctrine.event_subscriber" It can be deduced that Doctrine's event subscribers are supported somehow. Also I found in the internet that it is possible to catch such events. https://github.com/doctrine/dbal/issues/1110 The reason why ask general question is particular problem. There is a serious bug in Doctrine reported in 2015 and still not solved. The people wrote their own patch but this is workaround but not solution. Patches will be removed after composer's update operations. They suggest to use Symfonys's event subscriber to catch migration events ...or somehow catch postGenerateSchema. Problem seems to be unsolvable for beginners in Symfony. -- Pozdrawiam, Marek
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-06-14 13:16 +0200 |
| Message-ID | <gmhe05F45bsU1@mid.individual.net> |
| In reply to | #17990 |
On 13.06.19 21:13, Marek S wrote: [...] > ...or somehow catch postGenerateSchema. > > Problem seems to be unsolvable for beginners in Symfony. Ok - maybe the other way: why do you need to handle migration events? What exactly is the your case which can not be solved using the migration itself? -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Marek S <precz@spamowi.com> |
|---|---|
| Date | 2019-06-14 20:30 +0200 |
| Message-ID | <qe0p50$bqt$1@node2.news.atman.pl> |
| In reply to | #17991 |
W dniu 2019-06-14 o 13:16, Arno Welzel pisze:
>
> Ok - maybe the other way: why do you need to handle migration events?
> What exactly is the your case which can not be solved using the
> migration itself?
Yeah, you are right. Making the question precise, instead of general,
will allow to get answer easier.
Below I attached automatically created migration (first one).
Assumptions to this:
1. The database is a PostgreSQL.
2. Database contains 3 namespaces: public, external, ext.
3. Only public namespace is dedicated to Symfony.
4. Other namespaces contain third party objects, which will be used by
Symfony from time to time. For now, let's keep them not touched.
5. The migrations are created via console (doctrine:migrations:migrate)
Each of exported migrations contain bugs:
$this->addSql('CREATE SCHEMA public');
$this->addSql('CREATE SCHEMA exclude');
$this->addSql('CREATE SCHEMA exc');
Executing such a code will result exception saying that existing schema
can not be created.
My intention is do not fix migration files manually. Instead of this: do
something in events which allows to ignore creating schema(s). Also I
would like to avoid patching bugged (for years) Doctrine's code.
Especially when I'm new in this environment.
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20190609003956 extends AbstractMigration {
public function getDescription(): string {
return '';
}
public function up(Schema $schema): void {
// this up() migration is auto-generated, please modify it to
your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !==
'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE TABLE task (task_id BIGSERIAL NOT NULL,
title VARCHAR(255) NOT NULL, status BOOLEAN DEFAULT \'false\' NOT NULL,
PRIMARY KEY(task_id))');
}
public function down(Schema $schema): void {
// this down() migration is auto-generated, please modify it to
your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !==
'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE SCHEMA public');
$this->addSql('CREATE SCHEMA exclude');
$this->addSql('CREATE SCHEMA exc');
$this->addSql('DROP TABLE task');
}
}
--
Pozdrawiam,
Marek
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-06-15 18:00 +0200 |
| Message-ID | <gmkj15Fp3lrU1@mid.individual.net> |
| In reply to | #17992 |
Marek S:
> W dniu 2019-06-14 o 13:16, Arno Welzel pisze:
>>
>> Ok - maybe the other way: why do you need to handle migration events?
>> What exactly is the your case which can not be solved using the
>> migration itself?
>
> Yeah, you are right. Making the question precise, instead of general,
> will allow to get answer easier.
>
> Below I attached automatically created migration (first one).
> Assumptions to this:
>
> 1. The database is a PostgreSQL.
> 2. Database contains 3 namespaces: public, external, ext.
> 3. Only public namespace is dedicated to Symfony.
> 4. Other namespaces contain third party objects, which will be used by
> Symfony from time to time. For now, let's keep them not touched.
> 5. The migrations are created via console (doctrine:migrations:migrate)
doctrine:migrations:migrate does not *create* a migration but *execute*
them as needed.
If you want to *create* a migration you either use
doctrine:migrations:create to get a new, blank migration you have to
fill with your statements as required or you use
doctrine:migrations:diff to create migration wich contains all the
statements to upgrade the existing database schema to fit your ORM. A
downgrade migration will then also be created.
> Each of exported migrations contain bugs:
>
> $this->addSql('CREATE SCHEMA public');
> $this->addSql('CREATE SCHEMA exclude');
> $this->addSql('CREATE SCHEMA exc');
>
> Executing such a code will result exception saying that existing schema
> can not be created.
And why is the code there at all?
[...]
> public function down(Schema $schema): void {
> // this down() migration is auto-generated, please modify it to
> your needs
See above - "modify it to your needs"!
> $this->abortIf($this->connection->getDatabasePlatform()->getName() !==
> 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
>
> $this->addSql('CREATE SCHEMA public');
> $this->addSql('CREATE SCHEMA exclude');
> $this->addSql('CREATE SCHEMA exc');
> $this->addSql('DROP TABLE task');
Why should a *downgrade* migration create a schema? I would just delete
these statements. It's totally fine to modify migrations if required.
--
Arno Welzel
https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Marek S <precz@spamowi.com> |
|---|---|
| Date | 2019-06-15 22:57 +0200 |
| Message-ID | <qe3m3j$str$1@node2.news.atman.pl> |
| In reply to | #17995 |
W dniu 2019-06-15 o 18:00, Arno Welzel pisze: >> 5. The migrations are created via console (doctrine:migrations:migrate) > > doctrine:migrations:migrate does not *create* a migration but *execute* > them as needed. I meant make:migration > >> Executing such a code will result exception saying that existing schema >> can not be created. > > And why is the code there at all? Good question, which is asked for years. https://github.com/doctrine/dbal/issues/1110 > > Why should a *downgrade* migration create a schema? Only Doctrine's developer knows. > I would just delete > these statements. It's totally fine to modify migrations if required. Ok, I assumed that migrations should not be changed manually. But if it is corrrect approach, then I will follow this way. If they have to be corrected anyway, can I use them to build not supported by Doctrine functionality such as triggers? -- Regards, Marek
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-06-16 09:31 +0200 |
| Message-ID | <gmm9huF5j6vU1@mid.individual.net> |
| In reply to | #17997 |
Marek S: > W dniu 2019-06-15 o 18:00, Arno Welzel pisze: [...] >> I would just delete >> these statements. It's totally fine to modify migrations if required. > > Ok, I assumed that migrations should not be changed manually. But if it > is corrrect approach, then I will follow this way. If they have to be > corrected anyway, can I use them to build not supported by Doctrine > functionality such as triggers? Sure. You can do whatever you need in the migrations. Doctrine will just assist in creating them - but of course you can modify the code for your needs - that's why there is the comment "Auto-generated Migration: Please modify to your needs!". -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Marek S <precz@spamowi.com> |
|---|---|
| Date | 2019-06-16 14:29 +0200 |
| Message-ID | <qe5co3$dsl$1@node2.news.atman.pl> |
| In reply to | #17999 |
W dniu 2019-06-16 o 09:31, Arno Welzel pisze: > Sure. You can do whatever you need in the migrations. Doctrine will just > assist in creating them - but of course you can modify the code for your > needs - that's why there is the comment "Auto-generated Migration: > Please modify to your needs!". Thx Arno. BTW I have a problem with excluding database namespace from generating migrations but I want use that namespace for CRUD operations. Have you got experience with it? Problems looks like unsolvable. -- Pozdrawiam, Marek
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-06-17 00:18 +0200 |
| Message-ID | <gmntgsFggkrU1@mid.individual.net> |
| In reply to | #18001 |
Marek S: > W dniu 2019-06-16 o 09:31, Arno Welzel pisze: > >> Sure. You can do whatever you need in the migrations. Doctrine will just >> assist in creating them - but of course you can modify the code for your >> needs - that's why there is the comment "Auto-generated Migration: >> Please modify to your needs!". > > Thx Arno. > BTW I have a problem with excluding database namespace from generating > migrations but I want use that namespace for CRUD operations. Have you > got experience with it? Problems looks like unsolvable. Sorry, I didn't use Doctrine with PostgreSQL and namespaces yet, so I can't help you with this. -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web