diff --git a/migrations/Version20251126132140.php b/migrations/Version20251126132140.php index 98d1d08..e95206b 100644 --- a/migrations/Version20251126132140.php +++ b/migrations/Version20251126132140.php @@ -7,27 +7,28 @@ namespace DoctrineMigrations; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; -/** - * Auto-generated Migration: Please modify to your needs! - */ final class Version20251126132140 extends AbstractMigration { public function getDescription(): string { - return ''; + return 'Adds author_id column to the project_update table'; } public function up(Schema $schema): void { - // this up() migration is auto-generated, please modify it to your needs $this->addSql('ALTER TABLE project_update ADD author_id INT DEFAULT NULL'); $this->addSql('ALTER TABLE project_update ADD CONSTRAINT FK_8F81DE32F675F31B FOREIGN KEY (author_id) REFERENCES user (id)'); $this->addSql('CREATE INDEX IDX_8F81DE32F675F31B ON project_update (author_id)'); + + $this->addSql('UPDATE project_update pu + JOIN project p ON p.id = pu.project_id + SET pu.author_id = p.owner_id + WHERE pu.body != "" + '); } public function down(Schema $schema): void { - // this down() migration is auto-generated, please modify it to your needs $this->addSql('ALTER TABLE project_update DROP FOREIGN KEY FK_8F81DE32F675F31B'); $this->addSql('DROP INDEX IDX_8F81DE32F675F31B ON project_update'); $this->addSql('ALTER TABLE project_update DROP author_id');