fix: update volume backup components for improved functionality

- Refactored HandleVolumeBackups to use consistent naming for mount items.
- Added an AlertBlock to RestoreVolumeBackups to inform users about potential volume name conflicts.
- Updated mount retrieval logic in the mount router to enhance accuracy and efficiency in fetching volume mounts.
This commit is contained in:
Mauricio Siu
2025-07-01 23:48:19 -06:00
parent bddb07898e
commit b272f01a18
3 changed files with 14 additions and 14 deletions
@@ -550,11 +550,8 @@ export const HandleVolumeBackups = ({
</FormControl> </FormControl>
<SelectContent> <SelectContent>
{mounts?.map((mount) => ( {mounts?.map((mount) => (
<SelectItem <SelectItem key={mount.Name} value={mount.Name || ""}>
key={mount.mountId} {mount.Name}
value={mount.volumeName || ""}
>
{mount.volumeName}
</SelectItem> </SelectItem>
))} ))}
</SelectContent> </SelectContent>
@@ -44,6 +44,7 @@ import { toast } from "sonner";
import { z } from "zod"; import { z } from "zod";
import { type LogLine, parseLogs } from "../../docker/logs/utils"; import { type LogLine, parseLogs } from "../../docker/logs/utils";
import { formatBytes } from "../../database/backups/restore-backup"; import { formatBytes } from "../../database/backups/restore-backup";
import { AlertBlock } from "@/components/shared/alert-block";
interface Props { interface Props {
id: string; id: string;
@@ -169,6 +170,9 @@ export const RestoreVolumeBackups = ({ id, type, serverId }: Props) => {
<DialogDescription> <DialogDescription>
Select a destination and search for volume backup files Select a destination and search for volume backup files
</DialogDescription> </DialogDescription>
<AlertBlock>
Make sure the volume name is not being used by another container.
</AlertBlock>
</DialogHeader> </DialogHeader>
<Form {...form}> <Form {...form}>
+8 -9
View File
@@ -3,18 +3,17 @@ import {
apiFindOneMount, apiFindOneMount,
apiRemoveMount, apiRemoveMount,
apiUpdateMount, apiUpdateMount,
mounts,
} from "@/server/db/schema"; } from "@/server/db/schema";
import { import {
createMount, createMount,
deleteMount, deleteMount,
findApplicationById,
findMountById, findMountById,
getServiceContainer,
updateMount, updateMount,
} from "@dokploy/server"; } from "@dokploy/server";
import { createTRPCRouter, protectedProcedure } from "../trpc"; import { createTRPCRouter, protectedProcedure } from "../trpc";
import { z } from "zod"; import { z } from "zod";
import { and, eq } from "drizzle-orm";
import { db } from "@dokploy/server/db";
export const mountRouter = createTRPCRouter({ export const mountRouter = createTRPCRouter({
create: protectedProcedure create: protectedProcedure
@@ -40,11 +39,11 @@ export const mountRouter = createTRPCRouter({
allNamedByApplicationId: protectedProcedure allNamedByApplicationId: protectedProcedure
.input(z.object({ applicationId: z.string().min(1) })) .input(z.object({ applicationId: z.string().min(1) }))
.query(async ({ input }) => { .query(async ({ input }) => {
return await db.query.mounts.findMany({ const app = await findApplicationById(input.applicationId);
where: and( const container = await getServiceContainer(app.appName, app.serverId);
eq(mounts.applicationId, input.applicationId), const mounts = container?.Mounts.filter(
eq(mounts.type, "volume"), (mount) => mount.Type === "volume" && mount.Source !== "",
), );
}); return mounts;
}), }),
}); });