what the fuck

This commit is contained in:
boris committed 2026-04-02 13:46:07 +01:00
1 parent c1b1c2f372
commit 72a99a5bcd
69 files changed
+7519 -558

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20260401101500 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add nullable album owner relation (albums.owner_id -> users.id)';
}
public function up(Schema $schema): void
{
if ($this->isSqlite()) {
$this->addSql('ALTER TABLE albums ADD COLUMN owner_id INTEGER DEFAULT NULL');
$this->addSql('CREATE INDEX IF NOT EXISTS IDX_ALBUM_OWNER ON albums (owner_id)');
return;
}
$this->addSql('ALTER TABLE albums ADD owner_id INT DEFAULT NULL');
$this->addSql('CREATE INDEX IDX_ALBUM_OWNER ON albums (owner_id)');
$this->addSql('ALTER TABLE albums ADD CONSTRAINT FK_ALBUM_OWNER FOREIGN KEY (owner_id) REFERENCES users (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
}
public function down(Schema $schema): void
{
if ($this->isSqlite()) {
// SQLite down-migration omitted to avoid lossy table rebuild.
return;
}
$this->addSql('ALTER TABLE albums DROP CONSTRAINT FK_ALBUM_OWNER');
$this->addSql('DROP INDEX IDX_ALBUM_OWNER');
$this->addSql('ALTER TABLE albums DROP COLUMN owner_id');
}
private function isSqlite(): bool
{
return $this->connection->getDatabasePlatform()->getName() === 'sqlite';
}
}