Immobilien & User hinzugefügt
This commit is contained in:
31
migrations/Version20251108172941.php
Normal file
31
migrations/Version20251108172941.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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 Version20251108172941 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('CREATE TABLE immobilien (id INT AUTO_INCREMENT NOT NULL, adresse VARCHAR(255) NOT NULL, preis NUMERIC(10, 2) NOT NULL, flaeche NUMERIC(8, 2) NOT NULL, garage TINYINT(1) NOT NULL, zimmer INT NOT NULL, baujahr INT DEFAULT NULL, typ VARCHAR(255) NOT NULL, beschreibung LONGTEXT DEFAULT NULL, verfuegbar TINYINT(1) NOT NULL, balkon_flaeche INT DEFAULT NULL, keller_flaeche INT DEFAULT NULL, etage INT DEFAULT NULL, heizungstyp VARCHAR(100) DEFAULT NULL, nebenkosten NUMERIC(6, 2) DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('DROP TABLE immobilien');
|
||||
}
|
||||
}
|
||||
42
migrations/Version20251108175151.php
Normal file
42
migrations/Version20251108175151.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user