mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-10-22 16:35:26 +00:00
fix(databases): skip empty volumeName mounts during database rebuild
This commit is contained in:
@@ -11,6 +11,7 @@ import { mongo } from "./mongo";
|
||||
import { mysql } from "./mysql";
|
||||
import { postgres } from "./postgres";
|
||||
import { redis } from "./redis";
|
||||
import { VOLUME_NAME_MESSAGE, VOLUME_NAME_REGEX } from "./utils";
|
||||
|
||||
export const serviceType = pgEnum("serviceType", [
|
||||
"application",
|
||||
@@ -122,6 +123,27 @@ const createSchema = createInsertSchema(mounts, {
|
||||
]),
|
||||
});
|
||||
|
||||
const validateVolumeMountName = (
|
||||
data: { type?: string; volumeName?: string | null },
|
||||
ctx: z.RefinementCtx,
|
||||
) => {
|
||||
if (data.type === "volume") {
|
||||
if (!data.volumeName) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Volume name is required for volume mounts",
|
||||
path: ["volumeName"],
|
||||
});
|
||||
} else if (!VOLUME_NAME_REGEX.test(data.volumeName)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: VOLUME_NAME_MESSAGE,
|
||||
path: ["volumeName"],
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const apiCreateMount = createSchema
|
||||
.pick({
|
||||
type: true,
|
||||
@@ -134,7 +156,8 @@ export const apiCreateMount = createSchema
|
||||
})
|
||||
.extend({
|
||||
serviceId: z.string().min(1),
|
||||
});
|
||||
})
|
||||
.superRefine(validateVolumeMountName);
|
||||
|
||||
export const apiFindOneMount = z.object({
|
||||
mountId: z.string().min(1),
|
||||
@@ -157,6 +180,9 @@ export const apiFindMountByApplicationId = z.object({
|
||||
serviceId: z.string().min(1),
|
||||
});
|
||||
|
||||
export const apiUpdateMount = createSchema.partial().extend({
|
||||
mountId: z.string().min(1),
|
||||
});
|
||||
export const apiUpdateMount = createSchema
|
||||
.partial()
|
||||
.extend({
|
||||
mountId: z.string().min(1),
|
||||
})
|
||||
.superRefine(validateVolumeMountName);
|
||||
|
||||
@@ -41,7 +41,8 @@ export const rebuildDatabase = async (
|
||||
|
||||
for (const mount of database.mounts) {
|
||||
if (mount.type === "volume") {
|
||||
const command = `docker volume rm ${quote([mount?.volumeName ?? ""])} --force`;
|
||||
if (!mount.volumeName) continue;
|
||||
const command = `docker volume rm ${quote([mount.volumeName])} --force`;
|
||||
if (database.serverId) {
|
||||
await execAsyncRemote(database.serverId, command);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user