- Encounter entity; Combatant now belongs to an encounter (ON DELETE
CASCADE). Migration adds encounter_id, rehoming any existing combatants.
- /tracker lists encounters (name, count, last updated) with a "New
encounter" form; /tracker/{id} is the HP tracker for one encounter.
- Encounters can be renamed, have their combatants cleared, or be deleted.
- The Enemies list gains an encounter picker next to "Add to tracker"
(existing encounter or "— New encounter —", which prompts for a name);
an encounter's "Add enemies" link pre-selects it via ?encounter=.
- Routes for combatant HP/remove moved under /tracker/combatant/ to keep
the numeric {id} for encounters.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
42 lines
1.8 KiB
PHP
42 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 Version20260906172225 extends AbstractMigration
|
|
{
|
|
public function getDescription(): string
|
|
{
|
|
return 'Add encounter table; combatants belong to an encounter';
|
|
}
|
|
|
|
public function up(Schema $schema): void
|
|
{
|
|
$this->addSql('CREATE TABLE encounter (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(120) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4 ENGINE = InnoDB');
|
|
|
|
// add nullable first, rehome any pre-existing combatants, then enforce
|
|
$this->addSql('ALTER TABLE combatant ADD encounter_id INT DEFAULT NULL');
|
|
$this->addSql("INSERT INTO encounter (name, created_at, updated_at) SELECT 'Combat', NOW(), NOW() FROM DUAL WHERE EXISTS (SELECT 1 FROM combatant WHERE encounter_id IS NULL)");
|
|
$this->addSql('UPDATE combatant SET encounter_id = (SELECT MAX(id) FROM encounter) WHERE encounter_id IS NULL');
|
|
|
|
$this->addSql('ALTER TABLE combatant ADD CONSTRAINT FK_807DA381D6E2FADC FOREIGN KEY (encounter_id) REFERENCES encounter (id) ON DELETE CASCADE');
|
|
$this->addSql('CREATE INDEX IDX_807DA381D6E2FADC ON combatant (encounter_id)');
|
|
$this->addSql('ALTER TABLE combatant CHANGE encounter_id encounter_id INT NOT NULL');
|
|
}
|
|
|
|
public function down(Schema $schema): void
|
|
{
|
|
$this->addSql('ALTER TABLE combatant DROP FOREIGN KEY FK_807DA381D6E2FADC');
|
|
$this->addSql('DROP INDEX IDX_807DA381D6E2FADC ON combatant');
|
|
$this->addSql('ALTER TABLE combatant DROP encounter_id');
|
|
$this->addSql('DROP TABLE encounter');
|
|
}
|
|
}
|