mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-20 02:58:53 +00:00
fix: update mount path on editing pg image
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
deployPostgres,
|
deployPostgres,
|
||||||
findBackupsByDbId,
|
findBackupsByDbId,
|
||||||
findEnvironmentById,
|
findEnvironmentById,
|
||||||
|
findMountsByApplicationId,
|
||||||
findPostgresById,
|
findPostgresById,
|
||||||
findProjectById,
|
findProjectById,
|
||||||
IS_CLOUD,
|
IS_CLOUD,
|
||||||
@@ -16,6 +17,7 @@ import {
|
|||||||
startServiceRemote,
|
startServiceRemote,
|
||||||
stopService,
|
stopService,
|
||||||
stopServiceRemote,
|
stopServiceRemote,
|
||||||
|
updateMount,
|
||||||
updatePostgresById,
|
updatePostgresById,
|
||||||
} from "@dokploy/server";
|
} from "@dokploy/server";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
@@ -37,6 +39,16 @@ import {
|
|||||||
postgres as postgresTable,
|
postgres as postgresTable,
|
||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
import { cancelJobs } from "@/server/utils/backup";
|
import { cancelJobs } from "@/server/utils/backup";
|
||||||
|
|
||||||
|
function getMountPath(dockerImage: string): string {
|
||||||
|
const versionMatch = dockerImage.match(/postgres:(\d+)/);
|
||||||
|
const version = versionMatch?.[1]
|
||||||
|
? Number.parseInt(versionMatch[1], 10)
|
||||||
|
: 18;
|
||||||
|
|
||||||
|
return `/var/lib/postgresql/${version}/data`;
|
||||||
|
}
|
||||||
|
|
||||||
export const postgresRouter = createTRPCRouter({
|
export const postgresRouter = createTRPCRouter({
|
||||||
create: protectedProcedure
|
create: protectedProcedure
|
||||||
.input(apiCreatePostgres)
|
.input(apiCreatePostgres)
|
||||||
@@ -79,11 +91,13 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mountPath = getMountPath(input.dockerImage);
|
||||||
|
|
||||||
await createMount({
|
await createMount({
|
||||||
serviceId: newPostgres.postgresId,
|
serviceId: newPostgres.postgresId,
|
||||||
serviceType: "postgres",
|
serviceType: "postgres",
|
||||||
volumeName: `${newPostgres.appName}-data`,
|
volumeName: `${newPostgres.appName}-data`,
|
||||||
mountPath: "/var/lib/postgresql/data",
|
mountPath: mountPath,
|
||||||
type: "volume",
|
type: "volume",
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -363,6 +377,23 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
message: "You are not authorized to update this Postgres",
|
message: "You are not authorized to update this Postgres",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rest.dockerImage) {
|
||||||
|
const mountPath = getMountPath(rest.dockerImage);
|
||||||
|
const mounts = await findMountsByApplicationId(postgresId, "postgres");
|
||||||
|
if (!mounts || mounts.length === 0) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "NOT_FOUND",
|
||||||
|
message: "Mount not found for this Postgres",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (const mount of mounts) {
|
||||||
|
await updateMount(mount.mountId, {
|
||||||
|
mountPath: mountPath,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const service = await updatePostgresById(postgresId, {
|
const service = await updatePostgresById(postgresId, {
|
||||||
...rest,
|
...rest,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user