feat(documents) : add migration for type column with data classification

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-23 15:14:33 +01:00
parent 342b0afdbb
commit 8d920d5f65
8 changed files with 172 additions and 15 deletions

View File

@@ -0,0 +1,31 @@
<?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 Version20260323141052 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add type column to documents table and classify existing documents by mimeType';
}
public function up(Schema $schema): void
{
$this->addSql("DO \$\$ BEGIN IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'documents' AND column_name = 'type') THEN ALTER TABLE documents ADD COLUMN type VARCHAR(20) NOT NULL DEFAULT 'documentation'; END IF; END \$\$");
$this->addSql("UPDATE documents SET type = 'photo' WHERE mimetype LIKE 'image/%'");
$this->addSql("UPDATE documents SET type = 'autre' WHERE type = 'documentation' AND mimetype NOT LIKE 'application/pdf' AND mimetype NOT LIKE 'image/%'");
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE documents DROP COLUMN IF EXISTS type');
}
}