Merge branch 'develop' into feat/mail-integration
This commit is contained in:
36
migrations/Version20260519175041.php
Normal file
36
migrations/Version20260519175041.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260519175041 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Create workflow table and seed default Standard workflow';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('CREATE TABLE workflow (
|
||||
id SERIAL NOT NULL,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
is_default BOOLEAN DEFAULT FALSE NOT NULL,
|
||||
position INT DEFAULT 0 NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
)');
|
||||
$this->addSql('CREATE UNIQUE INDEX uniq_workflow_name ON workflow (name)');
|
||||
$this->addSql('CREATE UNIQUE INDEX uniq_workflow_one_default ON workflow (is_default) WHERE is_default = TRUE');
|
||||
|
||||
$this->addSql("INSERT INTO workflow (name, is_default, position) VALUES ('Standard', TRUE, 0)");
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP TABLE workflow');
|
||||
}
|
||||
}
|
||||
74
migrations/Version20260519175114.php
Normal file
74
migrations/Version20260519175114.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\Migrations\Exception\MigrationException;
|
||||
|
||||
final class Version20260519175114 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Attach existing TaskStatus rows to Standard workflow and backfill category (strict mapping)';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// 1) Récupérer l'id du workflow Standard
|
||||
$standardId = $this->connection->fetchOne("SELECT id FROM workflow WHERE name = 'Standard'");
|
||||
if (!$standardId) {
|
||||
throw new MigrationException('Workflow Standard introuvable. Lancer M1 d\'abord.');
|
||||
}
|
||||
|
||||
// 2) Garde-fou : vérifier qu'il n'y a pas de label hors mapping
|
||||
$mapping = [
|
||||
'A faire' => 'todo',
|
||||
'À faire' => 'todo',
|
||||
'En cours' => 'in_progress',
|
||||
'Bloqué' => 'blocked',
|
||||
'En attente de validation' => 'review',
|
||||
'Terminé' => 'done',
|
||||
];
|
||||
$rows = $this->connection->fetchAllAssociative('SELECT id, label FROM task_status');
|
||||
foreach ($rows as $row) {
|
||||
if (!isset($mapping[$row['label']])) {
|
||||
throw new MigrationException(sprintf(
|
||||
'TaskStatus #%d ("%s") n\'est pas mappable. Ajoutez son mapping dans la migration avant de relancer.',
|
||||
$row['id'],
|
||||
$row['label'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// 3) Ajouter colonnes nullable
|
||||
$this->addSql('ALTER TABLE task_status ADD COLUMN workflow_id INT DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE task_status ADD COLUMN category VARCHAR(32) DEFAULT NULL');
|
||||
|
||||
// 4) Backfill
|
||||
$this->addSql("UPDATE task_status SET workflow_id = {$standardId}");
|
||||
foreach ($mapping as $label => $cat) {
|
||||
$this->addSql(sprintf(
|
||||
"UPDATE task_status SET category = '%s' WHERE label = '%s'",
|
||||
$cat,
|
||||
str_replace("'", "''", $label),
|
||||
));
|
||||
}
|
||||
|
||||
// 5) NOT NULL + FK
|
||||
$this->addSql('ALTER TABLE task_status ALTER COLUMN workflow_id SET NOT NULL');
|
||||
$this->addSql('ALTER TABLE task_status ALTER COLUMN category SET NOT NULL');
|
||||
$this->addSql('ALTER TABLE task_status ADD CONSTRAINT FK_task_status_workflow FOREIGN KEY (workflow_id) REFERENCES workflow (id) ON DELETE CASCADE NOT DEFERRABLE');
|
||||
$this->addSql('CREATE INDEX IDX_task_status_workflow ON task_status (workflow_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE task_status DROP CONSTRAINT FK_task_status_workflow');
|
||||
$this->addSql('DROP INDEX IDX_task_status_workflow');
|
||||
$this->addSql('ALTER TABLE task_status DROP COLUMN workflow_id');
|
||||
$this->addSql('ALTER TABLE task_status DROP COLUMN category');
|
||||
}
|
||||
}
|
||||
38
migrations/Version20260519175142.php
Normal file
38
migrations/Version20260519175142.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
use Doctrine\Migrations\Exception\MigrationException;
|
||||
|
||||
final class Version20260519175142 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Attach existing projects to Standard workflow (NOT NULL, RESTRICT)';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$standardId = $this->connection->fetchOne("SELECT id FROM workflow WHERE name = 'Standard'");
|
||||
if (!$standardId) {
|
||||
throw new MigrationException('Workflow Standard introuvable.');
|
||||
}
|
||||
|
||||
$this->addSql('ALTER TABLE project ADD COLUMN workflow_id INT DEFAULT NULL');
|
||||
$this->addSql("UPDATE project SET workflow_id = {$standardId}");
|
||||
$this->addSql('ALTER TABLE project ALTER COLUMN workflow_id SET NOT NULL');
|
||||
$this->addSql('ALTER TABLE project ADD CONSTRAINT FK_project_workflow FOREIGN KEY (workflow_id) REFERENCES workflow (id) ON DELETE RESTRICT NOT DEFERRABLE');
|
||||
$this->addSql('CREATE INDEX IDX_project_workflow ON project (workflow_id)');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE project DROP CONSTRAINT FK_project_workflow');
|
||||
$this->addSql('DROP INDEX IDX_project_workflow');
|
||||
$this->addSql('ALTER TABLE project DROP COLUMN workflow_id');
|
||||
}
|
||||
}
|
||||
38
migrations/Version20260519175338.php
Normal file
38
migrations/Version20260519175338.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version20260519175338 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Align workflow schema with Doctrine naming (indexes, IDENTITY). Drops the partial unique index uniq_workflow_one_default (uniqueness is enforced by UniqueDefaultWorkflowListener at app level).';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER INDEX idx_project_workflow RENAME TO IDX_2FB3D0EE2C7C2CBA');
|
||||
$this->addSql('ALTER INDEX idx_task_status_workflow RENAME TO IDX_40A9E1CF2C7C2CBA');
|
||||
$this->addSql('DROP INDEX uniq_workflow_one_default');
|
||||
$this->addSql('ALTER TABLE workflow ALTER id DROP DEFAULT');
|
||||
$this->addSql('ALTER TABLE workflow ALTER id ADD GENERATED BY DEFAULT AS IDENTITY');
|
||||
// Aligner la séquence d'identity sur MAX(id) pour éviter le conflit avec les rows déjà insérés par M1
|
||||
$this->addSql('SELECT setval(pg_get_serial_sequence(\'workflow\', \'id\'), COALESCE((SELECT MAX(id) FROM workflow), 0) + 1, false)');
|
||||
$this->addSql('ALTER INDEX uniq_workflow_name RENAME TO UNIQ_65C598165E237E06');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER INDEX idx_2fb3d0ee2c7c2cba RENAME TO idx_project_workflow');
|
||||
$this->addSql('ALTER INDEX idx_40a9e1cf2c7c2cba RENAME TO idx_task_status_workflow');
|
||||
$this->addSql('ALTER TABLE workflow ALTER id DROP IDENTITY');
|
||||
$this->addSql("ALTER TABLE workflow ALTER id SET DEFAULT nextval('workflow_id_seq'::regclass)");
|
||||
$this->addSql('CREATE UNIQUE INDEX uniq_workflow_one_default ON workflow (is_default) WHERE (is_default = true)');
|
||||
$this->addSql('ALTER INDEX uniq_65c598165e237e06 RENAME TO uniq_workflow_name');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user