Skip to content

Commit 0978b52

Browse files
authored
Fix user with push subscription not being deleted (#1914)
1 parent 996ef2b commit 0978b52

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
final class Version20251214111055 extends AbstractMigration
11+
{
12+
public function getDescription(): string
13+
{
14+
return 'Modify UserPushSubscription, so that the user is not nullable and it cascade deletes if the user is deleted';
15+
}
16+
17+
public function up(Schema $schema): void
18+
{
19+
$this->addSql('ALTER TABLE user_push_subscription DROP CONSTRAINT FK_AE378BD8A76ED395');
20+
$this->addSql('ALTER TABLE user_push_subscription ALTER user_id SET NOT NULL');
21+
$this->addSql('ALTER TABLE user_push_subscription ADD CONSTRAINT FK_AE378BD8A76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
22+
}
23+
24+
public function down(Schema $schema): void
25+
{
26+
$this->addSql('ALTER TABLE user_push_subscription DROP CONSTRAINT fk_ae378bd8a76ed395');
27+
$this->addSql('ALTER TABLE user_push_subscription ALTER user_id DROP NOT NULL');
28+
$this->addSql('ALTER TABLE user_push_subscription ADD CONSTRAINT fk_ae378bd8a76ed395 FOREIGN KEY (user_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
29+
}
30+
}

src/Entity/UserPushSubscription.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class UserPushSubscription
1919
public int $id;
2020

2121
#[ManyToOne(targetEntity: User::class, cascade: ['persist'], inversedBy: 'pushSubscriptions')]
22+
#[JoinColumn(nullable: false, onDelete: 'CASCADE')]
2223
public User $user;
2324

2425
#[Column(type: 'text')]

0 commit comments

Comments
 (0)