43 lines
1.5 KiB
PHP
43 lines
1.5 KiB
PHP
<?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 Version20251108175151 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
|
|
// First add the column as nullable
|
|
$this->addSql('ALTER TABLE immobilien ADD verwalter_id INT DEFAULT NULL');
|
|
|
|
// Assign all existing immobilien to the first user
|
|
$this->addSql('UPDATE immobilien SET verwalter_id = (SELECT id FROM users ORDER BY id LIMIT 1)');
|
|
|
|
// Now make it NOT NULL and add constraints
|
|
$this->addSql('ALTER TABLE immobilien MODIFY verwalter_id INT NOT NULL');
|
|
$this->addSql('ALTER TABLE immobilien ADD CONSTRAINT FK_2C789D3E5F66D3 FOREIGN KEY (verwalter_id) REFERENCES users (id)');
|
|
$this->addSql('CREATE INDEX IDX_2C789D3E5F66D3 ON immobilien (verwalter_id)');
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
// this down() migration is auto-generated, please modify it to your needs
|
|
$this->addSql('ALTER TABLE immobilien DROP FOREIGN KEY FK_2C789D3E5F66D3');
|
|
$this->addSql('DROP INDEX IDX_2C789D3E5F66D3 ON immobilien');
|
|
$this->addSql('ALTER TABLE immobilien DROP verwalter_id');
|
|
}
|
|
}
|