Skip to content

Commit 4fb3ad3

Browse files
authored
Merge pull request #3048 from Bima42/fix/update-pg-data-path
fix: update pg data path for latest docker version
2 parents eb8c6e4 + 736a732 commit 4fb3ad3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

apps/dokploy/server/api/routers/postgres.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
findEnvironmentById,
99
findPostgresById,
1010
findProjectById,
11+
getMountPath,
1112
IS_CLOUD,
1213
rebuildDatabase,
1314
removePostgresById,
@@ -37,6 +38,7 @@ import {
3738
postgres as postgresTable,
3839
} from "@/server/db/schema";
3940
import { cancelJobs } from "@/server/utils/backup";
41+
4042
export const postgresRouter = createTRPCRouter({
4143
create: protectedProcedure
4244
.input(apiCreatePostgres)
@@ -79,11 +81,13 @@ export const postgresRouter = createTRPCRouter({
7981
);
8082
}
8183

84+
const mountPath = getMountPath(input.dockerImage);
85+
8286
await createMount({
8387
serviceId: newPostgres.postgresId,
8488
serviceType: "postgres",
8589
volumeName: `${newPostgres.appName}-data`,
86-
mountPath: "/var/lib/postgresql/data",
90+
mountPath: mountPath,
8791
type: "volume",
8892
});
8993

@@ -367,6 +371,7 @@ export const postgresRouter = createTRPCRouter({
367371
message: "You are not authorized to update this Postgres",
368372
});
369373
}
374+
370375
const service = await updatePostgresById(postgresId, {
371376
...rest,
372377
});

packages/server/src/services/postgres.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ import { TRPCError } from "@trpc/server";
1313
import { eq, getTableColumns } from "drizzle-orm";
1414
import { validUniqueServerAppName } from "./project";
1515

16+
export function getMountPath(dockerImage: string): string {
17+
const versionMatch = dockerImage.match(/postgres:(\d+)/);
18+
19+
if (versionMatch?.[1]) {
20+
const version = Number.parseInt(versionMatch[1], 10);
21+
if (version >= 18) {
22+
return `/var/lib/postgresql/${version}/data`;
23+
}
24+
}
25+
return "/var/lib/postgresql/data";
26+
}
27+
1628
export type Postgres = typeof postgres.$inferSelect;
1729

1830
export const createPostgres = async (input: typeof apiCreatePostgres._type) => {

0 commit comments

Comments
 (0)