Skip to content

Commit

Permalink
feat: delete on cascade when a user is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
maelgangloff committed Aug 6, 2024
1 parent 342b3ff commit 3eaa7fa
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 19 deletions.
21 changes: 7 additions & 14 deletions assets/components/Sider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
LogoutOutlined,
SearchOutlined,
TeamOutlined,
UserOutlined
UserOutlined,
FieldBinaryOutlined
} from "@ant-design/icons";
import {Badge, Menu} from "antd";
import React from "react";
Expand Down Expand Up @@ -52,19 +53,11 @@ export function Sider({isAuthenticated}: { isAuthenticated: boolean }) {
onClick: () => navigate('/info/tld')
},
{
key: 'entity-finder',
icon: <TeamOutlined/>,
label: t`Entity`,
title: t`Entity Finder`,
disabled: true,
onClick: () => navigate('/search/entity')
},
{
key: 'ns-finder',
icon: <CloudServerOutlined/>,
label: t`Nameserver`,
title: t`Nameserver Finder`,
disabled: true,
key: 'ip-finder',
icon: <FieldBinaryOutlined />,
label: t`LIPI IP Finder`,
title: t`IP Finder`,
disabled: false,
onClick: () => navigate('/search/nameserver')
}
]
Expand Down
50 changes: 50 additions & 0 deletions migrations/Version20240806222018.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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 Version20240806222018 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE connector DROP CONSTRAINT FK_148C456EA76ED395');
$this->addSql('ALTER TABLE connector ADD CONSTRAINT FK_148C456EA76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE watch_list DROP CONSTRAINT FK_152B584BA76ED395');
$this->addSql('ALTER TABLE watch_list ADD CONSTRAINT FK_152B584BA76ED395 FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE watch_lists_domains DROP CONSTRAINT FK_F693E1D0D52D7AA6');
$this->addSql('ALTER TABLE watch_lists_domains DROP CONSTRAINT FK_F693E1D0AF923913');
$this->addSql('ALTER TABLE watch_lists_domains ADD CONSTRAINT FK_F693E1D0D52D7AA6 FOREIGN KEY (watch_list_token) REFERENCES watch_list (token) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE watch_lists_domains ADD CONSTRAINT FK_F693E1D0AF923913 FOREIGN KEY (domain_ldh_name) REFERENCES domain (ldh_name) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE watch_list_trigger DROP CONSTRAINT FK_CF857A4CC4508918');
$this->addSql('ALTER TABLE watch_list_trigger ADD CONSTRAINT FK_CF857A4CC4508918 FOREIGN KEY (watch_list_id) REFERENCES watch_list (token) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('ALTER TABLE watch_list_trigger DROP CONSTRAINT fk_cf857a4cc4508918');
$this->addSql('ALTER TABLE watch_list_trigger ADD CONSTRAINT fk_cf857a4cc4508918 FOREIGN KEY (watch_list_id) REFERENCES watch_list (token) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE watch_list DROP CONSTRAINT fk_152b584ba76ed395');
$this->addSql('ALTER TABLE watch_list ADD CONSTRAINT fk_152b584ba76ed395 FOREIGN KEY (user_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE connector DROP CONSTRAINT fk_148c456ea76ed395');
$this->addSql('ALTER TABLE connector ADD CONSTRAINT fk_148c456ea76ed395 FOREIGN KEY (user_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE watch_lists_domains DROP CONSTRAINT fk_f693e1d0d52d7aa6');
$this->addSql('ALTER TABLE watch_lists_domains DROP CONSTRAINT fk_f693e1d0af923913');
$this->addSql('ALTER TABLE watch_lists_domains ADD CONSTRAINT fk_f693e1d0d52d7aa6 FOREIGN KEY (watch_list_token) REFERENCES watch_list (token) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE watch_lists_domains ADD CONSTRAINT fk_f693e1d0af923913 FOREIGN KEY (domain_ldh_name) REFERENCES domain (ldh_name) NOT DEFERRABLE INITIALLY IMMEDIATE');
}
}
2 changes: 1 addition & 1 deletion src/Entity/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Connector
private ?string $id;

#[ORM\ManyToOne(inversedBy: 'connectors')]
#[ORM\JoinColumn(nullable: false)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
public ?User $user = null;

#[Groups(['connector:list', 'connector:create', 'watchlist:list'])]
Expand Down
6 changes: 3 additions & 3 deletions src/Entity/WatchList.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ class WatchList
private string $token;

#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'watchLists')]
#[ORM\JoinColumn(nullable: false)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
public ?User $user = null;

/**
* @var Collection<int, Domain>
*/
#[ORM\ManyToMany(targetEntity: Domain::class, inversedBy: 'watchLists')]
#[ORM\JoinTable(name: 'watch_lists_domains',
joinColumns: [new ORM\JoinColumn(name: 'watch_list_token', referencedColumnName: 'token')],
inverseJoinColumns: [new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name')])]
joinColumns: [new ORM\JoinColumn(name: 'watch_list_token', referencedColumnName: 'token', onDelete: 'CASCADE')],
inverseJoinColumns: [new ORM\JoinColumn(name: 'domain_ldh_name', referencedColumnName: 'ldh_name', onDelete: 'CASCADE')])]
#[Groups(['watchlist:list', 'watchlist:item', 'watchlist:create', 'watchlist:update'])]
private Collection $domains;

Expand Down
2 changes: 1 addition & 1 deletion src/Entity/WatchListTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class WatchListTrigger

#[ORM\Id]
#[ORM\ManyToOne(targetEntity: WatchList::class, inversedBy: 'watchListTriggers')]
#[ORM\JoinColumn(referencedColumnName: 'token', nullable: false)]
#[ORM\JoinColumn(referencedColumnName: 'token', nullable: false, onDelete: 'CASCADE')]
private ?WatchList $watchList = null;

#[ORM\Id]
Expand Down

0 comments on commit 3eaa7fa

Please sign in to comment.