feat: add doctrine-fixtures-bundle & phpstan, restructure entity mapping
- Add doctrine/doctrine-fixtures-bundle (^4.3) for database fixtures - Add phpstan/phpstan (^2.0) as dev dependency for static analysis - Register DoctrineFixturesBundle in dev/test environments - Move entity mapping to src/Data/Doctrine/Entity/Saatgut - Update entity prefix to App\Data\Doctrine\Entity\Saatgut - Change entity alias from App to Saatgut
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace App\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20250617184300_create_saatgut_tables extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Erstellt die relationalen Tabellen für den Saatgut-Bestand: kategorie, pflanze, saatgut_bestand.';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// 1. Kategorie-Tabelle
|
||||
$this->addSql(<<<SQL
|
||||
CREATE TABLE kategorie (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(100) NOT NULL UNIQUE,
|
||||
farbe VARCHAR(7) DEFAULT NULL
|
||||
);
|
||||
SQL);
|
||||
|
||||
// 2. Pflanze-Tabelle
|
||||
$this->addSql(<<<SQL
|
||||
CREATE TABLE pflanze (
|
||||
id SERIAL PRIMARY KEY,
|
||||
art_name VARCHAR(200) NOT NULL,
|
||||
sorten_name VARCHAR(200) DEFAULT NULL,
|
||||
kategorie_id INTEGER DEFAULT NULL REFERENCES kategorie(id) ON DELETE SET NULL,
|
||||
beschreibung TEXT DEFAULT NULL
|
||||
);
|
||||
SQL);
|
||||
|
||||
// 3. SaatgutBestand-Tabelle mit Unique Constraint (nutzer_id + pflanze_id)
|
||||
$this->addSql(<<<SQL
|
||||
CREATE TABLE saatgut_bestand (
|
||||
id SERIAL PRIMARY KEY,
|
||||
nutzer_id VARCHAR(255) NOT NULL,
|
||||
pflanze_id INTEGER NOT NULL REFERENCES pflanze(id) ON DELETE CASCADE,
|
||||
menge DOUBLE PRECISION NOT NULL,
|
||||
kaufdatum DATE NOT NULL,
|
||||
ablaufdatum DATE DEFAULT NULL,
|
||||
notizen TEXT DEFAULT NULL,
|
||||
CONSTRAINT unik_nutzer_pflanze UNIQUE (nutzer_id, pflanze_id)
|
||||
);
|
||||
SQL);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP TABLE IF EXISTS saatgut_bestand');
|
||||
$this->addSql('DROP TABLE IF EXISTS pflanze');
|
||||
$this->addSql('DROP TABLE IF EXISTS kategorie');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user