Files
Plenario/config/Migrations/20261108120000_RemoveOrphanedRows.php
T
gnilebeinandClaude Opus 5.5 0a4c9fad09
CI / Deploy / test (push) Successful in 53s
CI / Deploy / deploy (push) Skipped
Delete options and responses together with their poll
Deleting a poll removed its slides with a plain deleteAll and relied on
ON DELETE CASCADE for slide options and responses. SQLite does not enforce
foreign keys by default, so answers of deleted polls stayed in the database.
Cascade through the ORM instead and remove the rows left behind earlier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 21:56:18 +01:00

34 lines
913 B
PHP

<?php
declare(strict_types=1);
use Migrations\BaseMigration;
/**
* Removes answer options and responses whose slide no longer exists.
*
* Deleting a poll used to rely on ON DELETE CASCADE, which SQLite does not enforce
* by default, so options and responses of deleted polls could stay behind.
* PollsTable now deletes them via the ORM; this cleans up what was left before.
* Safe to run repeatedly, a no-op on databases that enforce foreign keys.
*/
class RemoveOrphanedRows extends BaseMigration
{
/**
* @return void
*/
public function up(): void
{
$this->execute('DELETE FROM responses WHERE slide_id NOT IN (SELECT id FROM slides)');
$this->execute('DELETE FROM slide_options WHERE slide_id NOT IN (SELECT id FROM slides)');
}
/**
* Deleted rows cannot be restored.
*
* @return void
*/
public function down(): void
{
}
}