123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- declare(strict_types=1);
- namespace DoctrineMigrations;
- use Doctrine\DBAL\Schema\Schema;
- use Doctrine\Migrations\AbstractMigration;
- /**
- * Auto-generated Migration: Please modify to your needs!
- */
- final class Version20230419104506 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->addSql('ALTER TABLE media_video ADD film_id INT NOT NULL');
- foreach($this->connection->fetchAllAssociative('SELECT id, media_video_id FROM film WHERE media_video_id IS NOT NULL') as $film) {
- $this->addSql('UPDATE media_video SET film_id = :idFilm WHERE id = :mediaVideoIdFilm', [
- 'idFilm' => $film['id'],
- 'mediaVideoIdFilm' => $film['media_video_id']
- ]);
- }
- $this->addSql('DELETE FROM media_video WHERE (film_id = 0)');
- $this->addSql('ALTER TABLE media_video ADD CONSTRAINT FK_63DE1E9D567F5183 FOREIGN KEY (film_id) REFERENCES film (id)');
- $this->addSql('CREATE INDEX IDX_63DE1E9D567F5183 ON media_video (film_id)');
- }
- public function down(Schema $schema): void
- {
- // this down() migration is auto-generated, please modify it to your needs
- $this->addSql('ALTER TABLE media_video DROP FOREIGN KEY FK_63DE1E9D567F5183');
- $this->addSql('DROP INDEX IDX_63DE1E9D567F5183 ON media_video');
- $this->addSql('ALTER TABLE media_video DROP film_id');
- }
- }
|