Version20230419104506.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7. * Auto-generated Migration: Please modify to your needs!
  8. */
  9. final class Version20230419104506 extends AbstractMigration
  10. {
  11. public function getDescription(): string
  12. {
  13. return '';
  14. }
  15. public function up(Schema $schema): void
  16. {
  17. // this up() migration is auto-generated, please modify it to your needs
  18. $this->addSql('ALTER TABLE media_video ADD film_id INT NOT NULL');
  19. foreach($this->connection->fetchAllAssociative('SELECT id, media_video_id FROM film WHERE media_video_id IS NOT NULL') as $film) {
  20. $this->addSql('UPDATE media_video SET film_id = :idFilm WHERE id = :mediaVideoIdFilm', [
  21. 'idFilm' => $film['id'],
  22. 'mediaVideoIdFilm' => $film['media_video_id']
  23. ]);
  24. }
  25. $this->addSql('DELETE FROM media_video WHERE (film_id = 0)');
  26. $this->addSql('ALTER TABLE media_video ADD CONSTRAINT FK_63DE1E9D567F5183 FOREIGN KEY (film_id) REFERENCES film (id)');
  27. $this->addSql('CREATE INDEX IDX_63DE1E9D567F5183 ON media_video (film_id)');
  28. }
  29. public function down(Schema $schema): void
  30. {
  31. // this down() migration is auto-generated, please modify it to your needs
  32. $this->addSql('ALTER TABLE media_video DROP FOREIGN KEY FK_63DE1E9D567F5183');
  33. $this->addSql('DROP INDEX IDX_63DE1E9D567F5183 ON media_video');
  34. $this->addSql('ALTER TABLE media_video DROP film_id');
  35. }
  36. }