2025-02-22 17:29:14 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace DoctrineMigrations;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
2025-02-25 00:31:38 +01:00
|
|
|
use Doctrine\Migrations\AbstractMigration;
|
2025-02-22 17:29:14 +01:00
|
|
|
|
2025-02-25 00:31:38 +01:00
|
|
|
final class Version20250220215048 extends AbstractMigration
|
2025-02-22 17:29:14 +01:00
|
|
|
{
|
|
|
|
public function getDescription(): string
|
|
|
|
{
|
|
|
|
return 'Split $path property for attachments into $internal_path and $external_path';
|
|
|
|
}
|
|
|
|
|
2025-02-25 00:31:38 +01:00
|
|
|
public function up(Schema $schema): void
|
2025-02-22 17:29:14 +01:00
|
|
|
{
|
|
|
|
//Create the new columns as nullable (that is easier modifying them)
|
2025-02-25 00:31:38 +01:00
|
|
|
$this->addSql('ALTER TABLE attachments ADD internal_path VARCHAR(255) DEFAULT NULL');
|
|
|
|
$this->addSql('ALTER TABLE attachments ADD external_path VARCHAR(255) DEFAULT NULL');
|
2025-02-22 17:29:14 +01:00
|
|
|
|
|
|
|
//Copy the data from path to external_path and remove the path column
|
|
|
|
$this->addSql('UPDATE attachments SET external_path=path');
|
2025-03-29 20:57:58 +01:00
|
|
|
$this->addSql('ALTER TABLE attachments DROP COLUMN path');
|
2025-02-22 17:29:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
$this->addSql('UPDATE attachments SET internal_path=external_path WHERE external_path LIKE \'#%MEDIA#%%\' ESCAPE \'#\'');
|
|
|
|
$this->addSql('UPDATE attachments SET internal_path=external_path WHERE external_path LIKE \'#%BASE#%%\' ESCAPE \'#\'');
|
|
|
|
$this->addSql('UPDATE attachments SET internal_path=external_path WHERE external_path LIKE \'#%SECURE#%%\' ESCAPE \'#\'');
|
|
|
|
$this->addSql('UPDATE attachments SET internal_path=external_path WHERE external_path LIKE \'#%FOOTPRINTS#%%\' ESCAPE \'#\'');
|
|
|
|
$this->addSql('UPDATE attachments SET internal_path=external_path WHERE external_path LIKE \'#%FOOTPRINTS3D#%%\' ESCAPE \'#\'');
|
|
|
|
$this->addSql('UPDATE attachments SET external_path=NULL WHERE internal_path IS NOT NULL');
|
|
|
|
}
|
|
|
|
|
2025-02-25 00:31:38 +01:00
|
|
|
public function down(Schema $schema): void
|
2025-02-22 17:29:14 +01:00
|
|
|
{
|
|
|
|
$this->addSql('UPDATE attachments SET external_path=internal_path WHERE internal_path IS NOT NULL');
|
2025-03-29 20:57:58 +01:00
|
|
|
$this->addSql('ALTER TABLE attachments DROP COLUMN internal_path');
|
2025-02-22 17:29:14 +01:00
|
|
|
$this->addSql('ALTER TABLE attachments RENAME COLUMN external_path TO path');
|
|
|
|
}
|
|
|
|
}
|