Skip to content

Commit

Permalink
fix: remove metadata when manga is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Oct 15, 2022
1 parent a2c3d60 commit 76b688f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CREATE UNIQUE INDEX "Manga_metadataId_key" ON "Manga"("metadataId");
ALTER TABLE "Manga" ADD CONSTRAINT "Manga_libraryId_fkey" FOREIGN KEY ("libraryId") REFERENCES "Library"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Manga" ADD CONSTRAINT "Manga_metadataId_fkey" FOREIGN KEY ("metadataId") REFERENCES "Metadata"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "Manga" ADD CONSTRAINT "Manga_metadataId_fkey" FOREIGN KEY ("metadataId") REFERENCES "Metadata"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Chapter" ADD CONSTRAINT "Chapter_mangaId_fkey" FOREIGN KEY ("mangaId") REFERENCES "Manga"("id") ON DELETE CASCADE ON UPDATE CASCADE;
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ model Manga {
library Library @relation(fields: [libraryId], references: [id], onDelete: Cascade)
libraryId Int
chapter Chapter[]
metadata Metadata @relation(fields: [metadataId], references: [id], onDelete: Cascade)
metadata Metadata @relation(fields: [metadataId], references: [id])
metadataId Int @unique
}

Expand Down
9 changes: 6 additions & 3 deletions src/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Skeleton,
Text,
Timeline,
Tooltip,
} from '@mantine/core';
import {
IconActivity,
Expand Down Expand Up @@ -119,9 +120,11 @@ function HistoryItem({ chapter }: { chapter: HistoryItemType }) {
</Text>
</Text>
<SimpleGrid cols={2} mt={4}>
<Badge variant="light" size="xs" color="cyan" leftSection={<IconClock size={12} />}>
{time}
</Badge>
<Tooltip label={time}>
<Badge variant="light" size="xs" color="cyan" leftSection={<IconClock size={12} />}>
{time}
</Badge>
</Tooltip>
<Badge variant="light" size="xs" color="violet" leftSection={<IconFileReport size={12} />}>
{prettyBytes(chapter.size)}
</Badge>
Expand Down
5 changes: 5 additions & 0 deletions src/server/trpc/router/manga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export const mangaRouter = t.router({
id,
},
});
await ctx.prisma.metadata.delete({
where: {
id: removed.metadataId,
},
});
const mangaPath = path.resolve(removed.library.path, sanitizer(removed.title));
await removeManga(mangaPath);
await removeJob(removed.title);
Expand Down

0 comments on commit 76b688f

Please sign in to comment.