diff --git a/db/migrations/20261119090000_create_speaker_person.php b/db/migrations/20261119090000_create_speaker_person.php new file mode 100644 index 000000000..4789588a9 --- /dev/null +++ b/db/migrations/20261119090000_create_speaker_person.php @@ -0,0 +1,27 @@ +table('afup_speaker_person', ['signed' => false]) + ->addColumn('slug', 'string', ['limit' => 255, 'null' => false]) + ->addColumn('created_at', 'datetime', ['null' => false, 'default' => 'CURRENT_TIMESTAMP']) + ->addIndex('slug', ['unique' => true]) + ->create(); + + $this->table('afup_conferenciers') + ->addColumn('person_id', 'integer', ['null' => true, 'default' => null, 'signed' => false, 'after' => 'user_github']) + ->addForeignKey('person_id', 'afup_speaker_person', 'id', ['delete' => 'SET_NULL', 'update' => 'NO_ACTION']) + ->update(); + } +} diff --git a/tests/integration/AppBundle/Event/Speaker/SpeakerPersonSchemaTest.php b/tests/integration/AppBundle/Event/Speaker/SpeakerPersonSchemaTest.php new file mode 100644 index 000000000..1ea221902 --- /dev/null +++ b/tests/integration/AppBundle/Event/Speaker/SpeakerPersonSchemaTest.php @@ -0,0 +1,47 @@ +get(Connection::class); + + $connection->insert('afup_speaker_person', ['id' => 1, 'slug' => 'helene-schapira']); + $connection->insert('afup_conferenciers', ['conferencier_id' => 10, 'id_forum' => 1, 'prenom' => 'Hélène', 'nom' => 'Schapira', 'email' => 'h@example.com', 'person_id' => 1]); + $connection->insert('afup_conferenciers', ['conferencier_id' => 20, 'id_forum' => 2, 'prenom' => 'Hélène', 'nom' => 'Schapira', 'email' => 'h@example.com']); + + self::assertSame([[10, 1], [20, null]], $this->personIds($connection)); + + $connection->delete('afup_speaker_person', ['id' => 1]); + + self::assertSame([[10, null], [20, null]], $this->personIds($connection), 'supprimer une personne détache ses lignes sans les supprimer'); + } + + public function testSlugIsUnique(): void + { + $connection = self::getContainer()->get(Connection::class); + $connection->insert('afup_speaker_person', ['slug' => 'jean-martin']); + + $this->expectException(UniqueConstraintViolationException::class); + $connection->insert('afup_speaker_person', ['slug' => 'jean-martin']); + } + + /** + * @return list + */ + private function personIds(Connection $connection): array + { + return array_map( + static fn(array $row): array => [(int) $row['conferencier_id'], null !== $row['person_id'] ? (int) $row['person_id'] : null], + $connection->fetchAllAssociative('SELECT conferencier_id, person_id FROM afup_conferenciers ORDER BY conferencier_id'), + ); + } +}