diff --git a/apps/dokploy/server/api/routers/postgres.ts b/apps/dokploy/server/api/routers/postgres.ts index 96485d637..3112beb66 100644 --- a/apps/dokploy/server/api/routers/postgres.ts +++ b/apps/dokploy/server/api/routers/postgres.ts @@ -8,6 +8,7 @@ import { findEnvironmentById, findPostgresById, findProjectById, + getMountPath, IS_CLOUD, rebuildDatabase, removePostgresById, @@ -37,6 +38,7 @@ import { postgres as postgresTable, } from "@/server/db/schema"; import { cancelJobs } from "@/server/utils/backup"; + export const postgresRouter = createTRPCRouter({ create: protectedProcedure .input(apiCreatePostgres) @@ -79,11 +81,13 @@ export const postgresRouter = createTRPCRouter({ ); } + const mountPath = getMountPath(input.dockerImage); + await createMount({ serviceId: newPostgres.postgresId, serviceType: "postgres", volumeName: `${newPostgres.appName}-data`, - mountPath: "/var/lib/postgresql/data", + mountPath: mountPath, type: "volume", }); @@ -367,6 +371,7 @@ export const postgresRouter = createTRPCRouter({ message: "You are not authorized to update this Postgres", }); } + const service = await updatePostgresById(postgresId, { ...rest, }); diff --git a/packages/server/src/services/postgres.ts b/packages/server/src/services/postgres.ts index 0d900443e..d7016038a 100644 --- a/packages/server/src/services/postgres.ts +++ b/packages/server/src/services/postgres.ts @@ -13,6 +13,18 @@ import { TRPCError } from "@trpc/server"; import { eq, getTableColumns } from "drizzle-orm"; import { validUniqueServerAppName } from "./project"; +export function getMountPath(dockerImage: string): string { + const versionMatch = dockerImage.match(/postgres:(\d+)/); + + if (versionMatch?.[1]) { + const version = Number.parseInt(versionMatch[1], 10); + if (version >= 18) { + return `/var/lib/postgresql/${version}/data`; + } + } + return "/var/lib/postgresql/data"; +} + export type Postgres = typeof postgres.$inferSelect; export const createPostgres = async (input: typeof apiCreatePostgres._type) => {