CRUD Albums + Spotify API requests into DB.
All checks were successful
CI - Build Tonehaus Docker image / tonehaus-ci-build (push) Successful in 2m17s
All checks were successful
CI - Build Tonehaus Docker image / tonehaus-ci-build (push) Successful in 2m17s
This commit is contained in:
41
migrations/Version20251114120500.php
Normal file
41
migrations/Version20251114120500.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20251114120500 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Add user-created album fields: local_id, source, created_by_id; make spotify_id nullable';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql("ALTER TABLE albums ADD local_id VARCHAR(64) DEFAULT NULL");
|
||||
$this->addSql("ALTER TABLE albums ADD source VARCHAR(16) NOT NULL DEFAULT 'spotify'");
|
||||
$this->addSql("ALTER TABLE albums ADD created_by_id INT DEFAULT NULL");
|
||||
$this->addSql("ALTER TABLE albums ALTER spotify_id DROP NOT NULL");
|
||||
$this->addSql("CREATE UNIQUE INDEX uniq_album_local_id ON albums (local_id)");
|
||||
$this->addSql("ALTER TABLE albums ADD CONSTRAINT FK_F4E2474FB03A8386 FOREIGN KEY (created_by_id) REFERENCES users (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE");
|
||||
$this->addSql("CREATE INDEX IDX_F4E2474FB03A8386 ON albums (created_by_id)");
|
||||
$this->addSql("UPDATE albums SET source = 'spotify' WHERE source IS NULL");
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql("ALTER TABLE albums DROP CONSTRAINT FK_F4E2474FB03A8386");
|
||||
$this->addSql("DROP INDEX IF EXISTS uniq_album_local_id");
|
||||
$this->addSql("DROP INDEX IF EXISTS IDX_F4E2474FB03A8386");
|
||||
$this->addSql("ALTER TABLE albums DROP COLUMN local_id");
|
||||
$this->addSql("ALTER TABLE albums DROP COLUMN source");
|
||||
$this->addSql("ALTER TABLE albums DROP COLUMN created_by_id");
|
||||
$this->addSql("ALTER TABLE albums ALTER spotify_id SET NOT NULL");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user