All checks were successful
CI - Build Tonehaus Docker image / tonehaus-ci-build (push) Successful in 2m0s
52 lines
1.8 KiB
PHP
52 lines
1.8 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 Version20251114111853 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return '';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
if ($this->isSqlite()) {
|
|
// SQLite installs get albums from Version20251127235840.
|
|
return;
|
|
}
|
|
// Idempotent guard: if table already exists (from previous migration), skip
|
|
if ($schema->hasTable('albums')) {
|
|
return;
|
|
}
|
|
$this->addSql('CREATE TABLE albums (id SERIAL NOT NULL, spotify_id VARCHAR(64) NOT NULL, name VARCHAR(255) NOT NULL, artists JSON NOT NULL, release_date VARCHAR(20) DEFAULT NULL, total_tracks INT NOT NULL, cover_url VARCHAR(1024) DEFAULT NULL, external_url VARCHAR(1024) DEFAULT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))');
|
|
$this->addSql('CREATE UNIQUE INDEX UNIQ_F4E2474FA905FC5C ON albums (spotify_id)');
|
|
$this->addSql('COMMENT ON COLUMN albums.created_at IS \'(DC2Type:datetime_immutable)\'');
|
|
$this->addSql('COMMENT ON COLUMN albums.updated_at IS \'(DC2Type:datetime_immutable)\'');
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
if ($this->isSqlite()) {
|
|
return;
|
|
}
|
|
// Be defensive: only drop the table if it exists
|
|
if ($schema->hasTable('albums')) {
|
|
$this->addSql('DROP TABLE albums');
|
|
}
|
|
}
|
|
|
|
private function isSqlite(): bool
|
|
{
|
|
return $this->connection->getDatabasePlatform()->getName() === 'sqlite';
|
|
}
|
|
}
|