Merge pull request 'Delete options and responses together with their poll' (#30) from fix/poll-delete-cascade into main
CI / Deploy / test (push) Successful in 1m0s
CI / Deploy / deploy (push) Successful in 5s

Reviewed-on: #30
This commit was merged in pull request #30.
This commit is contained in:
gnilebein committed 2026-11-08 22:31:14 +01:00
commit f536ea89fc
4 files changed
+71 -1

No files matched your search

@@ -0,0 +1,33 @@
<?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
{
}
}